说明: 一直想写个集群环境搭建的总结了,每次开始一个新项目,环境搭建就要浪费我很长时间,现在我就从头开始一边搭建一边记录,供以后参考。

网络环境配置

# 更改ip地址
vi /etc/sysconfig/network-scripts/ifcfg-ens160
# 类似下面,注意ONBOOT="yes"
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
UUID="e408ab5d-6013-4f49-8e37-dfdb7202a25c"
DEVICE="ens33"
ONBOOT="yes"
IPV6_PRIVACY="no"
IPADDR=192.168.18.212
NETMASK=255.255.255.0
GATEWAY=192.168.18.1
DNS1=192.168.1.2
DNS2=8.8.8.8
# 重启网络服务
service network restart
# ping百度看看是否能联网
ping www.baidu.com

基础环境安装

# 更改时区,同步时间,安装基础包
timedatectl set-timezone Asia/Shanghai
yum -y install ntp ntpdate
ntpdate 0.asia.pool.ntp.org
hwclock --systohc
yum install -y net-tools wget vim unzip
# 关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
# 关闭Selinux,首先打开配置文件
setenforce 0
vim /etc/selinux/config
# 将SELINUX=enforcing改为SELINUX=disabled,保存后退出。

Python3.6环境安装

# 安装相应包
yum install -y ncurses-libs zlib-devel mysql-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel python-backports-lzma
wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz
tar -xvJf Python-3.6.5.tar.xz
cd Python-3.6.5
./configure --prefix=/usr/local/python3 --enable-shared CFLAGS=-fPIC
make && make install
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
cp libpython3.6m.so.1.0 /usr/local/lib64/
cp libpython3.6m.so.1.0 /usr/lib/
cp libpython3.6m.so.1.0 /usr/lib64/
# 进入项目目录安装环境,完成
pip3 install -r requirements.txt -i https://pypi.doubanio.com/simple/
# 下面步骤真实环境不需要安装
pip3 install virtualenv
pip3 install virtualenvwrapper
# 创建虚拟环境
vim ~/.bashrc
# 在文末填入以下代码并保存
VIRTUALENVWRAPPER_PYTHON=/usr/local/python3/bin/python3    # 指定virtualenvwrapper执行的python版本
export WORKON_HOME=$HOME/.virtualenvs    # 指定虚拟环境存放目录,.virtualenvs目录名可自拟
source /usr/local/python3/bin/virtualenvwrapper.sh    # virtualenvwrapper.sh所在目录
# 去找到virtualenv位置
sudo find / -name "virtualenv"
# /usr/local/python3/bin/virtualenv
# 进行软连接
ln -s /usr/local/python3/bin/virtualenv /usr/bin/virtualenv
# 运行.bashrc文件并创建python3环境
source ~/.bashrc
mkvirtualenv --python=/usr/local/python3/bin/python3 py3-env

附:常见的virtualenvwrapper命令

# 创建虚拟环境
mkvirtualenv my_env
# 切换到某个虚拟环境
workon my_env
# 退出当前虚拟环境
deactivate
# 删除某个虚拟环境
rmvirtualenv my_env
# 列出所有虚拟环境
lsvirtualenv
# 进入到虚拟环境所在的目录
cdvirtualenv


附:pip3临时换源方法

# 临时使用
pip install '你需要安装的包' -i https://pypi.doubanio.com/simple/
# 注意,simple 不能少, 是 https 而不是 http

Mysql5.7环境安装

1.卸载mariadb,并安装Mysql。

rpm -qa | grep mariadb
# 根据上面过滤的结果删除mariadb
rpm -e --nodeps mariadb-5.5.56-2.el7.x86_64
rpm -e --nodeps mariadb-server-5.5.56-2.el7.x86_64
rpm -e --nodeps mariadb-devel-5.5.56-2.el7.x86_64
rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
# 安装mysql(在线)
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
rpm -ivh mysql57-community-release-el7-11.noarch.rpm
yum install -y mysql-community-server
# 安装mysql(离线)
浏览器下载:https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.29-1.el7.x86_64.rpm-bundle.tar
# 解压
tar -xf mysql-5.7.29-1.el7.x86_64.rpm-bundle.tar
# 执行rpm包安装
rpm -ivh mysql-community-devel-5.7.29-1.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-libs-5.7.29-1.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-embedded-5.7.29-1.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-libs-compat-5.7.29-1.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-embedded-compat-5.7.29-1.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-common-5.7.29-1.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-embedded-devel-5.7.29-1.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-test-5.7.29-1.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-client-5.7.29-1.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-server-5.7.29-1.el7.x86_64.rpm --force --nodeps
# 设置开机自启
systemctl start mysqld
systemctl enable mysqld

2.更改Mysql初始密码,配置字符集,并设置远程登录。

# mysql的默认配置
# 配置文件:/etc/my.cnf
# 日志文件:var/log/mysqld.log
# 服务启动脚本:/usr/lib/systemd/system/mysqld.service
# socket文件:/var/run/mysqld/mysqld.pid
# 不重制密码是不可以进行任何操作的,而且mysql有个密码策略,一定要符合要求,不然会提示错误:
# You must reset your password using ALTER USER statement before executing this statement.
# mysql初始密码在mysqld.log 中。
# 获取初始密码
grep "password" /var/log/mysqld.log
# [Note] A temporary password is generated for root@localhost: f4pAyLjhzu)t
# 登录
mysql -uroot -p
# Enter password: 
# 输入密码登录并修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Your Password';
# Query OK, 0 rows affected (0.00 sec)
# 设置远程登录账户
GRANT ALL PRIVILEGES ON *.* TO 'Timmy'@'%' IDENTIFIED BY 'Your Password' WITH GRANT OPTION;
# 刷新权限
flush privileges;
# Query OK, 0 rows affected (0.00 sec)
# 打开配置文件,修改字符集
vim /etc/my.cnf
# 在[mysqld]下添加
character-set-server=utf8
init_connect='SET NAMES utf8'
# 重启服务
systemctl restart mysqld

Redis5.0.7环境安装

# 使用yum install redis进行安装,安装的不是最新版本版本号是3.2.10-2
# 如果要安装最新的redis,需要先安装Remi的软件源
yum install -y http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
# 安装最新版本的redis 
yum --enablerepo=remi install redis
# 开机自启Redis
systemctl start redis
systemctl enable redis
# 打开Redis配置文件
vim /etc/redis.conf
# 修改bind 127.0.0.1 为全部ip
bind  0.0.0.0
# 创建密码,搜索requirepass关键字,
# 设置密码的方法就是去掉注释,把requirepass foobared的foobared替换成自己的密码即可
requirepass Your Password
# 重启Redis
systemctl restart redis

heketi9.0.0环境安装

unzip heketi-9.0.0.zip
cd /root/heketi-9.0.0/client/api/python
pip3 install -i https://pypi.doubanio.com/simple/ -r requirements.txt
python3 setup.py install
Last modification:November 17th, 2020 at 10:06 am