IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 系统运维 -> 【1+X高级篇】— 数据库集群搭建(1.6) -> 正文阅读

[系统运维]【1+X高级篇】— 数据库集群搭建(1.6)

准备三台虚拟机
在这里插入图片描述
修改主机名(node1,node2,node3)

hostnamectl set-hostname 主机名(三台虚拟机主机名随意定义方便自己记忆就行)
bash 刷新主机名

配置IP(node1,node2,node3)

# Node1节点
[root@node1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33
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 

# Node2 节点
[root@node2 ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33
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

# Node3
[root@node3 ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33
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
ping: baidu.com: Name or service not known

配置DNS(搜索就近的运营商)
在这里插入图片描述
国内dns(114.114.114.114)和国际(8.8.8.8)

[root@controller ~]# cat /etc/resolv.conf
nameserver 114.114.114.114      

关闭防火墙 (3个节点都要做)

[root@node1 ~]# systemctl disable fire   walld
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 ~]#  setenforce 0
[root@node1 ~]#  getenforce
Permissive
[root@node1 ~]# vi /etc/selinux/config   
[root@node1 ~]# cat /etc/selinux/confi   g

# This file controls the state of SELi   nux on the system.
# SELINUX= can take one of these three    values:
#     enforcing - SELinux security pol   icy is enforced.
#     permissive - SELinux prints warn   ings instead of enforcing.
#     disabled - No SELinux policy is    loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three t   wo values:
#     targeted - Targeted processes ar   e protected,
#     minimum - Modification of target   ed policy. Only selected processes are    protected.
#     mls - Multi Level Security prote   ction.
SELINUXTYPE=targeted

重启再次查看

[root@node1 ~]#reboot
[root@node1 ~]# getenforce
Disabled
[root@node1 ~]# setenforce 0
setenforce: SELinux is disabled

映射

[root@node1 ~]# vi /etc/hosts
[root@node1 ~]# cat /etc/hosts
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 ~]# vi /etc/my.cnf.d/server.cnf
[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
# Mandatory settings
#wsrep_on=ON
#wsrep_provider=
#wsrep_cluster_address=
#binlog_format=row
#default_storage_engine=InnoDB
#innodb_autoinc_lock_mode=2
#
# Allow server to accept connections on all interfaces.
#
bind-address=192.168.200.11
#
# Optional setting
#wsrep_slave_threads=1
#innodb_flush_log_at_trx_commit=0

# this is only for embedded server

node2 节点

[root@node1 ~]# vi /etc/my.cnf.d/server.cnf
[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
# Mandatory settings
#wsrep_on=ON
#wsrep_provider=
#wsrep_cluster_address=
#binlog_format=row
#default_storage_engine=InnoDB
#innodb_autoinc_lock_mode=2
#
# Allow server to accept connections on all interfaces.
#
bind-address=192.168.200.12
#
# Optional setting
#wsrep_slave_threads=1
#innodb_flush_log_at_trx_commit=0

# this is only for embedded serve

node3 节点

[root@node1 ~]# vi /etc/my.cnf.d/server.cnf
[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
# Mandatory settings
#wsrep_on=ON
#wsrep_provider=
#wsrep_cluster_address=
#binlog_format=row
#default_storage_engine=InnoDB
#innodb_autoinc_lock_mode=2
#
# Allow server to accept connections on all interfaces.
#
bind-address=192.168.200.13
#
# Optional setting
#wsrep_slave_threads=1
#innodb_flush_log_at_trx_commit=0

# this is only for embedded serve

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 ~]# galera_new_cluster

node2 节点和 node3 节点命令相同

[root@node2 ~]# systemctl start mariadb
[root@node3 ~]# systemctl start mariadb

node1 节点查看端口

下载net-tools

[root@node1 ~]# yum install -y net-tools
[root@node1 ~]# netstat -ntpl
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 ~]# mysql -uroot -p000000
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 ~]# mysql -uroot -p123456
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| testnode1 | +--------------------+
4 rows in set (0.001 sec)

node2 节点创建测试库 验证galera数据库集群的多主性

[root@node2 ~]# mysql -uroot -p123456
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

如果对你有帮助,还望赏个关注鸭!!!在这里插入图片描述
ヾ(????)ノ" ,我们下期再见吧!!!😜

  系统运维 最新文章
配置小型公司网络WLAN基本业务(AC通过三层
如何在交付运维过程中建立风险底线意识,提
快速传输大文件,怎么通过网络传大文件给对
从游戏服务端角度分析移动同步(状态同步)
MySQL使用MyCat实现分库分表
如何用DWDM射频光纤技术实现200公里外的站点
国内顺畅下载k8s.gcr.io的镜像
自动化测试appium
ctfshow ssrf
Linux操作系统学习之实用指令(Centos7/8均
上一篇文章      下一篇文章      查看所有文章
加:2022-10-08 21:17:28  更:2022-10-08 21:19:51 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/25 18:19:46-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码