您的位置:首页 > 运维架构 > Linux

zabbix 4.2 的安装和设置(mysql57----centos7)

2019-07-04 16:17 351 查看

一、安装RPM
[root@localhost ~]# rpm -ivh https://repo.zabbix.com/zabbix/4.2/rhel/7/x86_64/zabbix-release-4.2-1.el7.noarch.rpm

二、安装相关软件
[root@localhost ~]# yum install mysql-server httpd php -y
[root@localhost ~]# yum install zabbix-server-mysql zabbix-web-mysql -y
[root@localhost ~]# yum install zabbix-agent -y

三、创建数据库、导入zabbix需要的表、创建用户并授权

第一次启动mysql,会在日志文件中生成root用户的一个随机密码,使用下面命令查看该密码
[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log

修改root用户密码
[root@localhost ~]# mysql -u root -p
Enter password:

mysql> alter user 'root'@'localhost' identified by 'p@$$w0rd';

创建数据库
mysql> create database zabbix;

导入zabbix需要的表
[root@localhost ~]# zcat /usr/share/doc/zabbix-server-mysql-4.2.3/create.sql.gz | mysql -uroot -p zabbix

创建用户并授权
mysql> create user zabbix@'localhost' identified by 'p@$$w0rd-zabbix';
mysql> grant all privileges on zabbix.* to zabbix@'localhost';
mysql> flush privileges;

四、编辑文件/etc/zabbix/zabbix_server.conf加入server信息

SocketDir=/var/run/zabbix
DBName=zabbix
DBUser=zabbix
DBPasswd=p@$$w0rd-zabbix

查看检查配置:
[root@localhost ~]# grep -v '^#' /etc/zabbix/zabbix_server.conf |grep -v '^$'

LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
SocketDir=/var/run/zabbixs
DBName=zabbix
DBUser=zabbix
DBPassword=Zabbix-123456
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
Timeout=4
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000
StatsAllowedIP=127.0.0.1

DBName=zabbix                            #zabbix所属数据库名称
DBUser=zabbix                            #zabbix所属数据库用户
DBPassword=www.xxxxxx.com                #zabbix数据库密码
StartPollers=30                         #轮询的初始值(0-1000)
StartIPMIPollers=4                       #IPMI轮询的初始值(0-1000)
StartPollersUnreachable=30              # 轮询不可达的主机数(包括IPMI 0-1000)
StartTrappers=8                         #捕获的初始值(0-1000)
StartPingers=4                          #ping的初始值(0-1000)
StartDiscoverers=0                      #自动发现的初始值(0-250)
CacheSize=384M                          #缓存大小
CacheUpdateFrequency=300                #缓存更新的频率
StartDBSyncers=8                        #数据库同步时间
TrendCacheSize=128M                     #总趋势缓存大小
AlertScriptsPath=/usr/bin               #脚本的存放位置
LogSlowQueries=1000                     #日志慢查询设定

五、修改时区:
vim /etc/httpd/conf.d/zabbix.conf
date.timezone = Asia/Shanghai

解决中文乱码
yum -y install wqy-microhei-fonts
cp /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /usr/share/fonts/dejavu/DejaVuSans.ttf

六、设置开机启动
systemctl enable mysqld
systemctl enable zabbix-server
systemctl enable httpd

zabbix 脚本--------------------------------------------------------------------------------------------------------------------------
.2.2 服务端快速安装脚本

#!/bin/bash

#clsn

#设置解析 注意:网络条件较好时,可以不用自建yum源

# echo '10.0.0.1 mirrors.aliyuncs.com mirrors.aliyun.com repo.zabbix.com' >> /etc/hosts

#安装zabbix源、aliyun YUM源

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm

#安装zabbix

yum install -y zabbix-server-mysql zabbix-web-mysql

#安装启动 mariadb数据库

yum install -y mariadb-server
systemctl start mariadb.service

#创建数据库

mysql -e 'create database zabbix character set utf8 collate utf8_bin;'
mysql -e 'grant all privileges on zabbix.* to zabbix@localhost identified by "zabbix";'

#导入数据

zcat /usr/share/doc/zabbix-server-mysql-3.0.13/create.sql.gz|mysql -uzabbix -pzabbix zabbix

#配置zabbixserver连接mysql

sed -i.ori '115a DBPassword=zabbix' /etc/zabbix/zabbix_server.conf

#添加时区

sed -i.ori '18a php_value date.timezone Asia/Shanghai' /etc/httpd/conf.d/zabbix.conf

#解决中文乱码

yum -y install wqy-microhei-fonts
\cp /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /usr/share/fonts/dejavu/DejaVuSans.ttf

#启动服务

systemctl start zabbix-server
systemctl start httpd

#写入开机自启动

chmod +x /etc/rc.d/rc.local
cat >>/etc/rc.d/rc.local<<EOF
systemctl start mariadb.service
systemctl start httpd
systemctl start zabbix-server
EOF

#输出信息

echo "浏览器访问 http://

hostname -I|awk '{print $1}'
/zabbix"
2.2.3 客户端快速部署脚本

#!/bin/bash

#clsn

#设置解析

echo '10.0.0.1 mirrors.aliyuncs.com mirrors.aliyun.com repo.zabbix.com' >> /etc/hosts

#安装zabbix源、aliyu nYUM源

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm

#安装zabbix客户端

yum install zabbix-agent -y
sed -i.ori 's#Server=127.0.0.1#Server=172.16.1.61#' /etc/zabbix/zabbix_agentd.conf
systemctl start zabbix-agent.service

#写入开机自启动

chmod +x /etc/rc.d/rc.local
cat >>/etc/rc.d/rc.local<<EOF
systemctl start zabbix-agent.service
EOF
2.3 检测连通性
2.3.1 服务端安装zabbix-get检测工具
yum install zabbix-get
2.3.2 在服务端进行测试
注意:只能在服务端进行测试

zabbix_get -s 172.16.1.61 -p 10050 -k "system.cpu.load[all,avg1]"
zabbix_get -s 172.16.1.21 -p 10050 -k "system.cpu.load[all,avg1]"
测试结果

[root@m01 ~]# zabbix_get -s 172.16.1.61 -p 10050 -k "system.cpu.load[all,avg1]"
0.000000

[root@m01 ~]# zabbix_get -s 172.16.1.21 -p 10050 -k "system.cpu.load[all,avg1]"
0.000000

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: