首页 > 编程语言 > 详细

python部署galery集群

时间:2019-03-02 23:21:05      阅读:213      评论:0      收藏:0      [点我收藏+]

galery.py文件内容

import pexpect 
import os  
import configparser

HOSTNAME_DB1=db1
HOSTNAME_DB2=db2
HOSTNAME_DB3=db3


DB1 = 192.168.254.30
DB2 = 192.168.254.31
DB3 = 192.168.254.39
PORT = 22
USERNAME = root
PASSWORD = root
#DB1
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))
res = os.system(galera_new_cluster &>/dev/null)
if res == 0:
    #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()

    child3 = pexpect.spawn(scp /etc/my.cnf.d/server.cnf %s@%s:/etc/my.cnf.d/server.cnf % (USERNAME,DB3)
)
    child3.expect(password:)
    child3.sendline(PASSWORD)
    child3.interact()
    child3.close()
#connect DB2
    child3 = pexpect.spawn(ssh %s@%s % (USERNAME, DB2))
    child3.expect(password:)
    child3.sendline(root)
    child3.expect(#)
    child3.sendline(sed -i "s/wsrep_node_name = db1/wsrep_node_name = db2/g" /etc/my.cnf.d/server.cnf;se
d -i "s/wsrep_node_address = 192.168.254.30/wsrep_node_address = 192.168.254.31/g" /etc/my.cnf.d/server.c
nf)
    child3.expect(#)
    child3.sendline(systemctl restart mariadb > /dev/null)
    child3.sendline(exit)
    child3.interact()
    child3.close()


    #connect DB3
    child4 = pexpect.spawn(ssh %s@%s % (USERNAME, DB3))
    child4.expect(password:)
    child4.sendline(root)
    child4.expect(#)
    child4.sendline(sed -i "s/wsrep_node_name = db1/wsrep_node_name = db3/g" /etc/my.cnf.d/server.cnf;se
d -i "s/wsrep_node_address = 192.168.254.30/wsrep_node_address = 192.168.254.39/g" /etc/my.cnf.d/server.c
nf)
    child4.expect(#)
    child4.sendline(systemctl restart mariadb > /dev/null)
    child4.sendline(exit)
    child4.interact()
    child4.close()
    print(galera集群配置完成)
else:
    print(galera服务启动故障)

server_db2.conf

[server]

[mysqld]

[galera]
wsrep_on = ON
wsrep_provider = /usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address = "gcomm://192.168.254.30,192.168.254.31,192.168.254.39"
wsrep_node_name = db2 
wsrep_node_address = 192.168.254.31
binlog_format = row 
default_storage_engine = InnoDB
innodb_autoinc_lock_mode = 2 
wsrep_slave_threads = 1 
innodb_flush_log_at_trx_commit = 1 
innodb_buffer_pool_size = 120M
wsrep_sst_method = rsync
wsrep_causal_reads = ON

[embedded]

[mariadb]

[mariadb-10.3]

 

python部署galery集群

原文:https://www.cnblogs.com/fengzi7314/p/10463386.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!