November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Categories

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Yum to configure multiple master cluster MariaDB Galera

Yum to configure multiple master cluster MariaDB Galera
Hereinafter, if the command is not preceded by PS1 is to represent the three nodes are required to perform the same action, if it means the implementation of the action on the specified node

cluster1.rmohan.com       Centos6.7   192.168.1.60    MariaDB
cluster2.rmohan.com       Centos6.7   192.168.1.62    MariaDB
cluster3.rmohan.com       Centos6.7   192.168.1.63    MariaDB

Hereinafter, if the command is not preceded by PS1 is to represent the three nodes are required to perform the same action, if it means the implementation of the action on the specified node
1, install ntpdate to set timing on node cluster1 cluster2 cluster3 each other synchronization and ssh
yum install -y ntpdate  openssh-askpass openssh-client* wget
echo “*/5 * * * * /usr/sbin/ntpdate pool.ntp.org >/dev/null 2>&1” >> /var/spool/cron/root
/usr/sbin/ntpdate pool.ntp.org
cat >> /etc/hosts << EOF
192.168.1.60  cluster1.rmohan.com  cluster1
192.168.1.62  cluster2.rmohan.com  cluster2
192.168.1.63  cluster3.rmohan.com  cluster3
EOF
Here is the production of a key ###
ssh-keygen  -t rsa -f ~/.ssh/id_rsa  -P ”
### The following are performed on each node, so that the public key of the machine onto the other nodes
awk ‘{if ($0!~/'”$(hostname)”‘|localhost/)print $NF}’ /etc/hosts |xargs -i ssh-copy-id -i ~/.ssh/id_rsa.pub root@{}
2, installed base build environment
Add EPEL Repository which is provided from Fedora project.
yum -y install epel-release
# set [priority=5]
sed -i -e “s/\]$/\]\npriority=5/g” /etc/yum.repos.d/epel.repo
# for another way, change to [enabled=0] and use it only when needed
sed -i -e “s/enabled=1/enabled=0/g” /etc/yum.repos.d/epel.repo
# if [enabled=0], input a command to use the repository
yum –enablerepo=epel install [Package]
Add RPMforge Repository which provides many useful packages.
yum -y install http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
# set [priority=10]
sed -i -e “s/\]$/\]\npriority=10/g” /etc/yum.repos.d/rpmforge.repo
# for another way, change to [enabled=0] and use it only when needed
sed -i -e “s/enabled = 1/enabled = 0/g” /etc/yum.repos.d/rpmforge.repo
# if [enabled=0], input a command to use the repository
yum –enablerepo=rpmforge install [Package]
rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-6.noarch.rpm
rpm –import http://mirrors.dwhd.org/epel/RPM-GPG-KEY-EPEL-6
rpm -ivh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
rpm –import http://mirrors.dwhd.org/repoforge/RPM-GPG-KEY.dag.txt
yum clean all && yum makecache
yum groupinstall “Development tools” “Server Platform Development” -y
yum install libxml2-devel lz4 lz4-devel libpcap nmap lsof socat -y
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/5.5.46/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

[root@cluster1 ~]# cat /etc/yum.repos.d/mariadb.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.0/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
[root@cluster1 ~]# scp /etc/yum.repos.d/mariadb.repo root@cluster2:/etc/yum.repos.d/
mariadb.repo                                                                                                                                                              100%  138     0.1KB/s   00:00
[root@cluster1 ~]# scp /etc/yum.repos.d/mariadb.repo root@cluster3:/etc/yum.repos.d/
mariadb.repo                                                                                                                                                              100%  138     0.1KB/s   00:00

[root@cluster1 ~]# yum install MariaDB-Galera-server MariaDB-client galera -y
[root@cluster2 ~]# yum install MariaDB-Galera-server MariaDB-client galera -y
[root@cluster3 ~]# yum install MariaDB-Galera-server MariaDB-client galera -y

[root@cluster1 ~]# service mysql restart
ERROR! MySQL server PID file could not be found!
Starting MySQL….. SUCCESS!

