LNMP+zabbix+负载均衡架构图————ansible自动部署
  d3hP2dZyxSet 2023年11月02日 63 0

架构图:

LNMP+zabbix+负载均衡架构图————ansible自动部署_vim

部署:

环境:

LVS+keepalived 192.168.246.10 192.168.246.20
LNP 192.168.246.30 192.168.246.40
MySQL 192.168.246.50 192.168.246.70 192.168.246.80
zabbix 192.168.246.60

1.安装ansible

[root@localhost ~]# yum install epel-release.noarch -y 
[root@localhost ~]# yum install -y ansible

2.配置免密登录

ssh-keygen
ssh-copy-id -i 192.168.246.10
ssh-copy-id -i 192.168.246.20
ssh-copy-id -i 192.168.246.30
ssh-copy-id -i 192.168.246.40
ssh-copy-id -i 192.168.246.50
ssh-copy-id -i 192.168.246.60
ssh-copy-id -i 192.168.246.70
ssh-copy-id -i 192.168.246.80
ssh-copy-id -i 192.168.246.90

3.创建角色并编写主机清单文件

mkdir /etc/ansible/playbook
ansible-galaxy init /etc/ansible/roles/host
ansible-galaxy init /etc/ansible/roles/yum_repo
ansible-galaxy init /etc/ansible/roles/LVS
ansible-galaxy init /etc/ansible/roles/keepalived1
ansible-galaxy init /etc/ansible/roles/keepalived2
ansible-galaxy init /etc/ansible/roles/LNP
ansible-galaxy init /etc/ansible/roles/mariadb
ansible-galaxy init /etc/ansible/roles/zabbix-server
ansible-galaxy init /etc/ansible/roles/zabbix-agent
ansible-galaxy init /etc/ansible/roles/master
ansible-galaxy init /etc/ansible/roles/slave
ansible-galaxy init /etc/ansible/roles/MHA-manager
vim /etc/ansible/hosts
[all_ip]
192.168.246.10
192.168.246.20
192.168.246.30
192.168.246.40
192.168.246.50
192.168.246.60

[nginx]
192.168.246.10
192.168.246.20

[LNP]
192.168.246.30
192.168.246.40

[zabbix]
192.168.246.50

[mysql]
192.168.246.60
192.168.246.70
192.168.246.80

[nodes]
192.168.246.20
192.168.246.30
192.168.246.40
192.168.246.10
192.168.246.60

[keepalived1]
192.168.246.10

[keepalived2]
192.168.246.20

[MHA-manager]
192.168.246.90

[slave]
192.168.246.70
192.168.246.80

[master]
192.168.246.60

ansible -m ping all_ip

3.编写host角色

vim /etc/ansible/roles/host/templates/hosts.j2
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

{% for host in groups.all %}
{ {hostvars[host].ansible_ens33.ipv4.address} } { {hostvars[host].ansible_name} }
{% endfor %}
vim /etc/ansible/roles/host/tasks/main.yml
- name: copy hosts.j2 to group servers
template:
src: hosts.j2
dest: /etc/hosts

4.编写yum_repo角色

