准备三台虚拟机 修改主机名(node1,node2,node3)
hostnamectl set-hostname 主机名(三台虚拟机主机名随意定义方便自己记忆就行) bash 刷新主机名
配置IP(node1,node2,node3)
[root@node1 ~]
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=ef0c10cd-1d70-48bb-91dd-0da3ee0fc904
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.200.11
NETMASK=255.255.255.0
GATEWAY=192.168.200.2
[root@node2 ~]
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=41c20eb2-d923-42e7-a195-10929bdc0c35
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.200.12
NETMASK=255.255.255.0
GATEWAY=192.168.200.2
[root@node3 ~]
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=6d0c98fe-36c3-4523-8fde-1bbd41b03a9a
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.200.13
NETMASK=255.255.255.0
GATEWAY=192.168.200.2
没配置DNS(无法使用外网) 会显示如下:
[root@node1 ~]
ping: baidu.com: Name or service not known
配置DNS(搜索就近的运营商) 国内dns(114.114.114.114)和国际(8.8.8.8)
[root@controller ~]
nameserver 114.114.114.114
关闭防火墙 (3个节点都要做)
[root@node1 ~]
Removed symlink /etc/systemd/system/mu lti-user.target.wants/firewalld.servic e.
Removed symlink /etc/systemd/system/db us-org.fedoraproject.FirewallD1.servic e.
[root@node1 ~]
[root@node1 ~]
Permissive
[root@node1 ~]
[root@node1 ~]
SELINUX=disabled
SELINUXTYPE=targeted
重启再次查看
[root@node1 ~]
[root@node1 ~]
Disabled
[root@node1 ~]
setenforce: SELinux is disabled
映射
[root@node1 ~]
[root@node1 ~]
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.200.11 node1
192.168.200.12 node2
192.168.200.13 node3
解压mariadb-ha 到 /opt目录,在/opt下新建目录把系统自带的repo文件移动到新建目录里 新建一个local.repo (包在资源里) 内容如下:
[mariadb]
name=mariadb
baseurl=file:///opt/mariadb-ha
gpgcheck=0
enabled=1
安装并初始化数据库 (3个节点)
yum install MariaDB-server MariaDB-client galera -y
systemctl start mariadb
mysql_secure_installation // 输入这条命令 如下操作
Enter current password for root (enter for none): 默认按回车
Set root password? [Y/n] y 按 y 回车 设置数据库密码
New password: 输入数据库密码
Re-enter new password: 重复数据库密码
Remove anonymous users? [Y/n] y 按 y 回车
Disallow root login remotely? [Y/n] n 按 n 回车
Remove test database and access to it? [Y/n] y 按 y 回车
Reload privilege tables now? [Y/n] y 按 y 回车
初始化完毕!!!
修改数据库文件 (3个节点都要修改) 修改如下:
node1 节点
[root@node1 ~]
[galera]
wsrep_on=ON
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address="gcomm://192.168.200.11,192.168.200.12,192.168.200.13"
wsrep_node_name= node1
wsrep_node_address=192.168.200.11
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
wsrep_slave_threads=1
innodb_flush_log_at_trx_commit=0
innodb_buffer_pool_size=120M
wsrep_sst_method=rsync
wsrep_causal_reads=ON
bind-address=192.168.200.11
node2 节点
[root@node1 ~]
[galera]
wsrep_on=ON
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address="gcomm://192.168.200.11,192.168.200.12,192.168.200.13"
wsrep_node_name= node2
wsrep_node_address=192.168.200.12
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
wsrep_slave_threads=1
innodb_flush_log_at_trx_commit=0
innodb_buffer_pool_size=120M
wsrep_sst_method=rsync
wsrep_causal_reads=ON
bind-address=192.168.200.12
node3 节点
[root@node1 ~]
[galera]
wsrep_on=ON
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address="gcomm://192.168.200.11,192.168.200.12,192.168.200.13"
wsrep_node_name= node3
wsrep_node_address=192.168.200.13
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
wsrep_slave_threads=1
innodb_flush_log_at_trx_commit=0
innodb_buffer_pool_size=120M
wsrep_sst_method=rsync
wsrep_causal_reads=ON
bind-address=192.168.200.13
3个节点登录数据库,并赋予root远程权限
[root@node1 ~]mysql -uroot -p123456
MariaDB [(none)]> grant all privileges on *.* to root@'%' identified by '123456';
Query OK, 0 rows affected (0.007 sec)
MariaDB [(none)]> Ctrl-C -- exit!
Aborted
关闭3个节点的数据库服务 然后重启服务
node1 节点
[root@node1 ~]
node2 节点和 node3 节点命令相同
[root@node2 ~]
[root@node3 ~]
node1 节点查看端口
下载net-tools
[root@node1 ~]
[root@node1 ~]
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address
State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:*
LISTEN 935/sshd
tcp 0 0 0.0.0.0:4567 0.0.0.0:*
LISTEN 11910/mysqld
tcp 0 0 127.0.0.1:25 0.0.0.0:*
LISTEN 1207/master
tcp6 0 0 :::22 :::*
LISTEN 935/sshd
tcp6 0 0 ::1:25 :::*
LISTEN 1207/master
tcp6 0 0 192.168.200.11:3306 :::*
LISTEN 11910/mysqld
验证集群
登陆node1节点的数据库,并查看galera插件是否启动成功
[root@node1 ~]
MariaDB [(none)]> show status like "wsrep_ready";
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| wsrep_ready | ON |
+---------------+-------+
1 row in set (0.002 sec)
查看集群成员数量 和galera集群状态
MariaDB [(none)]> show status like "wsrep_cluster_size";
+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| wsrep_cluster_size | 3 |
+--------------------+-------+
1 row in set (0.001 sec)
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 | 0.000000 |
| wsrep_causal_reads | 3 |
| wsrep_cert_deps_distance | 0.000000 |
| wsrep_cert_index_size | 0 |
| wsrep_cert_interval | 0.000000 |
| wsrep_cluster_conf_id | 3 |
| wsrep_cluster_size | 3 |
| wsrep_cluster_state_uuid | 739d4487-6d29-11ea-a39a-8edc6217817a |
| wsrep_cluster_status | Primary |
| wsrep_cluster_weight | 3 |
| wsrep_commit_oooe | 0.000000 |
| wsrep_commit_oool | 0.000000 |
| wsrep_commit_window | 0.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_paused | 0.000000 |
| wsrep_flow_control_paused_ns | 0 |
| wsrep_flow_control_recv | 0 |
| wsrep_flow_control_sent | 0 |
| wsrep_gcomm_uuid | 739bdf65-6d29-11ea-8e97-ca068305cc0a |
| wsrep_incoming_addresses |
192.168.200.11:3306,192.168.200.12:3306,192.168.200.13:3306 |
| wsrep_last_committed | 0 |
| wsrep_local_bf_aborts | 0 |
| wsrep_local_cached_downto | 18446744073709551615 |
| wsrep_local_cert_failures | 0 |
| wsrep_local_commits | 0 |
| wsrep_local_index | 0 |
| wsrep_local_recv_queue | 0 |
| wsrep_local_recv_queue_avg | 0.100000 |
| 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 | 739d4487-6d29-11ea-a39a-8edc6217817a|
| 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 | 25.3.28(r3875) |
| wsrep_ready | ON |
| wsrep_received | 10 |
| wsrep_received_bytes | 758 |
| wsrep_repl_data_bytes | 0 |
| wsrep_repl_keys | 0 |
| wsrep_repl_keys_bytes | 0 |
| wsrep_repl_other_bytes | 0 |
| wsrep_replicated | 0 |
| wsrep_replicated_bytes | 0 |
| wsrep_rollbacker_thread_count | 1 |
| wsrep_thread_count | 2 | +-------------------------------+-------------------------------------------------------------+
63 rows in set (0.001 sec)
MariaDB [(none)]> show status like "wsrep_incoming_addresses"; // 查看连接的主机
+--------------------------+-------------------------------------------------------------+
| Variable_name | Value | +--------------------------+-------------------------------------------------------------+
| wsrep_incoming_addresses |
192.168.200.11:3306,192.168.200.12:3306,192.168.200.13:3306 |
+--------------------------+-------------------------------------------------------------+
1 row in set (0.000 sec)
验证同步功能 在node1 节点创建测试数据库
MariaDB [(none)]> create database testnode1;
Query OK, 1 row affected (0.005 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| testnode1 |
+--------------------+
4 rows in set (0.001 sec)
node2 节点和node3 节点查看 显示如下:
[root@node2 ~]
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| testnode1 | +--------------------+
4 rows in set (0.001 sec)
node2 节点创建测试库 验证galera数据库集群的多主性
[root@node2 ~]
MariaDB [(none)]> create database testnode2;
Query OK, 1 row affected (0.004 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| testnode1 |
| testnode2 | +--------------------+
5 rows in set (0.000 sec)
验证node1 节点和node3 节点是否同步 两个节点显示如下:
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| testnode1 |
| testnode2 |
+--------------------+
5 rows in set (0.000 sec)
总结
特别补充:
安装 ansible 显示没包 解决方式如下
需要安装两个插件
yum -y install epel-release
yum -y install vconfig -y
如果对你有帮助,还望赏个关注鸭!!! ヾ(????)ノ" ,我们下期再见吧!!!😜
|