#Mariadb Galera Cluster 羣集 安裝部署html
openstack pike 部署 目錄彙總 http://www.cnblogs.com/elvi/p/7613861.htmlnode
#Mariadb Galera Cluster羣集 # ########################### # ##基本設置 # #配置hosts # echo '#Ha # 192.168.58.21 controller1 # 192.168.58.22 controller2 # 192.168.58.23 controller3 # '>>/etc/hosts # #免密驗 # #controller1 ssh免密驗證 # ssh-keygen -t rsa -P '' -f ~/.ssh/id_dsa # ssh-copy-id -i ~/.ssh/id_dsa.pub root@controller2 # ssh-copy-id -i ~/.ssh/id_dsa.pub root@controller2 # #其它節點同樣 # #shell批量配置http://www.cnblogs.com/elvi/p/7681779.html # ########################### # #每一個節點執行 # #配置內核 # echo ' # * soft nofile 65536 # * hard nofile 65536 # '>>/etc/security/limits.conf # # # echo ' # fs.file-max=655350 # net.ipv4.ip_local_port_range = 1025 65000 # net.ipv4.tcp_tw_recycle = 1 # '>>/etc/sysctl.conf # sysctl -p # ########################### #MariaDB Galera 安裝 yum install mariadb mariadb-server mariadb-galera-server -y yum install expect -y #SQL root密碼 DBPass=open2017 #配置數據庫 echo "# [mysqld] bind-address = 0.0.0.0 default-storage-engine = innodb innodb_file_per_table max_connections = 4096 collation-server = utf8_general_ci character-set-server = utf8 #">/etc/my.cnf.d/openstack.cnf #啓動數據庫服務 #systemctl enable mariadb.service systemctl start mariadb.service #mysql_secure_installation #初始化設置密碼,自動交互 /usr/bin/expect << EOF set timeout 30 spawn mysql_secure_installation expect { "enter for none" { send "\r"; exp_continue} "Y/n" { send "Y\r" ; exp_continue} "password:" { send "$DBPass\r"; exp_continue} "new password:" { send "$DBPass\r"; exp_continue} "Y/n" { send "Y\r" ; exp_continue} eof { exit } } EOF #測試 mysql -u root -p$DBPass -e "show databases;" [ $? = 0 ] || { echo "mariadb初始化失敗";exit; } ############# #galera配置 /usr/bin/cp /etc/my.cnf.d/galera.cnf{,.bak} egrep -v "#|^$" /etc/my.cnf.d/galera.cnf.bak >/etc/my.cnf.d/galera.cnf sed -i 's/wsrep_on=1/wsrep_on=ON/' /etc/my.cnf.d/galera.cnf sed -i 's/wsrep_sst_auth=root:/wsrep_sst_auth=root:'$DBPass'/' /etc/my.cnf.d/galera.cnf ########### #controller1節點 sed -i 's/bind-address = 0.0.0.0/bind-address = controller1/' /etc/my.cnf.d/openstack.cnf echo ' wsrep_cluster_address="gcomm://controller1,controller2,controller3" wsrep_node_name=controller1 wsrep_node_address=controller1 '>>/etc/my.cnf.d/galera.cnf cat /etc/my.cnf.d/galera.cnf systemctl daemon-reload systemctl stop mariadb.service galera_new_cluster #啓動第一個節點 ############# #controller2節點 sed -i 's/bind-address = 0.0.0.0/bind-address = controller2/' /etc/my.cnf.d/openstack.cnf echo ' wsrep_cluster_address="gcomm://controller1,controller2,controller3" wsrep_node_name=controller2 wsrep_node_address=controller2 '>>/etc/my.cnf.d/galera.cnf systemctl restart mariadb.service #controller3節點 sed -i 's/bind-address = 0.0.0.0/bind-address = controller3/' /etc/my.cnf.d/openstack.cnf echo ' wsrep_cluster_address="gcomm://controller1,controller2,controller3" wsrep_node_name=controller3 wsrep_node_address=controller3 '>>/etc/my.cnf.d/galera.cnf systemctl restart mariadb.service #其它節點啓動後,重啓第一個節點 controller1 systemctl restart mariadb.service #檢測 netstat -antp|grep mysqld mysql -u root -p$DBPass -e "show status like 'wsrep_cluster_size';" mysql -u root -p$DBPass -e "show status like 'wsrep_incoming_addresses';" #建立用於監控的mariadb 用戶haproxy (haproxy代理,監控使用) mysql -u root -p$DBPass -e "create user 'haproxy'@'%';flush privileges;" #root遠程訪問設置 mysql -u root -p$DBPass -e " grant all privileges on *.* to 'root'@'%' identified by '$DBPass' with grant option; flush privileges; select user,host,password from mysql.user;" ########################################## ##部署成功,檢測結果以下 # [root@controller1 ~]# mysql -u root -p$DBPass -e "show status like 'wsrep_cluster_size';" # +--------------------+-------+ # | Variable_name | Value | # +--------------------+-------+ # | wsrep_cluster_size | 3 | # +--------------------+-------+ # [root@controller1 ~]# mysql -u root -p$DBPass -e "show status like 'wsrep_incoming_addresses';" # +--------------------------+----------------------------------------------------+ # | Variable_name | Value | # +--------------------------+----------------------------------------------------+ # | wsrep_incoming_addresses | controller1:3306,controller2:3306,controller3:3306 | # +--------------------------+----------------------------------------------------+
# #排錯
# #關閉selinux、防火牆
# tail /var/log/mariadb/mariadb.log
# rm -f /var/lib/mysql//galera.cache
# #關閉羣集後,重啓
# #在其中一臺
# sed -i 's#seqno: -1#seqno: 1#' /var/lib/mysql/grastate.dat
# galera_new_cluster #啓動第一個節點
# #其它節點
# systemctl start mariadbmysql
#test
#/usr/libexec/mysqld --wsrep-new-cluster --user=root &
#systemctl start mariadb.service
#設置開機啓動,設置爲第一個節點
# systemctl disable mariadb.service
# echo '#做爲第一個節點啓動SQL
# /usr/bin/galera_new_cluster
# sleep 5
# ssh controller2 "systemctl start mariadb.service"
# ssh controller3 "systemctl start mariadb.service"
# sleep 3
# systemctl restart mariadb.service
# '>>/etc/rc.locallinux
########################################## #如下爲openstack相關的配置 #每一個節點都設置 # haproxy高可用代理mariadb echo '#mariadb_cluster listen mariadb_cluster mode tcp bind controller:3306 balance leastconn option mysql-check user haproxy server controller1 controller1:3306 weight 1 check inter 2000 rise 2 fall 5 server controller2 controller2:3306 weight 1 check inter 2000 rise 2 fall 5 server controller3 controller3:3306 weight 1 check inter 2000 rise 2 fall 5 '>>/etc/haproxy/haproxy.cfg systemctl restart haproxy.service #測試 DBPass=open2017 mysql -h controller -u root -p$DBPass -e "show status like 'wsrep_cluster_size';" ############# #如下在controller其中一節點執行便可 #建立openstack相關數據庫、用戶受權 #mysql -u root -p mysql -u root -p$DBPass -e " create database keystone; grant all privileges on keystone.* to 'keystone'@'localhost' identified by 'keystone'; grant all privileges on keystone.* to 'keystone'@'%' identified by 'keystone'; create database glance; grant all privileges on glance.* to 'glance'@'localhost' identified by 'glance'; grant all privileges on glance.* to 'glance'@'%' identified by 'glance'; create database nova; grant all privileges on nova.* to 'nova'@'localhost' identified by 'nova'; grant all privileges on nova.* to 'nova'@'%' identified by 'nova'; create database nova_api; grant all privileges on nova_api.* to 'nova'@'localhost' identified by 'nova'; grant all privileges on nova_api.* to 'nova'@'%' identified by 'nova'; create database nova_cell0; grant all privileges on nova_cell0.* to 'nova'@'localhost' identified by 'nova'; grant all privileges on nova_cell0.* to 'nova'@'%' identified by 'nova'; create database neutron; grant all privileges on neutron.* to 'neutron'@'localhost' identified by 'neutron'; grant all privileges on neutron.* to 'neutron'@'%' identified by 'neutron'; flush privileges; select user,host from mysql.user; show databases; " mysql -u root -p$DBPass -e " show databases; "