环境:
CentOS7.4
CA主机一
mysql主机两台
数据库:MariaDB-5.5
一、准备证书文件
1.生成CA自签名证书
mkdir /etc/my.cnf.d/ssl
cd /etc/my.cnf.d/ssl
openssl genrsa 2048 > cakey.pem
chmod 600 cakey.pem
openssl req -new -x509 -key cakey.pem -days 3650 -out cacert.pem
2.生成master私钥以及证书申请
openssl req -newkey rsa:2048 -days 365 -nodes -keyout master.key > master.csr
3.给master颁发证书
openssl x509 -req -in master.csr -CA cacert.pem -CAkey cakey.pem -set_serial 01 > master.crt
4.生成slave私钥以及证书申请
openssl req -newkey rsa:2048 -days 365 -nodes -keyout slave.key > slave.csr
5.给slave颁发证书
openssl x509 -req -in slave.csr -CA cacert.pem -CAkey cakey.pem -set_serial 02 > slave.crt
6.将证书文件分别分发给master和slave
Master:
Slave:
二、主库配置
#修改/etc/my.cnf
#添加ssl等配置信息
创建从库复制用户,并仅允许通过ssl加密连接:
mysql> grant replication slave on *.* to 'repluser'@'192.168.1.%' identified by 'mysql' require ssl;
三、从库配置
#修改/etc/my.cnf
#添加ssl等配置信息
配置连接主库的信息:
change master to master_host='192.168.1.2',master_user='repluser',master_password='mysql',master_log_file='mariadb-bin.000001',master_log_pos=245,master_ssl=1;
start slave;
show slave status\G