环境准备
环境检查(三个测试节点的环境都应该是一样的,只有ip不同)
[root@db01 bin]# cat /etc/redhat-release //系统版本
CentOS Linux release 7.5.1804 (Core)
[root@db01 bin]# uname -r //内核版本
3.10.0-862.el7.x86_64
[root@db01 bin]# hostname -I //ip地址,分别是51,52,53
10.0.0.51 172.16.1.51
系统配置
hostnamectl set-hostname db01 //修改主机名 nmcli connection modify eth0 ipv4.addresses 10.0.0.51/24 //修改外网10网段
nmcli connection modify eth1 ipv4.addresses 172.16.1.53/24 //修改内网 nmcli connection down eth1 && nmcli connection up eth1 //重启网卡
nmcli connection down eth0 && nmcli connection up eth0 cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.0.0.51 db01
10.0.0.52 db02
10.0.0.53 db03
下载mysql
mkdir /server/tools -p //创建安装包存放目录 [root@db01 ~]# mysql --version //mysql版本
mysql Ver 14.14 Distrib 5.7.22, for linux-glibc2.12 (x86_64) using EditLine wrapper tar xf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysql
//可以去mysql官网下载,然后倒入tar包
编辑配置文件
[root@db01 ~]# vim /etc/my.cnf //简单版的my.cnf [mysqld]
server-id=1 //每个节点server_id号都不一样
user=mysql //用户为Mysql
basedir=/usr/local/mysql
log_bin=mysql-bin //开启bin-log日志
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
log-error=/data/mysql/error.log #注解
--user: 指定mysql用户
--datadir:指定mysql数据存放目录
--basedir:指定mysql base目录
修改启动文件
vim /etc/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
创建用户、目录及授权
useradd -s /sbin/nologin -M mysql //创建用户
mkdir -p /data/mysql/binlog/ //创建bin-log目录
chown -R mysql.mysql /data/ //更改授权
环境变量
tail -1 /etc/profile
export PATH=/usr/local/mysql/bin:$PATH
source /etc/profile
初始化
mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
重载启动文件
systemctl daemon-reload //重载 启动
systemctl start mysqld
systemctl enable mysqld //加入开机自启动 [root@db01 bin]# netstat -lntup //检查3306端口是否开启
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 893/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 975/master
tcp6 0 0 :::3306 :::* LISTEN 1474/mysqld
tcp6 0 0 :::22 :::* LISTEN 893/sshd
tcp6 0 0 ::1:25 :::* LISTEN 975/master