脚本自动安装MySQL主从(mycat)和 redis主从服务

本文档详细介绍了如何使用bash脚本来自动安装并配置MySQL的主从复制,接着讲解了Mycat的部署过程,最后阐述了Redis主从服务的设置,适合Linux环境下对数据库管理和自动化部署感兴趣的读者。

Mysql1

#!/bin/bash

#关闭防火墙及SELinux服务
setenforce 0
systemctl stop firewalld

#主机名修改为mysql1
hostnamectl set-hostname mysql1

#配置hosts文件
echo "10.0.100.203  mysql1" >> /etc/hosts
echo "10.0.100.204  mysql2" >> /etc/hosts

#下载expect 和 数据库
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


                
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Guest-yan

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值