Recently, the original data of Hive needs to use mysql, so Galera Cluster is installed again. Although it has been installed many times, there are still some ambiguities. So roughly record it and share it.
Galera Cluster must be installed on at least 3 servers, as an all-master no-delay cluster, the odd number of servers is to prevent split brain.
The first documents to be prepared are as follows
Before installation, we have to install some prepared libraries:
yum install libaio gcc gcc-c++ boost-devel scons check-devel openssl-devel openssh-clients
perl-DBD-MySQL perl-Time-HiRes perl-Digest nc rsync lsof galera autoconf That's all, I don't rule out omissions, so installing galera cluster is very troublesome.
Remove the mysql library that comes with CentOS 7 before installation. This blog has been written before
yum remove mariadb-libs-5.5.56-2.el7.x86_64
Then start the installation
rpm -ivh add file name
Such as rpm -ivh mysql-wsrep-libs-compat-5.6-5.6.36-25.20.el6.x86_64.rpm
All in the picture should be installed, the installation order except mysql-wsrep-server-5.6-5.6.36-25.20.el6.x86_64.rpm and mysql-wsrep-5.6-5.6.36-25.20.el6.x86_64.rpm and the last installation Besides, the others can be in any order.
If there is an error during the installation process, it means that the library is not installed, you can use --force to force the installation.
After the installation is complete, perform the following operations
It is recommended to put dbdata/mysql_3306 in your relatively large external disk, not the system disk. In other words, the /opt directory is optional. You can use df -h to view.
Write my.cnf as follows
[ client]
port = 3306
socket = /mnt/dbdata/mysql_3306/mysql.sock
[ mysqld_multi]
mysqld = /usr/bin/mysqld_safe
mysqladmin = /usr/bin/mysqladmin
log = /var/log/mysqld_multi.err
[ mysqldump]
quick
max_allowed_packet = 16M
[ mysql]
no-auto-rehash
[ myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[ mysqlhotcopy]
interactive-timeout
[ mysqld]
port = 3306
socket = /mnt/dbdata/mysql_3306/mysql.sock
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
log-bin-trust-function-creators = 1
expire_logs_days = 1
max_connections = 600
skip-external-locking
skip-name-resolve
datadir=/mnt/dbdata/mysql_3306
character_set_server = utf8
log-bin = mysql-bin
max_allowed_packet=64M
server-id= 44
binlog_format=ROW
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
##############################################
wsrep_cluster_address=gcomm://IP1,IP2,IP3
##############################################
wsrep_cluster_name='galera_cluster'
wsrep_node_address='IP1'
wsrep_node_name='node1'
wsrep_sst_method=xtrabackup
wsrep_sst_auth=root: password
###############################################################################
Where the three servers are different
server-id should be set to a different number, generally set to the last number of the IP address
Set wsrep_node_address to different IP
Set wsrep_node_name to a different node name
The wsrep_sst_method must be set to rsync when connecting to the cluster for the first time. If you use xtrabackup, the first time you connect to the cluster, you will not be able to connect. After the first three servers are successfully connected, close all mysql services and change them all. Go back to xtrabackup, then you can connect successfully.
Remember to put it in the /etc directory after editing
Before starting the first server, comment out wsrep_cluster_address=gcomm://IP1,IP2,IP3, and uncomment wsrep_cluster_address=gcomm://.
Start the first server service mysql start
Use mysql to enter directly, no username or password is required.
GRANT ALL ON . TO'root'@'%' IDENTIFIED BY'password';'%' means that IP access is not restricted. If you want to restrict IP access, you can set the IP address segment, such as GRANT ALL ON * .* TO'root'@'192.168.%' IDENTIFIED BY'Password';
use mysql
update user set password=PASSWORD('password') where user='root';
flush privileges;
exit
Service mysql stop
Re-edit my.cnf vim /etc/my.cnf
Comment out wsrep_cluster_address=gcomm://, uncomment wsrep_cluster_address=gcomm://IP1,IP2,IP3
Start service mysql start --wsrep_cluster_address=gcomm:// again
Then start the second and third servers in succession service mysql start
At this time, all three servers can start normally and connect successfully.
Enter any mysql to view, mysql -uroot -hIP1 -p
After entering the password, enter
show status like 'wsrep%';
It means that the three servers are successfully connected. At this time, the SQL writing, modification, table creation, and database creation operations you do on any one will respond to the three servers at the same time, and the data will be fully synchronized.
Shut down all servers service mysql stop
vim /etc/my.cnf
wsrep_sst_method changes rsync to xtrabackup
Then start the servers in sequence according to the above method, and all installation of galera cluster is completed.
Recommended Posts