###由于zabbix server在阿里云,配置较低,难以承担目前业务,考虑迁移到 本地机房 zabbix server 升级迁移
##zabbixserver 192.168.xxx.256
##zabbix 数据库 192.168.1xx.xx2
##另外有个两台zabbix-proxy ,1台阿里云,另外一台在另一个机房中
配置:
zabbixserver 1192.168.xxx.256 C8M16D40
zabbix mysql 192.168.1xx.xx2 CM16D40 +100G
##server 端安装
###升级系统到最新7.5
hostnamectl set-hostname zabbix.jkabc.com
yum update -y
yum install yum-utils
rpm -ivh http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
yum-config-manager --enable rhel-7-server-optional-rpms
yum install zabbix-server-mysql
yum install zabbix-web-mysql
###在zabbixserver 进行配置
cp /etc/zabbix/zabbix_server.conf{,.bk}
cat > /etc/zabbix/zabbix_server.conf <<EOF
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
SocketDir=/var/run/zabbix
DBHost=192.168.1xx.xx2
DBName=zabbix
DBUser=zabbix
DBPassword=xxxxxxxxx
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
Timeout=4
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000
CacheSize=8000M
EOF
##设置报警脚本,在/usr/lib/zabbix/alertscripts
cat > /usr/lib/zabbix/alertscripts/BJ_test_dingding.py <<EOF
#!/usr/bin/python
# -*- coding: utf-8 -*-
import requests
import json
import sys
import os
headers = {'Content-Type': 'application/json;charset=utf-8'}
api_url = "https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxx"
def msg(text):
json_text= {
"msgtype": "text",
"text": {
"content": text
},
"at": {
"atMobiles": [
"1881xxxxxxxxxx"
],
"isAtAll": False
}
}
print requests.post(api_url,json.dumps(json_text),headers=headers).content
if __name__ == '__main__':
text = sys.argv[1]
msg(text)
EOF
cat > /usr/lib/zabbix/alertscripts/sendmail.py <<EOF
#-*- coding:utf-8 -*-
''' from: 改成你的邮箱地址 '''
import smtplib,sys,datetime
from email.Header import Header
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart
def send_mail(to_addr,subject,content):
msg = MIMEMultipart()
msg['to'] = to_addr
msg['from'] = '***[email protected]'
msg['subject'] = Header(subject+'[' + str(datetime.date.today()) + ']', 'utf-8')
text_msg = MIMEText(content,'plain','utf-8')
msg.attach(text_msg)
try:
s = smtplib.SMTP_SSL('smtp.exmail.qq.com','465')
s.ehlo()
#s.connect(mail_host)
s.login('***[email protected]','XXXXXXXXXX')
s.sendmail(msg['from'],msg['to'],msg.as_string())
s.close()
return True
except Exception,e:
print str(e)
return False
if __name__ == '__main__':
send_mail(sys.argv[1], sys.argv[2], sys.argv[3])
EOF
###启动服务
systemctl enable zabbix-server && systemctl start zabbix-server
##在mysqlserver 192.168.1xx.xx2 上执行
###更新系统
yum update -y
yum install maraidb-server -y
##初始化mysql
##安装zabbix 服务
rpm -ivh http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
yum-config-manager --enable rhel-7-server-optional-rpms
yum install zabbix-server-mysql
##创建数据库
create database zabbix default charset utf8;
GRANT all privileges ON zabbix.* TO 'zabbix'@'%' identified by 'xxxxxxxxm' WITH GRANT OPTION;
##进入目录
/usr/share/doc/zabbix-server-mysql-4.0.2
cp create.sql.gz{,.bk}
gunzip create.sql.gz
##在create.sql 首行添加
USE zabbix;
##导入数据库
cat create.sql |mysql -uzabbix -p
###在web
cp /etc/httpd/conf.d/zabbix.conf{,.bk}
vim /etc/httpd/conf.d/zabbix.conf ##修改时区是Asia/Shanghai
php_value date.timezone Asia/Shanghai
其他不变
##修改中文字体库,修复中文乱码
在目录/usr/share/zabbix/fonts/字体库中有个默认的graphfont.ttf ,从windows 机器上复制一个simkai.ttf 到该目录
simkai.ttf
###修改默认字体库,把里面graphfont 修改成simkai
vim /usr/share/zabbix/include/defines.inc.php
##启动httpd
systemctl enable httpd && systemctl start httpd
##web 登录 ip/zabbix 进行设置
##设置完成之后
ip/zabbix 用户名和密码:Admin/zabbix
###server端安装完成###############
### 安装zabbix 客户端
##备注 由于客户端涉及到centos6 centos7 两种系统,分别下载下来,放到各个系统的/tmp下面
##在跳板机 上执行如下,放到各个系统的/tmp下面
ansible all_servers -m copy -a 'src=/etc/ansible/script/zabbix_agent-rpm/ dest=/tmp/'
###针对虚拟机脚本如下
cat /etc/ansible/script/ZabbixAgentVms.sh
#!/bin/bash
if [ "`grep '192.168.xxx.256 zabbixserver.xxxx.com' /etc/hosts`" = "" ];then
echo "192.168.xxx.256 zabbixserver.xxxx.com" >> /etc/hosts
fi
IP=`ip a show dev eth0 scope global |grep "inet" |sed -e 's#.*inet##g' -e 's#/.*##g'`
zabbix_agent_conf(){
cp /etc/zabbix/zabbix_agentd.conf{,.bk}
cat > /etc/zabbix/zabbix_agentd.conf << EOF
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=1
EnableRemoteCommands=1
Server=zabbixserver.xxxx.com
ServerActive=zabbixserver.xxxxx.com
Hostname=$IP
BufferSize=200
Include=/etc/zabbix/zabbix_agentd.d/*.conf
UnsafeUserParameters=1
EOF
}
centos7_zabbix_agent(){
ps -ef|grep zabbix |awk '{print $2}' |xargs kill -9
rpm -ivh /tmp/zabbix-agent-4.0.2-1.el7.x86_64.rpm
zabbix_agent_conf
systemctl enable zabbix-agent && systemctl start zabbix-agent
}
centos6_zabbix_agent(){
ps -ef|grep zabbix |awk '{print $2}' |xargs kill -9
rpm -ivh /tmp/zabbix-agent-4.0.2-1.el6.x86_64.rpm
zabbix_agent_conf
service zabbix-agent start && chkconfig zabbix-agent on
}
if [ `cat /etc/redhat-release |sed -r 's/.* ([0-9]+)\..*/\1/'` -eq 7 ];then
echo "centos 7"
centos7_zabbix_agent
else
echo "centos6"
centos6_zabbix_agent
fi
#####ansible 添加客户端用例
1.zabbix-agent rpm包 先推送到 客户端
ansible all_servers -m copy -a 'src=/etc/ansible/script/zabbix_agent-rpm/ dest=/tmp/'
2.执行客户端安装脚本
ansible test -m script -a "script/ZabbixAgentVms.sh"
3.##测试是否正常
cat test_zabbix_agent.sh
#!/bin/bash
#read -p "请输入需要测试的IP地址:" $1
ssh 192.168.xxx.256 "
echo "system.uptime为:";
zabbix_get -s $1 -p10050 -k \"system.uptime\"
##测试结果
sh test_zabbix_agent.sh 192.168.xxx.xxx
system.uptime为:
12859568
###后期会补充上zabbix-proxy 相关安装文档
###后期会补充上zabbix-proxy 相关安装文档
##install zabbix_proxy
rpm -ivh http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
yum install zabbix-proxy mariadb-server zabbix-get
systemctl enable mariadb && systemctl start mariadb
##setting mysqld
create database zabbix_proxy default charset utf8;
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| zabbix_proxy |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]> grant all privileges on zabbix_proxy.* to 'zabbix_proxy'@'%' identified by 'xxxxxxxxxxxx' with grant option;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]>
[root@zabbix-proxy ~]# rpm -ql zabbix-proxy-mysql |grep sql.gz
/usr/share/doc/zabbix-proxy-mysql-4.0.2/schema.sql.gz
[root@zabbix-proxy ~]#
gunzip schema.sql.gz
[root@zabbix-proxy zabbix-proxy-mysql-4.0.2]# ls
AUTHORS ChangeLog COPYING NEWS README schema.sql
##导入库文件
zabbix-proxy-mysql-4.0.2]# mysql -uzabbix_proxy -p zabbix_proxy < /usr/share/doc/zabbix-proxy-mysql-4.0.2/schema.sql
###设置zabbix-proxy
cp /etc/zabbix/zabbix_proxy.conf{,.bk}
cat > /etc/zabbix/zabbix_proxy.conf <<EOF
ProxyMode=0
Server=xxxxxxxxxx
ServerPort=10051
Hostname=bjjxq_proxy
LogFile=/var/log/zabbix/zabbix_proxy.log
LogFileSize=1
PidFile=/var/run/zabbix/zabbix_proxy.pid
SocketDir=/var/run/zabbix
DBHost=localhost
DBName=zabbix_proxy
DBUser=zabbix_proxy
DBPassword=xxxxxx
ConfigFrequency=300
DataSenderFrequency=60
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
Timeout=4
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000
EOF
systemctl enable zabbix-proxy && systemctl start zabbix-proxy
###测试
1.安装zabbix-agent
yum install zabbix-agent -y
cat > /etc/zabbix/zabbix_agentd.conf <<EOF
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=1
EnableRemoteCommands=1
Server=zabbixproxy.xxxxxxx.com
ServerActive=zabbixproxy.xxxxxxcom
Hostname= 192xxxxxx
BufferSize=200
Include=/etc/zabbix/zabbix_agentd.d/*.conf
UnsafeUserParameters=1
EOF
echo "192.xxxx zabbixproxy.fxxxxx.com" >> /etc/hosts
systemctl enable zabbix-agent && systemctl start zabbix-agent
2.在zabbixserver 端 设置后,可以监控到 proxy 中的数据
###ansible 安装zabbix-agent
1. 下载zabbix-agent rpm
##在跳板机 上
/etc/ansible/scripts/zabbix_agent-rpm/zabbix-agent-4.0.2-1.el6.x86_64.rpm
/etc/ansible/scripts/zabbix_agent-rpm/zabbix-agent-4.0.2-1.el7.x86_64.rpm
ansible zabbix -m copy -a "src=/etc/ansible/scripts/zabbix_agent-rpm/ dest=/tmp"
2.ansbile 统一安装
ansible controller -m script -a "scripts/ZabbixAgentPhy.sh"
ansible compute -m script -a "scripts/ZabbixAgentPhy.sh"
ansible ceph -m script -a "scripts/ZabbixAgentPhy.sh"
ansible vms -m script -a "scripts/ZabbixAgentVms.sh"
3.在server 端进行配置 主机
##到这里就全部迁移完成