Compare commits
No commits in common. 'b8c482a8ca779ea9c271bdf5bea75660403ce597' and 'abdc2b11b7e1c578e53e0fb5e78b6aa5af36ee01' have entirely different histories.
b8c482a8ca
...
abdc2b11b7
@ -1,42 +0,0 @@
|
|||||||
vim /etc/keepalived/keepalived.conf
|
|
||||||
|
|
||||||
! Configuration File for keepalived
|
|
||||||
global_defs {
|
|
||||||
notification_email {
|
|
||||||
acassen@firewall.loc
|
|
||||||
failover@firewall.loc
|
|
||||||
sysadmin@firewall.loc
|
|
||||||
}
|
|
||||||
notification_email_from Alexandre.Cassen@firewall.loc
|
|
||||||
smtp_server 192.168.200.1
|
|
||||||
smtp_connect_timeout 30
|
|
||||||
router_id LVS_DEVEL
|
|
||||||
vrrp_skip_check_adv_addr
|
|
||||||
vrrp_garp_interval 0
|
|
||||||
vrrp_gna_interval 0
|
|
||||||
}
|
|
||||||
vrrp_script nginx_check {
|
|
||||||
script "/tools/nginx_check.sh"
|
|
||||||
interval 1
|
|
||||||
}
|
|
||||||
vrrp_instance VI_1 {
|
|
||||||
state BACKUP
|
|
||||||
interface ens33
|
|
||||||
virtual_router_id 52
|
|
||||||
priority 99
|
|
||||||
advert_int 1
|
|
||||||
authentication {
|
|
||||||
auth_type PASS
|
|
||||||
auth_pass test
|
|
||||||
}
|
|
||||||
virtual_ipaddress {
|
|
||||||
192.168.149.100
|
|
||||||
}
|
|
||||||
track_script {
|
|
||||||
nginx_check
|
|
||||||
}
|
|
||||||
notify_master /tools/master.sh
|
|
||||||
notify_backup /tools/backup.sh
|
|
||||||
notify_fault /tools/fault.sh
|
|
||||||
notify_stop /tools/stop.sh
|
|
||||||
}
|
|
@ -1,42 +0,0 @@
|
|||||||
vim /etc/keepalived/keepalived.conf
|
|
||||||
|
|
||||||
! Configuration File for keepalived
|
|
||||||
global_defs {
|
|
||||||
notification_email {
|
|
||||||
acassen@firewall.loc
|
|
||||||
failover@firewall.loc
|
|
||||||
sysadmin@firewall.loc
|
|
||||||
}
|
|
||||||
notification_email_from Alexandre.Cassen@firewall.loc
|
|
||||||
smtp_server 192.168.200.1
|
|
||||||
smtp_connect_timeout 30
|
|
||||||
router_id LVS_DEVEL
|
|
||||||
vrrp_skip_check_adv_addr
|
|
||||||
vrrp_garp_interval 0
|
|
||||||
vrrp_gna_interval 0
|
|
||||||
}
|
|
||||||
vrrp_script nginx_check {
|
|
||||||
script "/tools/nginx_check.sh"
|
|
||||||
interval 1
|
|
||||||
}
|
|
||||||
vrrp_instance VI_1 {
|
|
||||||
state MASTER
|
|
||||||
interface ens33
|
|
||||||
virtual_router_id 52
|
|
||||||
priority 100
|
|
||||||
advert_int 1
|
|
||||||
authentication {
|
|
||||||
auth_type PASS
|
|
||||||
auth_pass test
|
|
||||||
}
|
|
||||||
virtual_ipaddress {
|
|
||||||
192.168.149.100
|
|
||||||
}
|
|
||||||
track_script {
|
|
||||||
nginx_check
|
|
||||||
}
|
|
||||||
notify_master /tools/master.sh
|
|
||||||
notify_backup /tools/backup.sh
|
|
||||||
notify_fault /tools/fault.sh
|
|
||||||
notify_stop /tools/stop.sh
|
|
||||||
}
|
|
@ -1,63 +0,0 @@
|
|||||||
import paramiko
|
|
||||||
|
|
||||||
def main():
|
|
||||||
# 创建SSH对象
|
|
||||||
ssh = paramiko.SSHClient()
|
|
||||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
||||||
|
|
||||||
# 连接服务器
|
|
||||||
ssh.connect(hostname='192.168.111.138', port=22, username='xumingyang', password='185102')
|
|
||||||
|
|
||||||
# 执行命令获取keepalived状态
|
|
||||||
stdin, stdout, stderr = ssh.exec_command('systemctl status keepalived.service')
|
|
||||||
|
|
||||||
# 获取命令输出
|
|
||||||
keepalived_state = stdout.read().decode('utf-8')
|
|
||||||
|
|
||||||
# print(keepalived_state)
|
|
||||||
|
|
||||||
# 执行命令获取ip状态
|
|
||||||
stdin1, stdout1, stderr1 = ssh.exec_command('ip a')
|
|
||||||
|
|
||||||
# 获取命令输出
|
|
||||||
ip_a = stdout1.read().decode('utf-8')
|
|
||||||
|
|
||||||
print(ip_a)
|
|
||||||
# 关闭连接
|
|
||||||
ssh.close()
|
|
||||||
|
|
||||||
ssh.connect(hostname='192.168.111.132', port=22, username='xumingyang', password='252237')
|
|
||||||
|
|
||||||
# 执行命令获取keepalived状态
|
|
||||||
stdin2, stdout2, stderr2 = ssh.exec_command('systemctl status keepalived.service')
|
|
||||||
|
|
||||||
# 获取命令输出
|
|
||||||
keepalived_state1 = stdout2.read().decode('utf-8')
|
|
||||||
|
|
||||||
# print(keepalived_state1)
|
|
||||||
|
|
||||||
# 执行命令获取ip状态
|
|
||||||
stdin3, stdout3, stderr3 = ssh.exec_command('ip a')
|
|
||||||
|
|
||||||
# 获取命令输出
|
|
||||||
ip_a1 = stdout3.read().decode('utf-8')
|
|
||||||
|
|
||||||
print(ip_a1)
|
|
||||||
# 关闭连接
|
|
||||||
ssh.close()
|
|
||||||
|
|
||||||
|
|
||||||
virtual_ip = '192.168.111.139'
|
|
||||||
if virtual_ip in ip_a:
|
|
||||||
message='192.168.111.138 is Master'
|
|
||||||
else:
|
|
||||||
message='192.168.111.138 is Backup'
|
|
||||||
|
|
||||||
if virtual_ip not in ip_a1:
|
|
||||||
message2='192.168.111.132 is Backup'
|
|
||||||
else:
|
|
||||||
message2='192.168.111.132 is Master'
|
|
||||||
return message+' '+message2
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
|
Loading…
Reference in new issue