vim /etc/ansible/roles/yum_repo/tasks/main.yml
- name: Find files in yum.repo.d/*
find:
paths: /etc/yum.repo.d/
patterns: '*'
register: files_to_delete

- name: Remove original yum.repo.d/*
file:
path: "{{ item.path }}"
state: absent
with_items: "{{ files_to_delete.files }}"

- name: Copy aliyun yum.repo to all nodes
copy:
src: yum.repo
dest: /etc/yum.repo.d/
yum install -y wget
wget -O /etc/ansible/roles/yum_repo/files/yum.repo http://mirrors.aliyun.com/repo/Centos-7.repo
mv Centos-7.repo yum.repo

5.编写LVS角色

vim /etc/ansible/roles/LVS/tasks/main.yml
- name: Insatll net-tools
yum:
name: net-tools
state: present


- name: copy RS.sh to RS
copy:
src: RS.sh
dest: /root/

- name: Config RS
shell: sh /root/RS.sh

vim /etc/ansible/roles/LVS/files/RS.sh
#!/bin/bash
vip="192.168.246.100"
mask="255.255.255.255"
ifconfig lo:0 $vip broadcast $vip netmask $mask up
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce

6.编写keppalived1角色

vim /etc/ansible/roles/keepalived1/tasks/main.yml
- name: Install Keepalived
yum:
name: keepalived
state: present

- name: move keepalived.conf
shell: "mv /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.back"
- name: Copy Config Keepalived
copy:
src: keepalived.conf
dest: /etc/keepalived/

- name: Strat keepalived
service:
name: keepalived
state: started
enabled: yes
vim /etc/ansible/roles/keepalived1/files/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id node1 # 设置lvs的id,一个网络中应该唯一
}
vrrp_instance VI_1 {
state MASTER # 指定Keepalived的角色
interface ens33 # 网卡
virtual_router_id 10 # 虚拟路由器ID,主备需要一样
priority 100 # 优先级越大越优,backup路由器需要设置比这小!
advert_int 1 # 检查间隔1s
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.246.100 # 定义虚拟IP地址,可以定义多个
}
}
# 定义虚拟主机,对外服务的IP和port
virtual_server 192.168.246.100 80 {
delay_loop 6 # 设置健康检查时间,单位是秒
lb_algo wrr # 负责调度算法
lb_kind DR # LVS负载均衡机制
persistence_timeout 0
protocol TCP
# 指定RS主机IP和port
real_server 192.168.246.30 80 {
weight 2
# 定义TCP健康检查
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 192.168.246.40 80 {
weight 1
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}

7.编写keppalived2角色

vim /etc/ansible/roles/keepalived2/tasks/main.yml
- name: Install Keepalived
yum:
name: keepalived
state: present

- name: move keepalived.conf
shell: "mv /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.back"
- name: Copy Config Keepalived
copy:
src: keepalived.conf
dest: /etc/keepalived/

- name: Strat keepalived
service:
name: keepalived
state: started
enabled: yes
vim /etc/ansible/roles/keepalived2/files/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id node2 # 设置lvs的id,一个网络中应该唯一
}
vrrp_instance VI_1 {
state BACKUP # 指定Keepalived的角色
interface ens33 # 网卡
virtual_router_id 10 # 虚拟路由器ID,主备需要一样
priority 99 # 优先级越大越优,backup路由器需要设置比这小!
advert_int 1 # 检查间隔1s
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.246.100 # 定义虚拟IP地址,可以定义多个
}
}
# 定义虚拟主机,对外服务的IP和port
virtual_server 192.168.246.100 80 {
delay_loop 6 # 设置健康检查时间,单位是秒
lb_algo wrr # 负责调度算法
lb_kind DR # LVS负载均衡机制
persistence_timeout 0
protocol TCP
# 指定RS主机IP和port
real_server 192.168.246.30 80 {
weight 2
# 定义TCP健康检查
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 192.168.246.40 80 {
weight 1
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}

8.编写LNP角色

vim /etc/ansible/roles/LNP/tasks/main.yml
- name: Install nginx
yum:
name: "{{ item }}"
state: present
loop:
- epel-release
- nginx
- wget

- name: Config nginx Service
service:
name: nginx
state: started
enabled: yes

- name: create group www
group:
name: www
gid: 666

- name: create user www
user:
name: www
uid: 666
groups: 666
shell: /sbin/nologin

- name: change nginx_user to www
shell: "sed -i '/^user/c user www;' /etc/nginx/nginx.conf"

- name: Download php
shell: "rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm"

- name: Install php
shell: "yum -y install php71w-* --skip-broken php71w-mysqlnd"

- name: change php_user
shell: "sed -i '/^user/c user = www' /etc/php-fpm.d/www.conf"

- name: change php_group
shell: "sed -i '/^group/c group = www' /etc/php-fpm.d/www.conf"

- name: Start php
service:
name: php-fpm
state: started
enabled: yes

- name: create typecho conf
copy:
src: typecho.conf
dest: /etc/nginx/conf.d/

- name: Restart nginx service
service:
name: nginx
state: restarted

- name: mkdir file typecho
file:
path: /typecho/
state: directory

- name: download typecho
shell: "wget http://typecho.org/downloads/1.1-17.10.30-release.tar.gz"

- name: tar typecho
shell: "tar xzvf 1.1-17.10.30-release.tar.gz -C /typecho"

- name: change typecho name
shell: "mv /typecho/build /typecho/typecho"

vim /etc/ansible/roles/LNP/files/typecho.conf
server {
listen 80;
server_name blog.iproute.cn;
root /typecho/typecho;
index index.php index.html;
location ~ .*\.php(\/.*)*$ {
root /typecho/typecho;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
include fastcgi_params;
}
}

9.编写mariadb角色

vim /etc/ansible/roles/mariadb/tasks/main.yml
- name: Install tool
yum:
name: wget
state: present

- name: Install Mariadb
yum:
name: mariadb-server
state: present

- name: Start mariadb
service:
name: mariadb
state: started
enabled: yes

- name: copy mariadb_config
copy:
src: config.sh
dest: /root/

- name: Config service
shell: "sh /root/config.sh"

- name: Restart mariadb
service:
name: mariadb
state: restarted

- name: Download MHA-node
shell: "wget -c --referer=https://pan.baidu.com/s/18tciTp1W2S466Usxeiv5IQ?pwd=w5qw -O mha4mysql-node-0.56-0.el6.noarch.rpm 'https://bdbl-cm01.baidupcs.com/file/67615a789828acc4e89801d61547344a?bkt=en-43ea5360a23c0e2039c06550cb90891c5fcdc201446d2825085213fc02b79c58aadb3fed9c3bff3d4916a205e27284149708f56ab6db988cf57703d145e872b7&fid=1837172481-250528-920387790047370&time=1665380024&sign=FDTAXUbGERLQlBHSKfWqiu-DCb740ccc5511e5e8fedcff06b081203-KFUmON%2F98HnnXSP%2BVZaiiqKcPiY%3D&to=401&size=36326&sta_dx=36326&sta_cs=4227&sta_ft=rpm&sta_ct=7&sta_mt=0&fm2=MH%2CBaoding%2CAnywhere%2C%2Cjiangsu%2Ccmnet&ctime=1529295035&mtime=1665304348&resv0=0&resv1=0&resv2=rlim&resv3=5&resv4=36326&vuk=1837172481&iv=0&htype=&randtype=&tkbind_id=0&newver=1&newfm=1&secfm=1&flow_ver=3&pkey=en-abfeb0f660fbae15dd7f751fef55a1a38bf2d1292bf94b4030019887580498fe7060230995a44bddc834793db5de188e52b9d7fa0743e233305a5e1275657320&sl=68616270&expires=8h&rt=sh&r=563541612&vbdid=384965884&fin=mha4mysql-node-0.56-0.el6.noarch.rpm&fn=mha4mysql-node-0.56-0.el6.noarch.rpm&rtype=1&dp-logid=8859325313021416060&dp-callid=0.1&hps=1&tsl=200&csl=200&fsl=0&csign=2TTYjB5dlpPthm1ZRF3sWWfyzKY%3D&so=0&ut=6&uter=4&serv=0&uc=1499419338&ti=5e666840c78f1973033b5cb2864c1fa0339192ca6e28a8a7305a5e1275657320&hflag=30&from_type=3&adg=c_4cbfa5fff088e55cae69bc58eb6a5c35&reqlabel=250528_f_afeab346d70254f377eca63ca8b513f7_-1_37457d3bb5a63f7aa0215148ba0b5a9f&by=themis&resvsflag=1-0-0-1-1-1'"

- name: Install MHA-node
yum:
name: mha4mysql-node-0.56-0.el6.noarch.rpm
state: present

vim /etc/ansible/roles/mariadb/files/config.sh
#!/bin/bash
mysqladmin password '1'
mysql -uroot -p1 -e 'create database blog;show databases;'
mysql -uroot -p1 -e "grant all on *.* to root@'192.168.246.%' identified by '1';"
mysql -uroot -p1 -e "install plugin rpl_semi_sync_master soname 'semisync_master.so';"
mysql -uroot -p1 -e "install plugin rpl_semi_sync_slave soname 'semisync_slave.so';"
mysql -uroot -p1 -e "set global rpl_semi_sync_master_enabled = 1;"
mysql -uroot -p1 -e "set global rpl_semi_sync_slave_enabled = 1;"
mysql -uroot -p1 -e "grant replication slave on *.* to 'master'@'192.168.246.%' identified by '1';"
mysql -uroot -p1 -e "flush privileges;"
id=`ip a | grep "noprefixroute ens33" | awk -F ' ' 'NR==1{print $2};' | awk -F '.' '{print $4}' | awk -F '/' '{print $1}'`
sed -i "3a server_id = $id" /etc/my.cnf
sed -i "4a log_bin = mysql_bin" /etc/my.cnf
sed -i "5a rpl_semi_sync_master_enabled = 1" /etc/my.cnf
sed -i "6a rpl_semi_sync_master_timeout = 3000" /etc/my.cnf
sed -i "6a rpl_semi_sync_slave_enabled = 1" /etc/my.cnf
sed -i "7a relay_log_purge = 0" /etc/my.cnf

10.编写zabbix-server角色

vim /etc/ansible/roles/zabbix-server/tasks/main.yml
- name: Download zabbix package
shell: "rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm"

- name: Install zabbix-server-mysql zabbix-web-mysql zabbix-agent mariadb
yum:
name: "{{ item }}"
state: present
loop:
- zabbix-server-mysql
- zabbix-web-mysql
- zabbix-agent
- mariadb-server

- name: Config mariadb service
service:
name: mariadb
state: started
enabled: yes
- name: set password for mariadb
shell: "mysqladmin password '1'"
- name: copy mariadb.sh to server
copy:
src: mariadb.sh
dest: /root/

- name: create zabbix for mariadb
shell: "sh /root/mariadb.sh"


- name: Configure the database for zabbix
shell: "sed -i '/# DBPassword=/c DBPassword=1' /etc/zabbix/zabbix_server.conf"

- name: Configure PHP for the Zabbix frontend
shell: "sed -i '/ # php_value date.timezone/c php_value date.timezone Asia/Shanghai ' /etc/httpd/conf.d/zabbix.conf"

- name: Start zabbix-server zabbox-agent service
service:
name: "{{ item }}"
state: started
enabled: yes
loop:
- zabbix-server
- zabbix-agent
- httpd
vim /etc/ansible/roles/zabbix-server/files/mariadb.sh
#!/bin/bash
#创建数据库
a=`mysql -uroot -p1 -e "show databases;" | grep "zabbix"`
if [[ $a != "zabbix" ]];then
mysql -uroot -p1 -e "create database zabbix character set utf8 collate utf8_bin;"
fi
#创建用户
b=`mysql -uroot -p1 -e "select user,host from mysql.user;" | grep -o "zabbix"`
if [[ $b != "zabbix" ]];then
mysql -uroot -p1 -e "grant all on zabbix.* to zabbix@localhost identified by '1';"
fi
#倒数数据库
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -D zabbix -p1

11.编写zabbix-agent角色

vim /etc/ansible/roles/zabbix-agent/templates/zabbix_agentd.conf.j2
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=192.168.246.50
ServerActive=192.168.246.50
Hostname={{ ansible_fqdn }}
vim /etc/ansible/roles/zabbix-agent/tasks/main.yml
- name: Install zabbix-agent package
shell: "rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm"

- name: install zabbix-agent
yum:
name: zabbix-agent
state: present

- name: delete /etc/zabbix_agentd.conf
shell: "mv /etc/zabbix/zabbix_agentd.conf{,.back}"
- name: copy
template:
src: zabbix_agentd.conf.j2
dest: /etc/zabbix/zabbix_agentd.conf
notify: server zabbix-agent
- name: systemctl
service:
name: zabbix-agent
state: started
vim /etc/ansible/roles/zabbix-agent/handlers/main.yml
- name: server zabbix-agent
service:
name: zabbix-agent
state: restarted

12.编写slave角色

vim /etc/ansible/roles/slave/tasks/main.yml
- name: copy slave.sh
copy:
src: slave.sh
dest: /root/

- name: Configure master slave replication
shell: "sh /root/slave.sh"

vim /etc/ansible/roles/slave/files/slave.sh
#!/bin/bash
log=`mysql -uroot -p1 -h 192.168.246.60 -e "show master status\G;" | grep File | awk -F ':' '{gsub (" ", "", $0);print $2}'`
positinotallow=`mysql -uroot -p1 -h 192.168.246.60 -e "show master status\G;" | grep Position | awk -F ':' '{gsub (" ", "", $0);print $2}'`
mysql -uroot -p1 -e "change master to master_host='192.168.246.60',master_user='master',master_password='1',master_log_file='$log',master_log_pos=$position;"
mysql -uroot -p1 -e "start slave;"

13.编写master角色

vim /etc/ansible/roles/master/tasks/main.yml
- name: copy
copy:
src: grant.sh
dest: /root/

- name: Authorized mhauser user
shell: "sh /root/grant.sh"

vim /etc/ansible/roles/master/files/grant.sh
#!/bin/bash
mysql -uroot -p1 -e "grant all on *.* to mhauser@'192.168.246.%' identified by '1';flush privileges;"
mysql -uroot -p1 -e "grant all on *.* to mhauser@server1 identified by '1';flush privileges;"

14.编写MHA-manager角色

vim /etc/ansible/roles/MHA-manager/tasks/main.yml 
- name: Install tool
yum:
name: wget
state: present

- name: Download manager
shell: "wget -c --referer=https://pan.baidu.com/s/1xpnbMayLlw4fmb9CC7MzBw?pwd=gpxr -O mha4mysql-manager-0.56-0.el6.noarch.rpm 'https://bdbl-cm01.baidupcs.com/file/bfd2603244cbe64f088c70f502d46629?bkt=en-660aa7a193f4106dad4b8b70a9f790600769e87fa62168f29c7ab1a450711c0110d887937ae2a7644f7c07e8720baadef6f00832b1912434476e7e4deeddf0fd&fid=1837172481-250528-946789936136925&time=1665392242&sign=FDTAXUbGERLQlBHSKfWqiu-DCb740ccc5511e5e8fedcff06b081203-jreBu2W94CeFgFuQEbNilBOxEbc%3D&to=401&size=87119&sta_dx=87119&sta_cs=3&sta_ft=rpm&sta_ct=7&sta_mt=1&fm2=MH%2CBaoding%2CAnywhere%2C%2Cjiangsu%2Ccmnet&ctime=1529295034&mtime=1665304348&resv0=0&resv1=0&resv2=rlim&resv3=5&resv4=87119&vuk=1837172481&iv=0&htype=&randtype=&tkbind_id=0&newver=1&newfm=1&secfm=1&flow_ver=3&pkey=en-e86209ee5f05f1d272ca3877a8727a3755c2e07c65b860596b0b4d6acf8819ef75be95342b682d8c6c5fb5de4c1044edb1afd2572e19ee65305a5e1275657320&sl=68616270&expires=8h&rt=sh&r=275990381&vbdid=384965884&fin=mha4mysql-manager-0.56-0.el6.noarch.rpm&fn=mha4mysql-manager-0.56-0.el6.noarch.rpm&rtype=1&dp-logid=8862605096816399425&dp-callid=0.1&hps=1&tsl=200&csl=200&fsl=0&csign=2TTYjB5dlpPthm1ZRF3sWWfyzKY%3D&so=0&ut=6&uter=4&serv=0&uc=1499419338&ti=a3dba1a35b3557e7692d933e0c749103d7161a89779a33c7&hflag=30&from_type=3&adg=c_4cbfa5fff088e55cae69bc58eb6a5c35&reqlabel=250528_f_afeab346d70254f377eca63ca8b513f7_-1_37457d3bb5a63f7aa0215148ba0b5a9f&by=themis&resvsflag=1-0-0-1-1-1'"

- name: Down node
shell: "wget -c --referer=https://pan.baidu.com/s/18tciTp1W2S466Usxeiv5IQ?pwd=w5qw -O mha4mysql-node-0.56-0.el6.noarch.rpm 'https://bdbl-cm01.baidupcs.com/file/67615a789828acc4e89801d61547344a?bkt=en-43ea5360a23c0e2039c06550cb90891c5fcdc201446d2825085213fc02b79c58aadb3fed9c3bff3d4916a205e27284149708f56ab6db988cf57703d145e872b7&fid=1837172481-250528-920387790047370&time=1665380024&sign=FDTAXUbGERLQlBHSKfWqiu-DCb740ccc5511e5e8fedcff06b081203-KFUmON%2F98HnnXSP%2BVZaiiqKcPiY%3D&to=401&size=36326&sta_dx=36326&sta_cs=4227&sta_ft=rpm&sta_ct=7&sta_mt=0&fm2=MH%2CBaoding%2CAnywhere%2C%2Cjiangsu%2Ccmnet&ctime=1529295035&mtime=1665304348&resv0=0&resv1=0&resv2=rlim&resv3=5&resv4=36326&vuk=1837172481&iv=0&htype=&randtype=&tkbind_id=0&newver=1&newfm=1&secfm=1&flow_ver=3&pkey=en-abfeb0f660fbae15dd7f751fef55a1a38bf2d1292bf94b4030019887580498fe7060230995a44bddc834793db5de188e52b9d7fa0743e233305a5e1275657320&sl=68616270&expires=8h&rt=sh&r=563541612&vbdid=384965884&fin=mha4mysql-node-0.56-0.el6.noarch.rpm&fn=mha4mysql-node-0.56-0.el6.noarch.rpm&rtype=1&dp-logid=8859325313021416060&dp-callid=0.1&hps=1&tsl=200&csl=200&fsl=0&csign=2TTYjB5dlpPthm1ZRF3sWWfyzKY%3D&so=0&ut=6&uter=4&serv=0&uc=1499419338&ti=5e666840c78f1973033b5cb2864c1fa0339192ca6e28a8a7305a5e1275657320&hflag=30&from_type=3&adg=c_4cbfa5fff088e55cae69bc58eb6a5c35&reqlabel=250528_f_afeab346d70254f377eca63ca8b513f7_-1_37457d3bb5a63f7aa0215148ba0b5a9f&by=themis&resvsflag=1-0-0-1-1-1'"

- name: Install MHA
yum:
name: "{{ item }}"
state: present
loop:
- mha4mysql-node-0.56-0.el6.noarch.rpm
- mha4mysql-manager-0.56-0.el6.noarch.rpm

- name: creaet directory for mha
file:
path: /etc/mha
state: directory

- name: creaet directory for mha_log
file:
path: /usr/local/mha
state: directory

- name: copy config to MHA-manager
copy:
src: default.conf
dest: /etc/mha/

- name: grant mha config
shell: "chmod +x /etc/mha/default.conf"

- name: Check whether ssh can be connected
shell: "masterha_check_ssh --cnotallow=/etc/mha/default.conf"

- name: Check whether MHA switches successfully
shell: "masterha_check_repl --cnotallow=/etc/mha/default.conf"

- name: Start MHA
shell: "masterha_manager --cnotallow=/etc/mha/default.conf 2>&1 &"

vim /etc/ansible/roles/MHA-manager/files/default.conf
[server default]
#设置具有spuer的用户
user=mhauser
#设置对应的密码
password=1
#设置ssh登录的用户名
ssh_user=root

#设置实例mysql的二进制文件目录
master_binlog_dir=/var/lib/mysql
#远端mysql发生切换时保存的二进制文件
remote_workdir=/data/log/masterha
#工作日志文件
manager_workdir=/usr/local/mha
#日志文件
manager_log=/etc/mha/manager.log

#设置监控主机的间隔时间,默认3秒
ping_interval=1
#设置复制环境中的复制用户名
repl_user=master
#设置复制用户名密码
repl_password=1

[server1]
hostname=192.168.246.60

[server2]
hostname=192.168.246.70
candidate_master=1

[server3]
hostname=192.168.246.80
#设置此库不成为master
no_master=1

15.编写汇总任务

vim /etc/ansible/playbook/site.yml
- name: Config hosts file
hosts: all_ip
roles:
- host

- name: Update all node yum.repo.file
hosts: all_ip
roles:
- yum_repo

- name: Config LVS service
hosts: LNP
roles:
- LVS

- name: Config keepalived
hosts: keepalived1
roles:
- keepalived1


- name: Config keepalived
hosts: keepalived2
roles:
- keepalived2

- name: Install LNMP
hosts: LNP
roles:
- LNP

- name: Install mysql
hosts: mysql
roles:
- mariadb

- name: Config slave
hosts: slave
roles:
- slave

- name: Config master
hosts: master
roles:
- master

- name: Config MHA
hosts: MHA-manager
roles:
- MHA-manager

- name: Install zabbix-server service
hosts: zabbix
roles:
- zabbix-server

- name: Install zabbix-agent
hosts: nodes
roles:
- zabbix-agent

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  bifOjSxj34Bv   2023年12月07日   37   0   0 nginxDockerdockernginx
d3hP2dZyxSet