zoukankan      html  css  js  c++  java
  • python 部署lvs

    import paramiko
    
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    
    
    def direct_server():
    ssh.connect('192.168.200.12', 22, 'root', 'root',timeout=3)
    stdin, stdout, stderr = ssh.exec_command('ipvsadm -C;'
    'ipvsadm -A -t 192.168.200.250:80 -s wrr;'
    'ipvsadm -a -t 192.168.200.250:80 -r 192.168.254.20:80 -w 1 -g;'
    'ipvsadm -a -t 192.168.200.250:80 -r 192.168.254.25:80 -w 2 -g;'
    'ifconfig ens33:0 192.168.200.250 broadcast 192.168.200.250 netmask 255.255.255.255 up;'
    'route add -host 192.168.200.250 dev ens33:0')
    print(stderr.read().decode('utf-8'))
    print(stdout.read().decode('utf-8'))
    print('dicret_server配置完成!!!')
    
    
    def real_server1():
    ssh.connect('192.168.200.20', 22, 'root', 'root', timeout=3)
    stdin, stdout, stderr = ssh.exec_command('ifconfig lo:0 192.168.200.250 broadcast 192.168.200.250 netmask 255.255.255.255 up;'
    'route add -host 192.168.200.250 dev lo:0;'
    '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;'
    'service httpd restart')
    print(stderr.read().decode('utf-8'))
    print(stdout.read().decode('utf-8'))
    print('real_server1配置完成!!!')
    
    def real_server2():
    ssh.connect('192.168.200.25', 22, 'root', 'root', timeout=3)
    stdin, stdout, stderr = ssh.exec_command(
    'ifconfig lo:0 192.168.200.250 broadcast 192.168.200.250 netmask 255.255.255.255 up;'
    'route add -host 192.168.200.250 dev lo:0;'
    '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;'
    'service httpd restart')
    print(stderr.read().decode('utf-8'))
    print(stdout.read().decode('utf-8'))
    print('real_server2配置完成!!!')
    
    def main():
    direct_server()
    real_server1()
    real_server2()
    ssh.close()
    
    
    if __name__ == '__main__':
    main()
  • 相关阅读:
    css中的display以及position属性
    有人退税近4000元!个税年度汇算开始了,看看你能退多少?
    多维竞争
    阿里智能化接口测试平台--暴雪
    盗版网课有多猖狂?原价上万,只卖5元
    测试找BUG总结
    女程序员做了个梦。。。
    混沌的市场里,怎么一眼识别出「好房子」
    知乎扎心高赞:30岁还没有走到管理岗的人,后来怎么样了?
    自动化是在敏捷中提供连续测试的唯一方法
  • 原文地址:https://www.cnblogs.com/t-ym/p/11825681.html
Copyright © 2011-2022 走看看