Mysql1
#!/bin/bash
setenforce 0
systemctl stop firewalld
hostnamectl set-hostname mysql1
echo "10.0.100.203 mysql1" >> /etc/hosts
echo "10.0.100.204 mysql2" >> /etc/hosts
yum -y install expect
yum install -y mariadb mariadb-server
systemctl start mariadb
systemctl enable mariadb
expect -c "
spawn /usr/bin/mysql_secure_installation
expect \"Enter current password for root (enter for none):\"
send \"\r\"
expect \"Set root password?\"
send \"y\r\"
expect \"New password:\"
send \"000000\r\"
expect \"Re-enter new password:\"
send \"000000\r\"
expect \"Remove anonymous users?\"
send \"y\r\"
expect \"Disallow root login remotely?\"
send \"n\r\"
expect \"Remove test database and access to it?\"
send \"y\r\"
expect \"Reload privilege tables now?\"
send \"y\r\"
expect eof
"
sed -i -e '16a\log_bin = mysql-bin' /etc/my.cnf.d/mariadb-server.cnf
sed -i -e '17a\binlog_ignore_db = mysql' /etc/my.cnf.d/mariadb-server.cnf
sed -i -e '18a\server_id = 12' /etc/my.cnf.d/mariadb-server.cnf
systemctl restart mariadb
mysql -uroot -p000000 -e "grant all privileges on *.* to root@'%' identified by '000000';"
mysql -uroot -p000000 -e "grant replication slave on *.* to 'user'@'mysql2' identified by '000000';”
Mysql2