zabbix高可用搭建--数据库集群(2)

一、数据mariadb集群搭建分为两个内容
1、负载均衡搭建
2、mariadb galera cluster
二、负载均衡搭建
负载均衡集群是 load balance 集群的简写,翻译成中文就是负载均衡集群。常用的负载均衡开源软件有nginx、lvs、haproxy,商业的硬件负载均衡设备F5、Netscale。这里主要是学习 LVS 并对其进行了详细的总结记录。本次采用lvs的DR模式
2.1 安装keepalive和lvs安装包
yum install -y ##### keepalived 安装keepalive
yum install -y ipvsadm ##### 安装装lvs
2.2、编辑keepalive的配置,keepalive与网络的vrrp原理一样
vi /etc/keepalive/keepalived.conf
vrrp_instance VI_1 {
state MASTER
! nopreempt
interface chkconfig keepalived on
garp_master_delay 10
virtual_router_id 50
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass zabbix
}
virtual_ipaddress {
192.168.1.157
}
}

virtual_server 192.168.1.157 3306 {
delay_loop 6
lb_algo wrr
lb_kind DR
nat_mask 255.255.255.0
persistence_timeout 50
protocol TCP

real_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 1
TCP_CHECK {
connect_port 3306
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}

}

}

2.3.开启keepalive、ipvsam服务
systemctl start keepalived
systemctl start ipvsam
2.4、验证
ipvsam 查看负载情况
三、mariadb 集群
3.1 数据库安装
分别在三台主机安装mariadb的数据,本次安装10.3.14版本的数据,较为稳定的版本
vi /etc/yum.repos.d/MariaDB.repo
[mariadb]
name = MariaDB-10.3.14
baseurl=http://yum.mariadb.org/10.3.14/centos7-amd64

alternative: baseurl=http://archive.mariadb.org/mariadb-10.3.14/yum/centos7-amd64

gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

[[email protected] /]# yum install mariadb-server -y
Loaded plugins: langpacks, product-id, subscription-manager
Complete!
[[email protected] /]# rpm -qa | grep mariadb
mariadb-server-5.5.50-1.el7_2.x86_64
mariadb-libs-5.5.50-1.el7_2.x86_64
mariadb-5.5.50-1.el7_2.x86_64
mariadb-devel-5.5.50-1.el7_2.x86_64
启动mariadb服务程序并添加到开机启动项中:
[[email protected] /]# systemctl start mariadb
[[email protected] /]# systemctl enable mariadb
[[email protected] /]# netstat -anpt | grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 22418/mysqld
[[email protected] /]# ps -ef | grep mariadb
mysql 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.sock
root 22459 1092 0 00:40 pts/0 00:00:00 grep --color=auto mariadb
[[email protected] /]# 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步:刷新授权表,让初始化后的设定立即生效。
初始化数据库服务程序:
[[email protected] /]# mysql_secure_installation
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found
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: 输入要为root用户设置的数据库密码。
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(禁止root用户从远程登陆)
... 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(删除test数据库并取消对其的访问权限)

  • 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!
    使用root用户登陆到数据库中:
    [[email protected]st /]# mysql -u root -p
    Enter password: 此处输入root用户在数据库中的密码。
    Welcome to the MariaDB monitor. Commands end with ; or \g.
    Your MariaDB connection id is 5
    Server version: 5.5.35-MariaDB MariaDB Server
    Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.
    Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
    MariaDB [(none)]>
    查看当前已有的数据库:
    MariaDB [(none)]> show databases;
    +--------------------+
    | Database |
    +--------------------+
    | information_schema |
    | mysql |
    | performance_schema |
    +--------------------+
    3 rows in set (0.01 sec)
    3.2 配置集群
    vi /etc/my.conf
    [mysqld]
    binlog_format=ROW
    default-storage-engine=innodb
    innodb_autoinc_lock_mode=2
    bind-address=0.0.0.0

    Galera Provider Configuration

    wsrep_on=ON
    wsrep_provider=/usr/lib64/galera/libgalera_smm.so

    Galera Cluster Configuration

    wsrep_cluster_name="galera_cluster"
    wsrep_cluster_address="gcomm://192.168.1.192.168.1.155,192.168.1.156,"

Galera Synchronization Configuration

wsrep_sst_method=rsync

Galera Node Configuration

wsrep_node_address="192.168.1.156" #####其他节点需要修改
wsrep_node_name="Node1" #####其他节点需要修改
第1个节点先启动 使用galera_new_cluster
其他节点使用 systemctl start mariadb
3.4 安装zabbix-server-mysql
为了将zabbix的数据文件导入mysql中

mysql -uroot -p

password
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to [email protected] identified by ‘password‘;
mysql> quit;
导入初始架构和数据,系统将提示您输入新创建的密码。

zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix

五、配置vip
因为负载均衡lvs的DR原理,每台数据库都必须配置vip地址,并不对外进行广播
#!/bin/bash
#description:start realserver
vip1=192.168.1.157
case $1 in
start)
echo "Start Realserver"
/sbin/ifconfig lo:0 $vip1 broadcast $vip1 netmask 255.255.255.255 up

echo "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 down
echo "0" > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo "0" > /proc/sys/net/ipv4/conf/lo/arp_announce
echo "0" > /proc/sys/net/ipv4/conf/all/arp_ignore
echo "0" > /proc/sys/net/ipv4/conf/all/arp_announce
;;
*)
echo "Usage: $0 (start | stop)"
exit 1
esac
最后运行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

时间: 2024-08-21 14:18:15

zabbix高可用搭建--数据库集群(2)的相关文章

