wachid web id
share something that don't now before, don't know, search and share it
share something that don't now before, don't know, search and share it
Home Archives for 2017
Cluster node 1 has hostname db1 and IP address 192.168.1.1 Cluster node 2 has hostname db2 and IP address 192.168.1.2 Cluster node 3 has hostname db3 and IP address 192.168.1.3
[mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.0/centos6-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1
[mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.0/centos6-x86 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1
sudo setenforce0
sudo yum install http://dl.fedoraproject.org/pub/epel/6/x86_64/socat-1.7.2.3-1.el6.x86_64.rpm
sudo yum install socat
sudo yum install MariaDB-Galera-server MariaDB-client rsync galera
sudo service mysql start
sudo /usr/bin/mysql_secure_installation
mysql -u root -p
mysql> DELETE FROM mysql.user WHERE user=''; mysql> GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY 'dbpass'; mysql> GRANT USAGE ON *.* to sst_user@'%' IDENTIFIED BY 'dbpass'; mysql> GRANT ALL PRIVILEGES on *.* to sst_user@'%'; mysql> FLUSH PRIVILEGES; mysql> quit
sudo service mysql stop
sudo cat >> /etc/my.cnf.d/server.cnf << EOF
binlog_format=ROW default-storage-engine=innodb innodb_autoinc_lock_mode=2 innodb_locks_unsafe_for_binlog=1 query_cache_size=0 query_cache_type=0 bind-address=0.0.0.0 datadir=/var/lib/mysql innodb_log_file_size=100M innodb_file_per_table innodb_flush_log_at_trx_commit=2 wsrep_provider=/usr/lib64/galera/libgalera_smm.so wsrep_cluster_address="gcomm://1.1.1.1,1.1.1.2,1.1.1.3" wsrep_cluster_name='galera_cluster' wsrep_node_address='1.1.1.1' wsrep_node_name='db1' wsrep_sst_method=rsync wsrep_sst_auth=sst_user:dbpass EOF
wsrep_node_address=1.1.1.2 wsrep_node_name='db2'
wsrep_node_address='1.1.1.3' wsrep_node_name='db3'
sudo /etc/init.d/mysql start --wsrep-new-cluster
mysql-uroot-p-e"show status like 'wsrep%'"
wsrep_local_state_comment | Synced <-- cluster is synced wsrep_incoming_addresses | 1.1.1.1:3306 <-- node db1 is a provider wsrep_cluster_size | 1 <-- cluster consists of 1 node wsrep_ready | ON <-- good :)
sudo service mysql start
mysql -u root -p -e "show status like 'wsrep%'"
| wsrep_local_state_comment | Synced | | wsrep_incoming_addre sses | 1.1.1.1:3306,1.1.1.2:3306 | | wsrep_cluster_size | 2 | | wsrep_connected | ON | | wsrep_ready | ON |
sudo service mysql start
mysql -u root -p -e "show status like 'wsrep%'"
| wsrep_local_state_comment | Synced | | wsrep_incoming_addresses | 1.1.1.3:3306,1.1.1.1:3306,1.1.1.2:3306 | | wsrep_cluster_size | 3 | | wsrep_connected | ON | | wsrep_ready | ON |
mysql -u root -p -e 'CREATE DATABASE clustertest;'
mysql -u root -p -e 'CREATE TABLE clustertest.mycluster ( id INT NOT NULL AUTO_INCREMENT, name VARCHAR(50), ipaddress VARCHAR(20), PRIMARY KEY(id));'
mysql -u root -p -e 'INSERT INTO clustertest.mycluster (name, ipaddress) VALUES ("db1", "1.1.1.1");'
mysql -u root -p -e 'SELECT * FROM clustertest.mycluster;'
Enter password: +----+------+-----------+ | id | name | ipaddress | +----+------+-----------+ | 2 | db1 | 1.1.1.1 | +----+------+-----------+
mysql -u root -p -e 'SELECT * FROM clustertest.mycluster;'
Enter password: +----+------+-----------+ | id | name | ipaddress | +----+------+-----------+ | 2 | db1 | 1.1.1.1 | +----+------+-----------+
mysql -u root -p -e 'SELECT * FROM clustertest.mycluster;'
Enter password: +----+------+-----------+ | id | name | ipaddress | +----+------+-----------+ | 2 | db1 | 1.1.1.1 | +----+------+-----------+
1
|
vi /etc/selinux/config
|
1
2
3
4
5
6
7
8
9
10
11
|
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
|
1
|
vi /etc/yum.repos.d/mariadb.repo
|
1
2
3
4
5
6
7
|
# http://mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.0/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
enabled=0
|
1
|
vi /etc/hosts
|
1
2
3
|
192.168.1.37 galera1
192.168.1.39 galera2
192.168.1.40 galera3
|
1
|
yum --enablerepo=mariadb -y install MariaDB-Galera-server
|
# These groups are read by MariaDB server. Use it for options that only the serv er (but not clients) should see
#
# See the examples of server my.cnf files in /usr/share/mysql/
#
# this is read by the standalone daemon and embedded servers
[server]
# this is only for the mysqld standalone daemon
[mysqld]
#
# * Galera-related settings
#
[galera]
# Mandatory settings
wsrep_on=ON
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address="gcomm://192.168.1.37,192.168.1.39,192.168.1.40" 168.72.91,192.168.72.92,192.168.72.93"
wsrep_node_address=192.168.1.39
wsrep_node_name=galera-1
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
innodb_buffer_pool_size=5000M
# Custom settings
wsrep_cluster_name="galeracluster"
wsrep_sst_method=rsync
bind-address=0.0.0.0
# this is only for embedded server
[embedded]
# This group is only read by MariaDB servers, not by MySQL.
#If you use the same .cnf file for MySQL and MariaDB,
#you can put MariaDB-only options here
[mariadb]
# This group is only read by MariaDB-10.0 servers.
#If you use the same .cnf file for MariaDB of different versions,
#use this group for options that older servers don't understand
[mariadb-10.0]
/etc/init.d/mysql start --wsrep-new-cluster
Lalu coba jalankan perintah ini pada server galera1mysql -u root -p -e "show status like 'wsrep%'"
coba lihat pada baris “wsrep_incoming_addresses” ip nya baru 1| wsrep_incoming_addresses | 192.168.100.20:3306|
Selanjutnya jalankan perintah ini pada server galera2 & galera3/etc/init.d/mysql start
mysql -u root -p -e "show status like 'wsrep%'"
Dan coba lihat kali ini pada baris “wsrep_incoming_addresses” sudah ada 3 ip| wsrep_incoming_addresses | 192.168.100.20:3306,192.168.100.30:3306,192.168.100.10:3306 |
Oke tandanya kita sudah berhasil# systemctl start firewalld
Open the mariadb client and galera replication ports:# firewall-cmd --permanent --add-port=3306/tcp
# firewall-cmd --permanent --add-port=4567/tcp
Open rsync port that we use for replication# firewall-cmd --permanent --add-port=873/tcp
# firewall-cmd --permanent --add-port=4444/tcp
# firewall-cmd --permanent --add-port=9200/tcp
Lastly reload the firewall# firewall-cmd --reload