/usr/bin/mysqladmin -u root password ‘test123’
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we’ll need the current
password for the root user.  If you’ve just installed MariaDB, and
you haven’t set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on…
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
You already have a root password set, so you can safely answer ‘n’.
Change the root password? [Y/n] n
… skipping.
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] Y
… Success!
Normally, root should only be allowed to connect from ‘localhost’.  This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] Y
… Success!
By default, MariaDB comes with a database named ‘test’ that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] Y
– Dropping test database…
… Success!
– Removing privileges on test database…
… Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] Y
… Success!
Cleaning up…
All done!  If you’ve completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
[root@cluster2 ~]# service mysql restart
ERROR! MySQL server PID file could not be found!
Starting MySQL….. SUCCESS!
/usr/bin/mysqladmin -u root password ‘test123’
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we’ll need the current
password for the root user.  If you’ve just installed MariaDB, and
you haven’t set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on…
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
You already have a root password set, so you can safely answer ‘n’.
Change the root password? [Y/n] n
… skipping.
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] Y
… Success!
Normally, root should only be allowed to connect from ‘localhost’.  This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] Y
… Success!
By default, MariaDB comes with a database named ‘test’ that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] Y
– Dropping test database…
… Success!
– Removing privileges on test database…
… Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] Y
… Success!
Cleaning up…
All done!  If you’ve completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
[root@cluster3 ~]# service mysql restart
ERROR! MySQL server PID file could not be found!
Starting MySQL….. SUCCESS!
/usr/bin/mysqladmin -u root password ‘test123’
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we’ll need the current
password for the root user.  If you’ve just installed MariaDB, and
you haven’t set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on…
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
You already have a root password set, so you can safely answer ‘n’.
Change the root password? [Y/n] n
… skipping.
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] Y
… Success!
Normally, root should only be allowed to connect from ‘localhost’.  This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] Y
… Success!
By default, MariaDB comes with a database named ‘test’ that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] Y
– Dropping test database…
… Success!
– Removing privileges on test database…
… Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] Y
… Success!
Cleaning up…
All done!  If you’ve completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
CLUSTER1
mysql -u root -ptest123 <<< “USE mysql;
GRANT ALL PRIVILEGES ON *.* TO ‘cluster’@’%’ IDENTIFIED BY ‘test123’ WITH GRANT OPTION;
FLUSH PRIVILEGES;”
mysql -u root -ptest123 <<< “USE mysql;
SELECT USER,PASSWORD,HOST FROM user;”
CLUSTER2
mysql -u root -ptest123 <<< “USE mysql;
GRANT ALL PRIVILEGES ON *.* TO ‘cluster’@’%’ IDENTIFIED BY ‘test123’ WITH GRANT OPTION;
FLUSH PRIVILEGES;”
mysql -u root -ptest123 <<< “USE mysql;
SELECT USER,PASSWORD,HOST FROM user;”
CLUSTER3
mysql -u root -ptest123 <<< “USE mysql;
GRANT ALL PRIVILEGES ON *.* TO ‘cluster’@’%’ IDENTIFIED BY ‘test123’ WITH GRANT OPTION;
FLUSH PRIVILEGES;”
mysql -u root -ptest123 <<< “USE mysql;
SELECT USER,PASSWORD,HOST FROM user;”
 modify the configuration of three nodes
####cluster1####
[root@cluster1 ~]# sed -ne ‘/\[mariadb-10.0\]/,//p’ /etc/my.cnf.d/server.cnf
[mariadb-10.0]
query_cache_size=0
binlog_format=ROW
default_storage_engine=innodb
innodb_autoinc_lock_mode=2
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address=gcomm://192.168.1.62,192.168.1.63
wsrep_cluster_name=’cluster1′
wsrep_node_address=’192.168.1.60′
wsrep_node_name=’cluster1′
wsrep_sst_method=rsync
wsrep_sst_auth=root:password
[root@cluster1 my.cnf.d]# ls
mysql-clients.cnf  server.cnf  tokudb.cnf
[root@cluster1 my.cnf.d]# cat^C
[root@cluster1 my.cnf.d]# /etc/init.d/mysql bootstrap
Bootstrapping the cluster.. Starting MySQL…. SUCCESS!
####cluster2####
[root@cluster2 ~]# sed -ne ‘/\[mariadb-10.0\]/,//p’ /etc/my.cnf.d/server.cnf
[mariadb-10.0]
query_cache_size=0
binlog_format=ROW
default_storage_engine=innodb
innodb_autoinc_lock_mode=2
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address=gcomm://192.168.1.60,192.168.1.63
wsrep_cluster_name=’cluster1′
wsrep_node_address=’192.168.1.62′
wsrep_node_name=’cluster2′
wsrep_sst_method=rsync
wsrep_sst_auth=root:password
####cluster3####
[root@cluster3  ~]# sed -ne ‘/\[mariadb-10.0\]/,//p’ /etc/my.cnf.d/server.cnf
[mariadb-10.0]
query_cache_size=0
binlog_format=ROW
default_storage_engine=innodb
innodb_autoinc_lock_mode=2
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address=gcomm://192.168.1.60,192.168.1.62
wsrep_cluster_name=’cluster1′
wsrep_node_address=’192.168.1.63′
wsrep_node_name=’cluster3′
wsrep_sst_method=rsync
wsrep_sst_auth=root:password
[root@cluster1 my.cnf.d]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.46-MariaDB-wsrep MariaDB Server, wsrep_25.12.r4f81026
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
MariaDB [(none)]> create database mohan;
Query OK, 1 row affected (0.02 sec)
MariaDB [(none)]> show databases;
+——————–+
| Database           |
+——————–+
| information_schema |
| mohan              |
| mysql              |
| performance_schema |
| test               |
+——————–+
5 rows in set (0.00 sec)
MariaDB [(none)]> drop databases test;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘databases test’ at line 1
MariaDB [(none)]> drop database test;
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]>
root@cluster2 my.cnf.d]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.46-MariaDB-wsrep MariaDB Server, wsrep_25.12.r4f81026
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
MariaDB [(none)]> show databases;
+——————–+
| Database           |
+——————–+
| information_schema |
| mohan              |
| mysql              |
| performance_schema |
| test               |
+——————–+
5 rows in set (0.00 sec)
MariaDB [(none)]> show databases;
+——————–+
| Database           |
+——————–+
| information_schema |
| mohan              |
| mysql              |
| performance_schema |
+——————–+
4 rows in set (0.00 sec)
MariaDB [(none)]> quit
Bye
[root@cluster3 my.cnf.d]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.46-MariaDB-wsrep MariaDB Server, wsrep_25.12.r4f81026
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
MariaDB [(none)]> show databases;
+——————–+
| Database           |
+——————–+
| information_schema |
| mohan              |
| mysql              |
| performance_schema |
| test               |
+——————–+
5 rows in set (0.00 sec)
MariaDB [(none)]> show databases;
+——————–+
| Database           |
+——————–+
| information_schema |
| mohan              |
| mysql              |
| performance_schema |
+——————–+
4 rows in set (0.00 sec)
MariaDB [(none)]> quit
Bye

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>