啰嗦的话,不多说,我们直接开始部署,我相信有点linux基础的人都能看得懂。
Mysql5.7.22主从部署,既然是主从那肯定是需要至少2台服务器了,2台的安装都是一样的,请看下面!
1、 创建mysql用户:useradd -m -d /home/mysql mysql
2、 上传mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz安装包到/app目录下。
附官方下载链接:dev.mysql.com/downloads/f…
3、 解压安装包到/app目录下tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
4、 将解压完的安装包重命名为:mysql5722
mv mysql-5.7.22-linux-glibc2.12-x86_64 mysql5722
5、 进入mysql5722目录下创建data、logs目录。
cd mysql5722/ mkdir data && mkdir logs
6、 进入刚刚创建的logs目录下创建日志文件
cd logs touch error.log && touch general.log
授权/app/mysql5722目录属主属组为mysql
chown -R mysql:mysql /app/mysql5722
7、 进入mysql的bin目录下进行初始化设置:
cd ../bin/ ./mysqld --initialize --user=mysql --basedir=/app/mysql5722/ --datadir=/app/mysql5722/data
8、 创建mysql配置文件:
注意:初始化的时候会提示root用户的默认密码记得保存,首次登陆需要。
cd /etc/&& mv my.cnf my.cnf.bak
新建配置文件:touch my.cnf,内容如下:
Master节点配置文件内容:
[mysqld]
server-id=1
log_bin=master-bin
log_bin_index=master-bin.index
binlog_do_db=mysql
expire_logs_days=7
#skip-grant-tables
lower_case_table_names=1
explicit_defaults_for_timestamp
port = 3306
datadir = /app/mysql5722/data
socket = /app/mysql5722/mysql.sock
user = mysql
symbolic-links = 0
basedir = /app/mysql5722
big-tables
character-set-server = utf8
#general-log-file = /app/mysql5722/logs/general.log
language = /app/mysql5722/share
lc-messages-dir = /app/mysql5722/share
general-log = on
#GENERAL_LOG=ON
general-log-file = /app/mysql5722/logs/mysqld.log
slow-query-log = 1
pid-file = /app/mysql5722/mysql.pid
slow-query-log-file = /app/mysql5722/logs/mysqld_slow.log
slave-load-tmpdir = /app/mysql5722/tmp
plugin-dir = /app/mysql5722/lib/plugin
max_connections = 1000
#innodb
#innodb_log_file_size=512M
#innodb_buffer_pool_size=2G
[mysqld_safe]
log-error=/app/mysql5722/logs/mysql_error.log
pid-file=/app/mysql5722/mysql.pid
[client]
port = 3306
socket=/app/mysql5722/mysql.sock
user=mysql
9、 配置启动命令:
cd /app/mysql5722/support-files/
cp mysql.server /etc/init.d/mysqld
cd /etc/init.d/
修改mysqld配置文件内容添加如下两行信息:10、 配置开机启动
chkconfig --add mysqld chkconfig mysqld on chown -R mysql:mysql mysql5722/
11、 启动mysql数据库
service mysqld start
12、 登录mysql
./mysql -uroot -p'LRabR;xaS9lh'
修改root默认密码,不然无法执行sql:
./mysql -uroot -p'LRabR;xaS9lh' 修改root默认密码,不然无法执行sql: alter user user() identified by "Abcd@123";修改root用户密码 flush privileges;刷新 user mysql; create user 'master'@'%' identified by 'Abcd@123'; grant replication slave on . to 'master'@'%'; flush privileges show master status;
备slave节点配置文件:
[mysqld]
server-id=2
relay_log=slave-relay-bin
relay_log_index=slave-relay-bin.index
basedir=/app/mysql5722
datadir=/app/mysql5722/data
socket=/app/mysql5722/mysql.sock
user=mysql
character-set-server=utf8
lower_case_table_names=1
explicit_defaults_for_timestamp
port=3306
general-log=1
general-log-file=/app/mysql5722/logs/general.log
slow-query-log=1
long_query_time=1
slow_query_log_file=/app/mysql5722/slowquery.log
pid-file=/app/mysql5722/mysql.pid
slave-load-tmpdir=/app/mysql5722/slavetmp
max_connections=1000
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
#skip-grant-tables
[mysqld_safe]
log-error=/app/mysql5722/logs/error.log
pid-file=/app/mysql5722/mysql.pid
[client]
port=3306
socket=/app/mysql5722/mysql.sock
user=mysql
保存后重启从节点mysql。
备机:(slave)上配置:
登录mysql后执行:
user mysql;
change master to master_host='10.1.60.71',master_user='master',master_password='abcd@123',master_log_file='master-bin.000001',master_log_pos=154;
show slave status\G;
保证如下两个值都为YES说明主从复制已经配置成功,需要注意的是两台服务器的防火墙策略,网络必须是互通的。
Slave_IO_Running:YES Slave_SQL_Running:YES
当然此架构如果对外提供服务不想使用服务器的真实IP,你也可以安装keepalived做VIP对外进行提供服务!
作者:软件测试小dao