1、MySQL的高可性解决方案MHA实战
ip | 服务 |
---|
172.16.0.7 | mysql master |
172.16.0.17 | mysql slave |
172.16.0.27 | MHA |
#在MHA服务器安装
[root@mha-manager ~]#yum -y install mha4mysql-manager-0.58-0.el7.centos.noarch.rpm
[root@mha-manager ~]#yum -y install mha4mysql-node-0.58-0.el7.centos.noarch.rpm
#在所有mysql服务器安装
[root@master ~]#yum -y install mha4mysql-node-0.58-0.el7.centos.noarch.rpm
#在所有节点实现相互之间ssh key验证
[root@mha-manager ~]# ssh-keygen
[root@mha-manager ~]# ssh-copy-id 172.16.0.7
[root@mha-manager ~]# ssh-copy-id 172.16.0.17
[root@mha-manager ~]# ssh-copy-id 172.16.0.27
[root@mha-manager ~]# mkdir /etc/mastermha/
[root@mha-manager ~]# vim /etc/mastermha/app1.cnf
[server default]
user=mhauser
password=123456
manager_workdir=/data/mastermha/app1/
manager_log=/data/mastermha/app1/manager.log
remote_workdir=/data/mastermha/app1/
ssh_user=root
repl_user=repluser
repl_password=123456
ping_interval=1
check_repl_delay=0
master_binlog_dir=/data/mysql/
[server1]
hostname=172.16.0.7
candidate_master=1
[server2]
hostname=172.16.0.17
#配置mysql master节点
[root@master ~]#vim /etc/my.cnf
[mysqld]
server_id=7
log-bin=/data/mysql/mysql-bin
skip_name_resolve=1
mysql>grant replication slave on *.* to repluser@'172.16.0.%' identified by
'123456';
mysql>grant all on *.* to mhauser@'172.16.0.%' identified by '123456';
#配置mysql slave节点
[root@slave ~]#vim /etc/my.cnf
[mysqld]
server_id=17
log-bin=/data/mysql/mysql-bin
read_only
relay_log_purge=0
skip_name_resolve=1
mysql>CHANGE MASTER TO MASTER_HOST='MASTER_IP', MASTER_USER='repluser',
MASTER_PASSWORD='123456', MASTER_LOG_FILE='master-bin.000001',
MASTER_LOG_POS=245;
mysql>START SLAVE;
#检查MHA环境
[root@mha-manager ~]# masterha_check_ssh --conf=/etc/mastermha/app1.cnf
[root@mha-manager ~]# masterha_check_repl --conf=/etc/mastermha/app1.cnf
#启动MHA
[root@mha-manager ~]# nohup masterha_manager --conf=/etc/mastermha/app1.cnf &> /dev/null
#当master down机后,mha自动退出
[root@mha-manager ~]#cat /data/mastermha/app1/manager.log
2、Ansible常用模块总结
Ansible常用模块 | |
---|
Shell | shell执行命令 |
Scipt | 脚本 |
Copy | 服务器复制文件到远程主机 |
Fetch | 从远程主机提取文件至服务器 |
File | 设置文件属性 |
Unarchive | 解包解压缩 |
Archive | 打包压缩 |
Hostname | 管理主机名 |
Cron | 计划任务 |
Yum | 管理软件包 |
Service | 管理服务 |
User | 管理用户 |
Group | 管理组 |
3、Ansible playbook实现zabbix-agent批量部署(主机名不同)
ip | 服务 |
---|
172.16.0.27 | ansible |
172.16.0.7 | zabbix-agent1 |
172.16.0.17 | zabbix-agent2 |
#在ansible
[root@ansible ~]# yum -y install ansible
[root@ansible ~]# ssh-keygen
[root@ansible ~]# ssh-copy-id 172.16.0.7
[root@ansible ~]# ssh-copy-id 172.16.0.17
[root@ansible ~]# ssh-copy-id 172.16.0.27
[root@ansible ~]# vim /etc/ansible/hosts
[zabbix_agent]
172.16.0.7
172.16.0.17
[root@ansible ~]# wget https: