标签:zabbix ha
MariaDB.repo
—————————————————
[mariadb]
name = MariaDB
baseurl = https://mirrors.ustc.edu.cn/mariadb/yum/10.2/centos7-amd64
gpgkey=https://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1
—————————————————
PHP.repo
—————————————————
[webtatic]
name=Webtatic Repository EL7 - $basearch
#baseurl=https://repo.webtatic.com/yum/el7/$basearch/
mirrorlist=https://mirror.webtatic.com/yum/el7/$basearch/mirrorlist
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-webtatic-el7
[webtatic-debuginfo]
name=Webtatic Repository EL7 - $basearch - Debug
#baseurl=https://repo.webtatic.com/yum/el7/$basearch/debug/
mirrorlist=https://mirror.webtatic.com/yum/el7/$basearch/debug/mirrorlist
failovermethod=priority
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-webtatic-el7
[webtatic-source]
name=Webtatic Repository EL7 - $basearch - Source
#baseurl=https://repo.webtatic.com/yum/el7/SRPMS/
mirrorlist=https://mirror.webtatic.com/yum/el7/SRPMS/mirrorlist
failovermethod=priority
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-webtatic-el7
——————————————————————————————————————————
以下是配置详情:
环境准备:
操作系统:Centos7
Mysql数据库:3台,主从从
192.168.1.31/32/33
31做主,VIP 192.168.1.30
Zabbix HA:192.168.1.34 zabbix-server1
192.168.1.35 zabbix-server2
VIP:192.168.1.66
文件夹说明
zabbix-web /usr/share/nginx/html/zabbix/
zabbix_server.conf /etc/zabbix/
nginx.conf /etc/nginx/nginx.conf
? ?
?
准备工作
1./etc/hosts/写入2台服务器计算机名和ip地址
2.2台服务器双向ssh互通
3.关闭selinux
4.关闭防火墙
5.卸载已安装的Nginx,php,Mariadb
—————————————————
2台zabbix服务器安装装必要软件
#yum update -y
?
#yum install -y php72w-{fpm,tidy,bcmath,process,pdo,pgsql,xml,snmp,pear,gd,xmlrpc,common,mysql,xcache,mbstring,soap,ldap,cli,odbc,imap,devel,mcrypt,mssql}
zabbix-web zabbix-server MariaDB-client nginx pcs pacemaker
?
配置LNMP
————————————————————————
将/usr/share/zabbix 拷贝到/usr/share/nginx/html/下
#cd /usr/share/nginx/html/zabbix/conf/
拷贝conf文件夹下的zabbix.conf.php.example到/etc/zabbix/web/下并改名为zabbix.conf.php
#cp /usr/share/nginx/html/zabbix/conf/zabbix.conf.php.example /etc/zabbix/zabbix.conf.php
——————————————————
修改zabbix.conf.php:#vim zabbix.conf.php
<?php
// Zabbix GUI configuration file.
global $DB;
?
$DB[‘TYPE‘] = ‘MYSQL‘;#数据库类型
$DB[‘SERVER‘] = ‘192.168.1.30‘;#数据库服务器
$DB[‘PORT‘] = ‘3306‘;#数据库端口
$DB[‘DATABASE‘] = ‘zabbix‘;#库名
$DB[‘USER‘] = ‘zabbix‘;#数据库用户
$DB[‘PASSWORD‘] = ‘zabbix‘;#数据库密码
?
// Schema name. Used for IBM DB2 and PostgreSQL.
$DB[‘SCHEMA‘] = ‘‘;
?
$ZBX_SERVER = ‘192.168.1.66‘;#zabbix主机,使用cluster ip
$ZBX_SERVER_PORT = ‘10051‘;#zabbix端口
$ZBX_SERVER_NAME = ‘Wula_Monitor‘;#监控名
?
$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;
修改完成后,同步到另一台服务器:scp /etc/zabbix/conf/zabbix.conf.php root@zabbix-server2:‘/etc/zabbix/conf/‘
————————————————————————
2台服务器上分别启动服务
#systemctl start nginx
#systemctl start php-fpm
——————————————————————
在zabbix-server1配置zabbix_server.conf
#vim /etc/zabbix/zabbix_server.conf
ListenPort=10051
SourceIP=192.168.1.66
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
SocketDir=/var/run/zabbix
DBHost=192.168.1.30
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBSocket=/data/mysql/mysql.sock
StartAlerters=3
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
ListenIP=192.168.1.66
Timeout=4
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000
修改完成后,同步到另一台服务器:scp /etc/zabbix/zabbix_server.conf root@zabbix-server2:‘/etc/zabbix/zabbix_server.conf‘
主数据库操作192.168.1.30
初始化zabbix数据库
#mysql_secure_installation
注意初始化数据库是不要关闭远程访问
创建zabbix数据库
#create database zabbix character set utf8;
创建用户zabbix密码zabbix并赋权访问zabbix数据库,地址为192.168.1.x
#grant all privileges on zabbix.* to zabbix@‘192.168.1.%‘ identified by ‘zabbix‘;
flush privileges;
?
在任意一台zabbix服务器上找到数据库文件导入到mysql数据库
#cd /usr/share/doc/zabbix-server-mysql-3.4.7
数据库文件create.sql.gz
#zcat create.sql.gz |mysql -u zabbix -pzabbix zabbix -h192.168.1.30
查看数据库是否被导入
#mysql -u zabbix -p -h 192.168.1.30
?
————————————————————————
2台ZABBIX配置Pacemaker
#zabbixserver1
#sudo passwd hacluster
#sudo systemctl start pcsd.service
#sudo systemctl enable pcsd.service
?
#zabbixserver2
#sudo passwd hacluster
#sudo systemctl start pcsd.service
#sudo systemctl enable pcsd.service
启动服务
?
————————————————————————
2台服务器互相认证
#pcs cluster auth zabbix-server1 zabbix-server2
创建集群zabbixserver
#pcs cluster setup --name zabbixserver zabbix-server1 zabbix-server2
启动集群
#pcs cluster start --all
打开corosync&pacemaker服务
#zabbixserver1
#sudo systemctl enable corosync.service
#sudo systemctl enable pacemaker.service
#zabbixserver2
#sudo systemctl enable corosync.service
#sudo systemctl enable pacemaker.service
因为我们只有2台服务器,关闭stonith;
#pcs property set stonith-enabled=false
忽略最低节点要求
#pcs property set no-quorum-policy=ignore
配置集群VIP地址
#pcs resource create cluster_vip ocf:heartbeat:IPaddr2 ip=192.168.1.66 cidr_netmask=24 op monitor interval=20s
测试下VIP地址
#ping -c1 192.168.1.66
关闭2台zabbix上的zabbix-server服务
#zabbixserver1
#sudo systemctl disable zabbix-server
#zabbixserver2
#sudo systemctl disable zabbix-server
在pacemaker上配置zabbix-server服务,让zabbix-server始终在集群中运行
#pcs resource create zabbix_server systemd:zabbix-server op monitor interval=10s
配置zabbix-server始终与VIP保持在同一台服务器上运行。因此当VIP绑定在那台服务器上,那台服务器上才开始运行zabbix-server服务,防止脑裂
#pcs constraint colocation add zabbix_server cluster_vip
#pcs constraint order cluster_vip then zabbix_server
如果希望zabbix-server在特定的服务器上运行,提升其中一台的优先度
#pcs constraint location cluster_vip prefers zabbix-server1
#pcs constraint location zabbix_server prefers zabbix-server1
————————————————————
配置到这基本结束
#pcs status 查看集群状态
?
?
————————————————————————
如果出现ocf_timeout(198)报错,基本就是zabbix_server.conf 有问题,可能是2边不同步,让其中一台node standby,#pcs node standby,看另一台VIP是否启动,如果启动,查看zabbix日志,#tail -f /var/log/zabbix/zabbix_server.log;手动启动zabbix-server服务,查看日志,找问题
————————————————————————
至此,配置完成,地址:http://192.168.1.66/zabbix
标签:zabbix ha
原文地址:http://blog.51cto.com/7040682/2074567