啰嗦的话,不多说,我们直接开始部署,我信赖有点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目录下。
附官方下载链接:https://dev.mysql.com/downloads/file/?id=476936
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
注意:初始化的时间会提示root用户的默认暗码记得保存,首次登岸需要。
8、 创建mysql配置文件:
cd /etc/&& mv my.cnf my.cnf.bak
新建配置文件:touch my.cnf,内容如下:
Master节点配置文件内容:
[mysqld]server-id=1log_bin=master-binlog_bin_index=master-bin.indexbinlog_do_db=mysqlexpire_logs_days=7#skip-grant-tableslower_case_table_names=1explicit_defaults_for_timestampport = 3306datadir = /app/mysql5722/datasocket = /app/mysql5722/mysql.sockuser = mysqlsymbolic-links = 0basedir = /app/mysql5722big-tablescharacter-set-server = utf8#general-log-file = /app/mysql5722/logs/general.loglanguage = /app/mysql5722/sharelc-messages-dir = /app/mysql5722/sharegeneral-log = on#GENERAL_LOG=ONgeneral-log-file = /app/mysql5722/logs/mysqld.logslow-query-log = 1pid-file = /app/mysql5722/mysql.pidslow-query-log-file = /app/mysql5722/logs/mysqld_slow.logslave-load-tmpdir = /app/mysql5722/tmpplugin-dir = /app/mysql5722/lib/pluginmax_connections = 1000#innodb#innodb_log_file_size=512M#innodb_buffer_pool_size=2G[mysqld_safe]log-error=/app/mysql5722/logs/mysql_error.logpid-file=/app/mysql5722/mysql.pid[client]port = 3306socket=/app/mysql5722/mysql.sockuser=mysql9、 配置启动命令:
cd /app/mysql5722/support-files/
cp mysql.server /etc/init.d/mysqld
cd /etc/init.d/
修改mysqld配置文件内容添加如下两行信息:
10、 配置开机启动
chkconfig --add mysqldchkconfig mysqld onchown -R mysql:mysql mysql5722/11、 启动mysql数据库
service mysqld start
12、 登录mysql
./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 privilegesshow master status;备slave节点配置文件:
vim /etc/my.cnf
[mysqld]server-id=2relay_log=slave-relay-binrelay_log_index=slave-relay-bin.indexbasedir=/app/mysql5722datadir=/app/mysql5722/datasocket=/app/mysql5722/mysql.sockuser=mysqlcharacter-set-server=utf8lower_case_table_names=1explicit_defaults_for_timestampport=3306general-log=1general-log-file=/app/mysql5722/logs/general.logslow-query-log=1long_query_time=1slow_query_log_file=/app/mysql5722/slowquery.logpid-file=/app/mysql5722/mysql.pidslave-load-tmpdir=/app/mysql5722/slavetmpmax_connections=1000# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0#skip-grant-tables[mysqld_safe]log-error=/app/mysql5722/logs/error.logpid-file=/app/mysql5722/mysql.pid[client]port=3306socket=/app/mysql5722/mysql.sockuser=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对外进行提供服务!
更加详细的内容,可以转发关注我哦,咱们一起在技术的这条道路上相互资助前进! |