一, 环境准备
主网 IP | 私网 IP | 主机名 | 角色 | VIP |
---|---|---|---|---|
10.203.178.125 | 192.168.10.2 | cnsz22VLK12919 | 主 | 10.203.178.137,192.168.10.1 |
10.203.178.127 | 192.168.10.3 | cnsz22VLK12918 | 备 | - |
二, 安装配置 dhcp
1,10.203.178.125 配置 dhcp 服务
a,dhcp 服务软件安装
yum install -y dhcpd
b, 修改配置文件
- VIM /etc/dhcp/dhcpd.conf
- # cobbler slave dhcpd
- ddns-update-style interim;
- allow booting;
- allow bootp;
- ignore client-updates;
- set vendorclass = option vendor-class-identifier;
- option pxe-system-type code 93 = unsigned integer 16;
- subnet 192.168.10.0 netmask 255.255.254.0 {
- option routers 192.168.10.1;
- option domain-name-servers 10.202.32.100;
- option subnet-mask 255.255.254.0;
- range dynamic-bootp 192.168.10.10 192.168.10.199;
- default-lease-time 7200;
- max-lease-time 14400;
- next-server 10.203.178.137;
- class "pxeclients" {
- match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
- if option pxe-system-type = 00:02 {
- filename "ia64/elilo.efi";
- } else if option pxe-system-type = 00:06 {
- filename "grub/grub-x86.efi";
- } else if option pxe-system-type = 00:07 {
- filename "grub/grub-x86_64.efi";
- } else {
- filename "pxelinux.0";
- }
- }
- }
c, 启动 dhcpd 服务:
- service dhcpd restart
- service dhcpd status
2,10.203.178.127 配置 dhcp 服务
a, 安装 dhcp 服务
同上
b, 配置 dhcp 服务
同上, 但修改下列行到另一个 c 类地址段
range dynamic-bootp 192.168.11.10 192.168.11.199;
c, 启动 dhcpd 服务:
同上
三, 安装配置 cobbler
略
四, 安装配置 keepalived
1,10.203.178.125 安装 keepalived 服务
a, 软件安装
yum install -y keepalived
b, 配置 keepalived
- VIM /etc/keepalived/scripts/keepalived.conf
- global_defs {
- router_id pribms.dev
- }
- vrrp_script chk_http1 {
- script "/etc/keepalived/scripts/check_healthy.sh"
- interval 2
- }
- vrrp_instance VI_1 {
- state BACKUP
- interface eth0
- virtual_router_id 137
- priority 100
- nopreempt
- advert_int 1
- authentication {
- auth_type PASS
- auth_pass 1qaz@WSX
- }
- virtual_ipaddress {
- 10.203.178.137
- }
- track_script {
- chk_http1
- }
- master_notify /etc/keepalived/scripts/restart_cobblerd.sh
- }
- vrrp_instance VI_2 {
- state BACKUP
- interface eth3
- virtual_router_id 101
- priority 100
- nopreempt
- advert_int 1
- authentication {
- auth_type PASS
- auth_pass 2wsx#EDC
- }
- virtual_ipaddress {
- 192.168.10.1
- }
- }
c, 创建 keepalived 健康检查脚本
- VIM /etc/keepalived/scripts/check_healthy.sh
- #!/bin/bash
- stop_keepalived() {
- service keepalived stop
- exit 1
- }
- nc -w 10 -z 127.0.0.1 80 || service httpd restart
- nc -w 10 -z 127.0.0.1 8080 || /bin/bash /App/cloud-pri-bms/code/run_app.sh restart
- sleep 2
- nc -w 10 -z 127.0.0.1 80 || stop_keepalived
- nc -w 10 -z 127.0.0.1 8080 || stop_keepalived
d, 创建 keepalived 角色切换为主之后的触发脚本
- VIM /etc/keepalived/scripts/restart_cobblerd.sh
- #!/bin/bash
- #Auther: Harry
- #Date: 2019-09-12
- /etc/init.d/cobblerd restart
- /usr/bin/cobbler sync
e, 启动 keepalived 并设置开机启动
- # 启动服务
- service keepalived start
- ip a
- # 打开开机自启动并验证:
- chkconfig keepalived on
- chkconfig keepalived --list
2,10.203.178.127 安装 keepalived 服务
a, 软件安装
同上
b, 配置 keepalived
同上
- # 修改
- priority 99
- # 删除
- nopreempt
c, 创建 keepalived 监控检查脚本
同上
d, 创建 keepalived 角色切换为主之后的触发脚本
同上
e, 启动 keepalived 并设置开机启动
同上
五, 安装配置 rsync 服务:
功能: rysnc 客户端可以将指定目录中的文件同步到 rsync 服务器端
1,10.203.178.125 配置 rsync 服务
a, 安装 rsync,xinetd,inotify-tools 软件
yum install -y rsync xinetd inotify-tools
b, 编辑 rsyncd.conf 配置文件
VIM /etc/cobbler/rsync.template
在前面插入下面这段
- log file = /var/log/rsyncd.log
- pidfile = /var/run/rsyncd.pid
- lock file = /var/run/rsync.lock
- secrets file = /etc/rsync.pass
- motd file = /etc/rsyncd.Motd
- [systems]
- path = /App/cobbler/config/systems.d/
- comment = systemd
- uid = root
- gid = root
- use chroot = no
- read only = no
- list = no
- max connections = 200
- timeout = 600
- auth users = appfiles_user
- hosts allow = 10.203.178.127
- [tftpboot]
- path = /App/tftpboot/
- comment = tftpboot
- uid = root
- gid = root
- use chroot = no
- read only = no
- list = no
- max connections = 200
- timeout = 600
- auth users = appfiles_user
- hosts allow = 10.203.178.127
同步到 / etc/rsyncd.conf 配置文件中
cobbler sync
c, 设置 rsync 同步的账号和密码
- echo "appfiles_user:Ken930dy"> /etc/rsync.pass
- chmod 600 /etc/rsyncd.conf
- chmod 600 /etc/rsync.pass
d, 配置 rsync 同步密码
- echo Ken930dy> /etc/keepalived/passwd.txt
- chmod 600 /etc/keepalived/passwd.txt
e, 设置 rsync 服务开机自启动
- chkconfig rsync on
- chkconfig rsync --list
f, 配置 rsync_inotify.sh 脚本文件
同步路径:
- src1=/App/cobbler/config/systems.d/
- src2=/App/tftpboot/
- VIM /opt/rsync_scripts/rsync_inotify.sh
- #!/bin/bash
- #chenzexin
- #20150608
- export PATH=$PATH:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/binsbin:/bin:/usr/sbin:/usr/bin:/root/bin
- src1=/App/cobbler/config/systems.d/
- src2=/App/tftpboot/
- des1=systems
- des2=tftpboot
- passwdfile=/etc/keepalived/passwd.txt
- ip=10.203.178.127
- logfile=/var/log/rsync_app.log
- if ! grep -q 8192000 /proc/sys/fs/inotify/max_user_watches ; then
- echo 8192000> /proc/sys/fs/inotify/max_user_watches
- fi
- /usr/bin/inotifywait -mrq --timefmt '%Y-%m-%d %H:%M' --format '%T %w%f %e' -modify,delete,create,attrib $src1 | \
- while read file ; do
- rsync -vzrtopg --delete --progress $src1 appfiles_user@$ip::$des1 --passworfile=$passwdfile
- echo "$file was synced">> ${
- logfile
- } 2>&1
- done &
- /usr/bin/inotifywait -mrq --timefmt '%Y-%m-%d %H:%M' --format '%T %w%f %e' -modify,delete,create,attrib $src2 | \
- while read file ; do
- rsync -vzrtopg --delete --progress $src2 appfiles_user@$ip::$des2 --passworfile=$passwdfile
- echo "$file was synced">> ${
- logfile
- } 2>&1
- done &
- sleep 2
- date '+%Y-%m-%d %H:%M:%S'>> $src1/rync_date
- date '+%Y-%m-%d %H:%M:%S'>> $src2/rync_date
- wait
2,10.203.178.127 配置 rsync 服务
a, 安装 rsync,xinetd,inotify-tools 软件
同上
b, 编辑 rsyncd.conf 配置文件
VIM /etc/cobbler/rsync.template
同上
- # 修改
- hosts allow = 10.203.178.125
同步到 / etc/rsyncd.conf 配置文件中
同上
c, 设置 rsync 同步的账号和密码
同上
d, 配置 rsync 同步密码
同上
e, 重启 xinetd 服务并设置 rsync 服务开机自启动
- chkconfig rsync on
- chkconfig rsync --list
- service xinetd restart
f, 配置 rsync_inotify.sh 脚本文件
同上
- # 修改
- ip=10.203.178.125
六, 故障恢复:
1, 场景简介
正常情况下, 10.203.178.125 作为主节点提供服务
10.203.178.127 作为备节点
主节点上的数据实时同步到备节点
2, 主节点 10.203.178.125 宕机的情况
a, 恢复 10.203.178.125 服务
检查 httpd 服务
- service httpd status
- service httpd start
检查 cobbler 服务
- service cobblerd status
- service cobblerd start
检查 API 服务
- telnet 127.0.0.1 8080
- /bin/bash /App/cloud-pri-bms/code/run_app.sh start
b, 同步 10.203.178.127 数据到 10.203.178.125
10.203.178.125 检查并启动 xinetd 服务
- /etc/init.d/xinetd status
- /etc/init.d/xinetd start #未启动则手动启动服务
10.203.178.127 执行同步脚本并创建文件
- nohup sh /opt/rsync_scripts/rsync_inotify.sh>>/App/clog/rsync.log 2>&1 &
- touch /App/cobbler/config/systems.d/1111.txt
- touch /App/tftpboot/2222.txt
10.203.178.125 上验证是否同步:
- ll /App/cobbler/config/systems.d/
- ll /App/tftpboot/
10.203.178.127 上删掉刚才创建的文件
- rm /App/cobbler/config/systems.d/1111.txt
- rm /App/tftpboot/2222.txt
c, 启动 10.203.178.125 高可用服务
检查 keepalived 服务并启动
- service keepalived status
- service keepalived start
3, 备节点 10.203.178.127 宕机的情况
a, 恢复 10.203.178.127 服务
检查 httpd 服务
- service httpd status
- service httpd start
检查 cobbler 服务
- service cobblerd status
- service cobblerd start
检查 API 服务
- telnet 127.0.0.1 8080
- /bin/bash /App/cloud-pri-bms/code/run_app.sh start
b, 同步 10.203.178.125 数据到 10.203.178.127
10.203.178.127 检查并启动 xinetd 服务
- service xinetd status
- service xinetd start
10.203.178.125 执行同步脚本并创建文件
- touch /App/cobbler/config/systems.d/1111.txt
- touch /App/tftpboot/2222.txt
10.203.178.127 上验证是否同步
- ll /App/cobbler/config/systems.d/
- ll /App/tftpboot/
10.203.178.125 上删掉刚才创建的文件
- rm /App/cobbler/config/systems.d/1111.txt
- rm /App/tftpboot/2222.txt
10.203.178.127 重启 cobbler 服务并同步
- service cobblerd restart
- cobbler sync
c, 启动 10.203.178.127 高可用服务
检查 keepalived 服务并启动
- service keepalived status
- service keepalived start
来源: https://www.cnblogs.com/dragon7421/p/11540083.html