本文共 7474 字,大约阅读时间需要 24 分钟。
一、数据mariadb集群搭建分为两个内容
1、负载均衡搭建2、mariadb galera cluster二、负载均衡搭建负载均衡集群是 load balance 集群的简写,翻译成中文就是负载均衡集群。常用的负载均衡开源软件有nginx、lvs、haproxy,商业的硬件负载均衡设备F5、Netscale。这里主要是学习 LVS 并对其进行了详细的总结记录。本次采用lvs的DR模式2.1 安装keepalive和lvs安装包yum install -y ##### keepalived 安装keepaliveyum install -y ipvsadm ##### 安装装lvs2.2、编辑keepalive的配置,keepalive与网络的vrrp原理一样vi /etc/keepalive/keepalived.confvrrp_instance VI_1 { state MASTER! nopreemptinterface chkconfig keepalived ongarp_master_delay 10virtual_router_id 50priority 100advert_int 1authentication { auth_type PASSauth_pass zabbix}virtual_ipaddress { 192.168.1.157}}virtual_server 192.168.1.157 3306 {
delay_loop 6lb_algo wrrlb_kind DRnat_mask 255.255.255.0persistence_timeout 50protocol TCPreal_server 192.168.1.154 3306 { weight 1 TCP_CHECK { connect_port 3306 connect_timeout 3 nb_get_retry 3 delay_before_retry 3 }}real_server 192.168.1.155 3306 { weight 1 TCP_CHECK { connect_port 3306 connect_timeout 3 nb_get_retry 3 delay_before_retry 3 }}
real_server 192.168.1 3306 {
weight 1TCP_CHECK { connect_port 3306connect_timeout 3nb_get_retry 3delay_before_retry 3}}
}
2.3.开启keepalive、ipvsam服务
systemctl start keepalivedsystemctl start ipvsam2.4、验证ipvsam 查看负载情况三、mariadb 集群3.1 数据库安装 分别在三台主机安装mariadb的数据,本次安装10.3.14版本的数据,较为稳定的版本vi /etc/yum.repos.d/MariaDB.repo[mariadb]name = MariaDB-10.3.14baseurl=gpgkey=
gpgcheck=1[root@localhost /]# yum install mariadb-server -y
Loaded plugins: langpacks, product-id, subscription-managerComplete![root@localhost /]# rpm -qa | grep mariadbmariadb-server-5.5.50-1.el7_2.x86_64mariadb-libs-5.5.50-1.el7_2.x86_64mariadb-5.5.50-1.el7_2.x86_64mariadb-devel-5.5.50-1.el7_2.x86_64启动mariadb服务程序并添加到开机启动项中:[root@localhost /]# systemctl start mariadb[root@localhost /]# systemctl enable mariadb[root@localhost /]# netstat -anpt | grep 3306tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 22418/mysqld[root@localhost /]# ps -ef | grep mariadbmysql 22418 22259 0 00:39 ? 00:00:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sockroot 22459 1092 0 00:40 pts/0 00:00:00 grep --color=auto mariadb[root@localhost /]# ln -s '/usr/lib/systemd/system/mariadb.service' '/etc/systemd/system/multi-user.target.wants/mariadb.service'为了保证数据库的安全性,一定要进行初始化工作:第1步:设定root用户密码。第2步:删除匿名帐号。第3步:禁止root用户从远程登陆。第4步:删除test数据库并取消对其的访问权限。第5步:刷新授权表,让初始化后的设定立即生效。初始化数据库服务程序:[root@localhost /]# mysql_secure_installation/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not foundNOTE: 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 currentpassword for the root user. If you've just installed MariaDB, andyou 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 MariaDBroot user without the proper authorisation.Set root password? [Y/n] yNew password: 输入要为root用户设置的数据库密码。Re-enter new password: 重复再输入一次密码。Password updated successfully!Reloading privilege tables..... Success!By default, a MariaDB installation has an anonymous user, allowing anyoneto log into MariaDB without having to have a user account created forthem. This is intended only for testing, and to make the installationgo a bit smoother. You should remove them before moving into aproduction environment.Remove anonymous users? [Y/n] y(删除匿名帐号)... Success!Normally, root should only be allowed to connect from 'localhost'. Thisensures that someone cannot guess at the root password from the network.Disallow root login remotely? [Y/n] y(禁止root用户从远程登陆)... Success!By default, MariaDB comes with a database named 'test' that anyone canaccess. This is also intended only for testing, and should be removedbefore moving into a production environment.Remove test database and access to it? [Y/n] y(删除test数据库并取消对其的访问权限)wsrep_on=ON
wsrep_provider=/usr/lib64/galera/libgalera_smm.sowsrep_cluster_name="galera_cluster"
wsrep_cluster_address="gcomm://192.168.1.192.168.1.155,192.168.1.156,"wsrep_sst_method=rsync
wsrep_node_address="192.168.1.156" #####其他节点需要修改
wsrep_node_name="Node1" #####其他节点需要修改第1个节点先启动 使用galera_new_cluster其他节点使用 systemctl start mariadb3.4 安装zabbix-server-mysql为了将zabbix的数据文件导入mysql中password
mysql> create database zabbix character set utf8 collate utf8_bin;mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'password';mysql> quit;导入初始架构和数据,系统将提示您输入新创建的密码。五、配置vip
因为负载均衡lvs的DR原理,每台数据库都必须配置vip地址,并不对外进行广播#!/bin/bash#description:start realservervip1=192.168.1.157case $1 instart)echo "Start Realserver"/sbin/ifconfig lo:0 $vip1 broadcast $vip1 netmask 255.255.255.255 upecho "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce echo "1" > /proc/sys/net/ipv4/conf/all/arp_ignore echo "2" > /proc/sys/net/ipv4/conf/all/arp_announce
;;
stop)echo "Stop Realserver"/sbin/ifconfig lo:0 downecho "0" > /proc/sys/net/ipv4/conf/lo/arp_ignoreecho "0" > /proc/sys/net/ipv4/conf/lo/arp_announceecho "0" > /proc/sys/net/ipv4/conf/all/arp_ignoreecho "0" > /proc/sys/net/ipv4/conf/all/arp_announce;;*)echo "Usage: $0 (start | stop)"exit 1esac最后运行shell脚本常见故障
搭建galera cluster的时候设置sst为xtrabackup,启动node1报错。
[ERROR] WSREP: It may not be safe to bootstrap the cluster from this node. It was not the last one to leave the cluster and may not contain all the updates. To force cluster bootstrap with this node, edit the grastate.dat file manually and set safe_to_bootstrap to 1 .解决方式:grastate.dat file of the node you intend to use as the first node.需要把该文件删除 重新启动即可。转载于:https://blog.51cto.com/1194325/2384801