B02-openstack高可用-Mariadb集群

Mariadb集群

1:安装mariadb相关软件包:

# 在全部controller节点安装mariadb,以controller01节点为例
[root@controller01 ~]# yum install mariadb mariadb-server python2-PyMySQL -y

 

# 安装galera相关插件,利用galera搭建集群

[root@controller01 ~]# yum install mariadb-server-galera mariadb-galera-common galera xinetd rsync -y

 

2:初始化mariadb的root密码

[root@controller01 ~]# systemctl start mariadb
[root@controller01 ~]# systemctl enable mariadb

[root@controller01 ~]# mysql_secure_installation

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.

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] 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!

3:编辑galera集群配置文件:

在全部控制节点/etc/my.cnf.d/目录下新增openstack.cnf配置文件,主要设置集群同步相关参数,以controller01节点为例,个别涉及ip地址/host名等参数根据实际情况修改

[root@controller01 my.cnf.d]# cat openstack.cnf
[server]

[mysqld]
bind-address = 10.100.214.201
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

[galera]
wsrep_on=ON
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_name="mariadb_galera_cluster"

wsrep_cluster_address="gcomm://10.100.214.201,10.100.214.202,10.100.214.203"
wsrep_node_name="controller01"
wsrep_node_address="10.100.214.201"

binlog_format=ROW
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
wsrep_slave_threads=1
innodb_flush_log_at_trx_commit=2
innodb_buffer_pool_size=1024M
wsrep_sst_method=rsync

[embedded]

[mariadb]

[mariadb-10.3]

将controller01的配置文件分别copy到其他两个主机
在第二个节点修改配置,修改对应第二节地址:wsrep_node_name、wsrep_node_address,bind-address
在第三个节点修改配置,修改对应第三节地址:wsrep_node_name、wsrep_node_address,bind-address

 

等以上的安装配置操作在所有控制节点执行完毕以后,就可以开始构建集群,该操作可以在任一控制节点执行。

 

4.构建集群

停止全部控制节点的mariadb服务,以controller01节点为例

[root@controller01 ~]# systemctl stop mariadb

 

# 任选1个控制节点以如下方式启动mariadb服务,这里选择controller01节点

[root@controller01 ~]# /usr/libexec/mysqld --wsrep-new-cluster --user=root &
[1] 9672
[root@controller01 ~]# 2020-06-10 13:35:04 0 [Note] /usr/libexec/mysqld (mysqld 10.3.20-MariaDB) starting as process 9672 ...

在另外两台的controller节点上进行启动mariadb

 

 

 

等待其他的mariadb启动之后,返回controller01执行下列操作

[root@controller01 ~]# pkill -9 mysql
[root@controller01 ~]# rm -rf /var/lib/mysql/*
[1]+  Killed                  /usr/libexec/mysqld --wsrep-new-cluster --user=root
[root@controller01 ~]# chown mysql:mysql /var/run/mariadb/mariadb.pid
[root@controller01 ~]# systemctl start mariadb.service
[root@controller01 ~]# systemctl status mariadb.service

5:检测:

[root@controller01 ~]# mysql -uroot -phuayun -e 'show status like "wsrep_cluster_size";'
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| wsrep_cluster_size | 3     |
+--------------------+-------+

[root@controller01 ~]# mysql -uroot -phuayun -e '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            | 0                                                           |
| wsrep_cert_deps_distance      | 0.000000                                                    |
| wsrep_cert_index_size         | 0                                                           |
| wsrep_cert_interval           | 0.000000                                                    |
| wsrep_cluster_conf_id         | 5                                                           |
| wsrep_cluster_size            | 3                                                           |
| wsrep_cluster_state_uuid      | 233db5fa-aadc-11ea-9474-d24a31f6b238                        |
| wsrep_cluster_status          | Primary                                                     |
| 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              | d6ea8f40-aadc-11ea-800d-23e3ac752175                        |
| wsrep_incoming_addresses      | 10.100.214.202:3306,10.100.214.203:3306,10.100.214.201: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             | 2                                                           |
| wsrep_local_recv_queue        | 0                                                           |
| wsrep_local_recv_queue_avg    | 0.000000                                                    |
| wsrep_local_recv_queue_max    | 1                                                           |
| 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        | 233db5fa-aadc-11ea-9474-d24a31f6b238                        |
| wsrep_protocol_version        | 8                                                           |
| wsrep_provider_name           | Galera                                                      |
| wsrep_provider_vendor         | Codership Oy <info@codership.com>                           |
| wsrep_provider_version        | 3.23(rXXXX)                                                 |
| wsrep_ready                   | ON                                                          |
| wsrep_received                | 3                                                           |
| wsrep_received_bytes          | 314                                                         |
| 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                                                           |
+-------------------------------+-------------------------------------------------------------+

在controller01创建数据库,到另外两台节点上查看是否可以同步

 

5. 设置心跳检测clustercheck
下面的操作在所有控制节点支持。
[root@countroller01 sysconfig]# vim clustercheck
[root@countroller01 sysconfig]# pwd
/etc/sysconfig
 
MYSQL_USERNAME="clustercheck"
MYSQL_PASSWORD="huayun"
MYSQL_HOST="localhost"
MYSQL_PORT="3306"
 
/etc/xinetd.d/galera-monitor
# default:on
# description: galera-monitor
service galera-monitor
{
port = 9200
disable = no
socket_type = stream
protocol = tcp
wait = no
user = root
group = root
groups = yes
server = /usr/bin/clustercheck
type = UNLISTED
per_source = UNLIMITED
log_on_success =
log_on_failure = HOST
flags = REUSE
}
~
/etc/services
修改 /etc/services,找到:
wap-wsp 9200/tcp # WAP connectionless session service
wap-wsp 9200/udp # WAP connectionless session service
注释掉,在前面加上 Galera 端口信息:
galera-monitor 9200/tcp
# Galera Clustercheck #wap-wsp 9200/tcp # WAP connectionless session service
#wap-wsp 9200/udp # WAP connectionless session service
 
创建集群检查用户
本操作需要选择一个控制节点执行。
MariaDB [mysql]> GRANT PROCESS ON *.* TO 'clustercheck'@'localhost' IDENTIFIED BY 'huayun';
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
 
启动 xinetd 服务
systemctl start xinetd systemctl enable xinetd
检查
检查一下状态是否正常,执行:
/usr/bin/clustercheck
 
[root@countroller01 xinetd.d]# /usr/bin/clustercheck
HTTP/1.1 200 OK
Content-Type: text/plain
Connection: close
Content-Length: 32
 
Galera cluster node is synced.

 

posted @ 2020-06-10 15:22  Mr-呵呵哒  阅读(871)  评论(0编辑  收藏  举报