检查maryiadb的启动信息中,这里配置得是单nginx主

作者:美狮美高梅官方网站

利用 respository tool 获取需要的 mariadb 版本对应的仓库,并完成安装

服务器 IP
负载均衡VIP 10.10.129.100
负载均衡(一) 10.10.140.49
负载均衡(二) 10.10.142.212
DB(一) 10.10.133.13
DB(二) 10.10.141.182
DB(三) 10.10.132.91

mariadb集群与nginx负载均衡配置--centos7版本,nginx--centos7

这里配置得是单nginx主机。。先准备4台主机,三台mariadb集群,一台nginx。


mariadb集群配置

环境信息

MariaDB Server:MariaDB-10.2.10

CentOS:CentOS Linux release7.2.1511 (Core)

MariaDB Galera Cluster 三个集群节点主机名和IP地址信息:
192.168.1.51 db1
192.168.1.52 db2
192.168.1.53 db3

 

 

环境准备,最小化安装CentOS7.2后,安装net-tools-2.0-0.17.20131004git.el7.x86_64.rpm和lrzsz-0.12.20-36.el7.x86_64.rpm,方便远程管理和传输文件。

  1. 编辑配置hosts文件
    # vi /etc/hosts
    127.0.0.1 localhost.localdomain localhost
    192.168.1.51 db1
    192.168.1.52 db2
    美狮美高梅官方网站,192.168.1.53 db3
  1. # vi /etc/security/limits.conf
    * soft nofile 65536
    * hard nofile 65536
  1. # vi /etc/sysctl.conf
    新美高梅网站,fs.file-max=655350
    net.ipv4.ip_local_port_range = 1025 65000
    net.ipv4.tcp_tw_recycle = 1

最后执行:
# sysctl -p

  1. 关闭SELINUX和防火墙
    # vi /etc/selinux/config
    SELINUX=disabled

# systemctl stop firewalld.service
# systemctl disable firewalld.service
# setenforce 0

部署MariaDB

从MariaDB 10.1版本开始,Galera Cluster就已经包含在MariaDB包里面了,不需要单独部署MariaDB-Galera-server

1.修改计算机名,并将计算机名--IP对应关系添加每个服务器的hosts文件内容如下:
cat > /etc/hosts << EOF
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.10.133.13 MySQL_Cluster_DB_1
10.10.141.182 MySQL_Cluster_DB_2
10.10.132.91 MySQL_Cluster_DB_3
10.10.140.49 MySQL_Cluster_HA_1
10.10.142.212 MySQL_Cluster_HA_2
EOF

和galera 包。

galera-25.3.20-1.rhel7.el7.centos.x86_64.rpm MariaDB-10.2.10-centos7-x86_64-compat.rpm
MariaDB-10.2.10-centos7-x86_64-client.rpm MariaDB-10.2.10-centos7-x86_64-server.rpm
MariaDB-10.2.10-centos7-x86_64-common.rpm

sudo apt-get install software-properties-common sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943dbsudo add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://mirrors.neusoft.edu.cn/mariadb/repo/10.1/ubuntu trusty main'sudo apt-get updatesudo apt-get install mariadb-server
2.配置Yum源(添加Percona、epel和MariaDB)

1.添加Percona源:
rpm -ivh http://www.percona.com/redir/downloads/percona-release/redhat/percona-release-0.1-3.noarch.rpm
2.添加epel源:yum -y install epel-release
3.添加MariaDB源:
rpm --import https://yum.mariadb.org/RPM-GPG-KEY-MariaDB

cat > /etc/yum.repos.d/MariaDB.repo << EOF
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.0/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOF

准备好这五个包

步骤一:配置Yum源(192.168.1.51,192.168.1.52,192.168.1.53)
# touch /etc/yum.repos.d/MariaDB-IDC.repo
添加如下内容:
[mariadb]
name = MariaDB
baseurl =
gpgkey=
gpgcheck=1

上面的yum源可能太慢,可以考虑使用如下地址:
[mariadb]
name = MariaDB
baseurl=

创建单点 cluster

可以通过以下命令新创建一个 galera cluster 集群

mysqld --wsrep-new-cluster

通过 mysql 命令来查看当前集群的状态:

show status like 'wsrep_%';

显示集群的 wsrep_cluster_size = 0, wsrep_cluster_status = DISCONNECTED,表明node并未加入到 cluster 中。这是因为,需要在修改 mariadb 配置,来开启 wsrep

[galera]# Mandatory settingswsrep_on=ONwsrep_provider=/usr/lib/galera/libgalera_smm.sowsrep_cluster_address="gcomm://10.240.140.2,10.240.140.3"binlog_format=row#default_storage_engine=InnoDB#innodb_autoinc_lock_mode=2

修改后重启,查看状态

MariaDB []> show status like 'wsrep_%';+------------------------------+--------------------------------------+| Variable_name | Value |+------------------------------+--------------------------------------+| 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 | 1 || wsrep_cluster_state_uuid | 11204c5f-9ba9-11e8-a8dc-2acc1cebe53a || 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 |...
3.安装MariaDB、galera、xtrabackup

1.安装前,需要先卸载掉mysql-libs:
rpm -e --nodeps mysql-libs
2.安装MariaDB、galera、xtrabackup:
yum -y install MariaDB-Galera-server galera MariaDB-client xtrabackup
3.设置启动mariadb,加固安全
chkconfig mysql on && service mysql start
mysql_secure_installation
4.mysql -uroot -p登录后,检查maryiadb的启动信息中,是否有wsrep的信息:
Server version: 10.0.20-MariaDB-wsrep MariaDB Server, wsrep_25.10.r4144

gpgcheck=0

本文由美狮美高梅官方网站发布,转载请注明来源

关键词: