系统
三台centos7.5
172.16.20.126 master1
172.16.20.127 master2
172.16.20.128 master3
需要虚拟机可以连通外网
三台都需要关闭防火墙和selinux
[root@master1 ~]# setenforce 0 #设置selinux
[root@master1 ~]# getenforce
Permissive
[root@master1 ~]# systemctl stop firewalld #关闭防火墙
[root@master1 ~]# systemctl disable firewalld #设置防火墙开机不启动
修改整加主机映射
[root@master1 ~]# cat /etc/hosts ##主机映射
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.20.123 master
172.16.20.126 master1172.16.20.127 master2
172.16.20.128 master3
配置mariadb的yum源并下载mariadb
[root@master1 ~]# rm -rf /etc/yum.repos.d/*[root@master1 ~]# cat /etc/yum.repos.d/centos.repo ##配置yum源
[mariadb] ##mariadb源
name=mariadb
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mariadb/yum/10.2/centos7-amd64/
gpgcheck=0[root@master1 ~]# yum install -y mariadb-server #安装mariadb
[root@master1 ~]# yum list | grep mariadb #检查是否安装mariadb
三台主机都需要修改配置文件
[root@master1 ~]# cat /etc/my.cnf.d/server.cnf
[galera]
# Mandatory settings
wsrep_on=ON
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address="gcomm://172.16.20.126,172.16.20.127,172.16.20.128"
binlog_format=row
只需在其中一台执行
[root@master1 ~]# /bin/galera_new_cluster
[root@master1 ~]# systemctl enable --now mariadb
然后分别在三台主机都进行mariadb的初始化超做
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDBSERVERS 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.Set root password? [Y/n] y New password: Re-enter new password: Password updated successfully! Reloading privilege tables..... Success!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] ... 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] ... 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] - 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] ... Success!Cleaning up...All done! If you've completed all of the above steps, your MariaDB
installation should now be secure
进入数据库查看,还可以创建个数据库,在到其他主机上看看数据库有没有同步
[root@master1 ~] mysql -uroot -p'000000'
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 20
Server version: 10.2.37-MariaDB MariaDB ServerCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]> show status like 'wsrep%'-> ;
+-------------------------------+----------------------------------------------------------+
| Variable_name | Value |
+-------------------------------+----------------------------------------------------------+
| wsrep_applier_thread_count | 1 |
| wsrep_apply_oooe | 0.000000 |
| wsrep_apply_oool | 0.000000 |
| wsrep_apply_window | 1.000000 |
| wsrep_causal_reads | 0 |
| wsrep_cert_deps_distance | 1.000000 |
| wsrep_cert_index_size | 1 |
| wsrep_cert_interval | 0.000000 |
| wsrep_cluster_conf_id | 3 |
| wsrep_cluster_size | 3 |
| wsrep_cluster_state_uuid | b629cd00-8ca5-11eb-9867-c665ad79cfcf |
| wsrep_cluster_status | Primary |
| wsrep_cluster_weight | 3 |
| wsrep_commit_oooe | 0.000000 |
| wsrep_commit_oool | 0.000000 |
| wsrep_commit_window | 1.000000 |
| wsrep_connected | ON |
| wsrep_desync_count | 0 |
| wsrep_evs_delayed | |
| wsrep_evs_evict_list | |
| wsrep_evs_repl_latency | 0/0/0/0/0 |
| wsrep_evs_state | OPERATIONAL |
| wsrep_flow_control_active | false |
| wsrep_flow_control_paused | 0.000000 |
| wsrep_flow_control_paused_ns | 0 |
| wsrep_flow_control_recv | 0 |
| wsrep_flow_control_requested | false |
| wsrep_flow_control_sent | 0 |
| wsrep_gcomm_uuid | b6293146-8ca5-11eb-9e6b-83afd8a77833 |
| wsrep_gmcast_segment | 0 |
| wsrep_incoming_addresses | 172.16.20.127:3306,172.16.20.128:3306,172.16.20.126:3306 |
| wsrep_last_committed | 4 |
| wsrep_local_bf_aborts | 0 |
| wsrep_local_cached_downto | 1 |
| wsrep_local_cert_failures | 0 |
| wsrep_local_commits | 0 |
| wsrep_local_index | 2 |
| wsrep_local_recv_queue | 0 |
| wsrep_local_recv_queue_avg | 0.142857 |
| wsrep_local_recv_queue_max | 2 |
| wsrep_local_recv_queue_min | 0 |
| wsrep_local_replays | 0 |
| wsrep_local_send_queue | 0 |
| wsrep_local_send_queue_avg | 0.000000 |
| wsrep_local_send_queue_max | 1 |
| wsrep_local_send_queue_min | 0 |
| wsrep_local_state | 4 |
| wsrep_local_state_comment | Synced |
| wsrep_local_state_uuid | b629cd00-8ca5-11eb-9867-c665ad79cfcf |
| wsrep_open_connections | 0 |
| wsrep_open_transactions | 0 |
| wsrep_protocol_version | 9 |
| wsrep_provider_name | Galera |
| wsrep_provider_vendor | Codership Oy <info@codership.com> |
| wsrep_provider_version | 3.32(rf74c6d3) |
| wsrep_ready | ON |
| wsrep_received | 7 |
| wsrep_received_bytes | 697 |
| wsrep_repl_data_bytes | 1436 |
| wsrep_repl_keys | 4 |
| wsrep_repl_keys_bytes | 128 |
| wsrep_repl_other_bytes | 0 |
| wsrep_replicated | 4 |
| wsrep_replicated_bytes | 1832 |
| wsrep_rollbacker_thread_count | 1 |
| wsrep_thread_count | 2 |
+-------------------------------+----------------------------------------------------------+
66 rows in set (0.00 sec)MariaDB [(none)]>
接下来就直接在其中一台服务器创建数据库,看看其他几台有没有同步