MyCAT+MySQL 搭建高可用企业级数据库集群

第1章 课程介绍课程介绍1-1 MyCAT导学 试看1-2 课程介绍 第2章 MyCAT入门这一章中,我们将回顾了垂直切分,水平切分,分库分表等基础概念,然后快速回如何安装和启动MyCAT的,介绍如何以打包好的可执行程序的方式来启动MyCAT.以及如何对其相关的启动配置文件进行配置.2-1 章节综述2-2 什么是MyCAT2-3 什么是数据库中间层2-4 MyCAT的主要作用2-5 MyCAT基本元素2-6 MyCAT安装 第3章 MYCAT核心配置详解本章将对MyCAT的常用核心配置文件ser

MyCAT+MySQL 搭建高可用企业级数据库集群——第1章 课程介绍

1-1 Mycat导学 1-2 课程介绍 1-1 Mycat导学 1.Mycat导学内容介绍: PS:来吧,让我们一起努力,变成更好的自己吧! 1-2 课程介绍 1.课程介绍: 目标:通过Mycat实现MySQL的高可用集群架构: 原文地址:https://www.cnblogs.com/tqtl911/p/9099913.html

MyCAT+MySQL 搭建高可用企业级数据库集群——第2章 MyCat入门

2-1 章节综述 2-2 什么是MyCat 2-3 什么是数据库中间层 2-4 MyCat的主要作用 2-5 MyCat基本元素 2-6 MyCat的安装 2-1 章节综述 1.掌握Mycat的基础概念.功能及适用场景: 2.掌握Mycat的安装和启动: 2-2 什么是MyCat 1.不同的工种对Mycat的不同理解: 研发人员: 架构师: 2.实现"读写分离"的两种方式: 从程序的角度实现,配置两套数据源: 通过中间件的角度实现,比如Mycat: 2-3 什么是数据库中间层 1.数据

MyCAT+MySQL 搭建高可用企业级数据库集群——第4章 MyCat进阶实战至垂直分库

4-1 为什么要进行垂直分库和相关操作 4-2 收集分析业务模块 4-3 MySQL复制的步骤 4-4 MySQL复制环境说明 4-5 MySQL复制实战 4-6 MySQL复制总结 4-7 垂直切分 4-8 垂直切分相关配置 4-9 垂直切分schema文件配置 4-10 垂直切分server文件配置 4-11 后续工作 4-12 Mycat启动调试 4-13 Mycat验证配置 4-14 清理多余数据 4-15 跨分片查询 4-16 配置和验证全局表 4-17 垂直切分的优缺点 4-1 为什

搭建高可用mongodb shard 集群以及多节点备份

mongodb通过哪些机制实现路由.分片: 从图中可以看到有四个组件:mongos.config server.shard.replica set. mongos,数据库集群请求的入口,所有的请求都通过mongos进行协调,不需要在应用程序添加一个路由选择器,mongos自己就是一个请求分发中心,它负责把对应的数据请求请求转发到对应的shard服务器上.在生产环境通常有多mongos作为请求的入口,防止其中一个挂掉所有的mongodb请求都没有办法操作. config server,顾名思义为配

搭建高可用的MongoDB集群副本集

什么是副本集呢?打魔兽世界总说打副本,其实这两个概念差不多一个意思.游戏里的副本是指玩家集中在高峰时间去一个场景打怪,会出现玩家暴多怪物少的情况,游戏开发商为了保证玩家的体验度,就为每一批玩家单独开放一个同样的空间同样的数量的怪物,这一个复制的场景就是一个副本,不管有多少个玩家各自在各自的副本里玩不会互相影响. mongoDB的副本也是这个,主从模式其实就是一个单副本的应用,没有很好的扩展性和容错性.而副本集具有多个副本保证了容错性,就算一个副本挂掉了还有很多副本存在,并且解决了上面第一个问题"

Windows 2012 系统搭建高可用故障转移集群

Windows 2012 系统搭建高可用故障转移集群 一.故障转移集群介绍 2 1.1 系统介绍 2 1.2 工作原理 2 二.实验目的 2 2.1 验证故障转移功能 2 2.2 验证高可用集群的可用性,以及支持的服务类型 2 三.实验原理 3 3.1 实验拓扑 3 3.2 实验环境设备 3 四.配置步骤 4 4.1 配置域服务器 4 4.2  iSCSI 虚拟存储配置 18 4.3 配置故障转移集群服务 45 4.4  验证集群 63 五.实验结果验证 68 5.1  验证故障转移 68 5.

Nginx+Keepalived搭建高可用负载均衡集群

Nginx+Keepalived搭建高可用负载均衡集群   一. 环境说明 前端双Nginx+keepalived,nginx反向代理到后端的tomcat集群实现负载均衡,Keepalived实现集群高可用. 操作系统: Centos 6.6_X64 Nginx版本: nginx-1.9.5 Keepalived版本:keepalived-1.2.13 结构: Keepalived+nginx-MASTER:10.6.1.210         Keepalived+nginx-BACKUP:

使用keepalived搭建高可用的LVS-DR集群

使用keepalived搭建高可用的LVS-DR集群   一:Keepalived服务概述 keepalived 是一个类似于 layer3, 4 & 5 交换机制的软件,也就是我们平时说的第 3 层.第 4 层和第 5层交换. Keepalived 的作用是检测 web 服务器的状态,如果有一台 web 服务器死机,戒工作出现故障,Keepalived 将检测到,并将有故障的 web 服务器从系统中剔除,当 web 服务器工作正常后 Keepalived 自劢将web 服务器加入到服务器群中,