zoukankan      html  css  js  c++  java
  • python部署galery集群

    galery.py文件内容

    import pexpect
    import os
    import configparser
    
    HOSTNAME_DB1='db1'
    HOSTNAME_DB2='db2'
    HOSTNAME_DB3='db3'
    DB1 = '192.168.254.24'
    DB2 = '192.168.254.27'
    DB3 = '192.168.254.36'
    PORT = 22
    USERNAME = 'root'
    PASSWORD = 'root'
    
    server3_cnf = 'sed -i "s/wsrep_node_name = db1/wsrep_node_name = db3/g" /etc/my.cnf.d/server.cnf;sed -i "s/wsrep_node_address = %s/wsrep_node_address = %s/g" /etc/my.cnf.d/server.cnf' % (DB1,DB3)
    server2_cnf = 'sed -i "s/wsrep_node_name = db1/wsrep_node_name = db3/g" /etc/my.cnf.d/server.cnf;sed -i "s/wsrep_node_address = %s/wsrep_node_address = %s/g" /etc/my.cnf.d/server.cnf' % (DB1,DB3)
    def config_parse():
        config = configparser.ConfigParser()
        config.read("/etc/my.cnf.d/server.cnf", encoding="utf-8")
        config.set('galera','wsrep_on','ON')
        config.set('galera','wsrep_provider','/usr/lib64/galera/libgalera_smm.so')
        config.set('galera','wsrep_cluster_address','"gcomm://%s,%s,%s"' % (DB1, DB2, DB3))
        config.set('galera','wsrep_node_name','%s' % HOSTNAME_DB1 )
        config.set('galera','wsrep_node_address','%s' % DB1)
        config.set('galera','binlog_format','row')
        config.set('galera','default_storage_engine','InnoDB')
        config.set('galera','innodb_autoinc_lock_mode','2')
        config.set('galera','wsrep_slave_threads','1')
        config.set('galera','innodb_flush_log_at_trx_commit','1')
        config.set('galera','innodb_buffer_pool_size','120M')
        config.set('galera','wsrep_sst_method','rsync')
        config.set('galera','wsrep_causal_reads','ON')
        config.write(open('/etc/my.cnf.d/server.cnf','w'))
    def cp_server_cnf():
        child1 = pexpect.spawn('scp /etc/my.cnf.d/server.cnf %s@%s:/etc/my.cnf.d/server.cnf' % (USERNAME,DB2))
        child1.expect('password:')
        child1.sendline(PASSWORD)
        child1.interact()
        child1.close()
        child2 = pexpect.spawn('scp /etc/my.cnf.d/server.cnf %s@%s:/etc/my.cnf.d/server.cnf' % (USERNAME,DB3))
        child2.expect('password:')
        child2.sendline(PASSWORD)
        child2.interact()
    
        child2.close()
    def conn_db(ip,cnf):
        child3 = pexpect.spawn('ssh %s@%s' % (USERNAME, ip))
        child3.expect('password:')
        child3.sendline('root')
        child3.expect('#')
        child3.sendline(cnf)
        child3.expect('#')
        child3.sendline('systemctl restart mariadb > /dev/null')
        child3.sendline('exit')
        child3.interact()
        child3.close()
    def init_cmd():
        res1 = os.system('service mariadb stop')
        res2 = os.system('mysqld_safe --wsrep_cluster_address=gcomm://%s,%s,%s >/dev/null &' % (DB1, DB2, DB3))
        res3 = os.system('galera_new_cluster &>/dev/null')
        if res2 == 0:
            print('galera初始化完成')
            if res3 == 0:
                print('galera集群已经启动')
            else:
                print('galera集群启动失败')
        else:
            print('galera初始化失败!')
    def main():
        config_parse()
        cp_server_cnf()
        init_cmd()
        conn_db(DB2,server2_cnf)
        conn_db(DB3,server3_cnf)
    
    
    if __name__ == '__main__':
        main()
    View Code
  • 相关阅读:
    3. 尾缀
    Cocos工程命名规则整理(node部分)
    3.1-3.3 HBase Shell创建表
    2.11-2.12 HBase的数据迁移常见方式
    2.8-2.10 HBase集成MapReduce
    2.7 HBase架构深入剖析
    2.3-2.6 HBase java API
    2.1-2.2 HBase数据存储
    1.6-1.8 HBase表的物理模型
    1.4-1.5 HBase部署及基本使用
  • 原文地址:https://www.cnblogs.com/fengzi7314/p/10463386.html
Copyright © 2011-2022 走看看