多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# CentOS7安装zabbix3.4 [TOC] # 第1章 准备环境   # 第2章 阿里云镜像CentOS7安装Zabbix3.4 ## 2.1 官网安装链接地址 ``` https://www.zabbix.com/download ``` 截图如下: ![](https://box.kancloud.cn/2e61d5955c979bfa4a4101b8fa39668e_698x524.png) 因为国内的原因,使用zabbix官网的源可能会安装失败,所以下面我们使用阿里云的zabbix源来安装. ## 2.2 使用阿里云的zabbix-server源安装 ### 2.2.1 配置zabbix阿里源 ``` [root@zabix-66 ~]# cat /etc/yum.repos.d/zabbix.repo [zabbix] name=Zabbix Official Repository - $basearch baseurl=https://mirrors.aliyun.com/zabbix/zabbix/3.4/rhel/7/x86_64/ enabled=1 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX-A14FE591 [zabbix-non-supported] name=Zabbix Official Repository non-supported - $basearch baseurl=https://mirrors.aliyun.com/zabbix/zabbix/3.4/rhel/7/x86_64/ enabled=1 gpgkey=https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX gpgcheck=1 ``` 清理缓存 ``` [root@zabix-66 ~]# yum clean all 已加载插件:fastestmirror 正在清理软件源: base epel extras updates zabbix zabbix-non-supported Cleaning up everything Cleaning up list of fastest mirrors ``` 重新生成元数据 ``` [root@zabix-66 ~]# yum makecache .................................... ``` ### 2.2.2 安装zabbix服务以及mysql ``` [root@zabix-66 ~]# yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent mariadb mariadb-server ``` ### 2.2.3 安全配置mysql数据库 ``` [root@zabix-66 ~]# systemctl start mariadb [root@zabix-66 ~]# systemctl enable mariadb Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service. [root@zabix-66 ~]# mysql_secure_installation ``` ###密码配置为zabbix,其他步骤一路回车 ``` [root@zabix-66 ~]# mysql -uroot -pzabbix MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin; MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix'; ``` ### 2.2.4 导入zabbix配置文件 ``` [root@zabix-66 ~]# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -pzabbix zabbix ``` ### 2.2.5 配置zabbix配置文件 ``` [root@zabix-66 ~]# egrep -v "^#|^$" /etc/zabbix/zabbix_server.conf LogFile=/var/log/zabbix/zabbix_server.log LogFileSize=0 PidFile=/var/run/zabbix/zabbix_server.pid SocketDir=/var/run/zabbix DBName=zabbix DBUser=zabbix DBPassword=zabbix SNMPTrapperFile=/var/log/snmptrap/snmptrap.log Timeout=4 AlertScriptsPath=/usr/lib/zabbix/alertscripts ExternalScripts=/usr/lib/zabbix/externalscripts LogSlowQueries=3000 ``` ### 2.2.6 配置php文件,修改时区 ``` [root@zabix-66 ~]# grep "php_value" /etc/httpd/conf.d/zabbix.conf php_value max_execution_time 300 php_value memory_limit 128M php_value post_max_size 16M php_value upload_max_filesize 2M php_value max_input_time 300 php_value always_populate_raw_post_data -1 php_value date.timezone Asia/Shanghai ``` ### 2.2.7 启动Apache Web服务器 ``` [root@zabix-66 ~]# systemctl start httpd ``` ### 2.2.8 登录web界面进行设置 ``` http://192.168.56.66/zabbix/setup.php ``` ![](https://box.kancloud.cn/5ba496455a4a7b3a7e8cedd2edbc2959_485x293.png) ![](https://box.kancloud.cn/80f88a0ff2ae4400602c09c5c204c672_483x283.png) ![](https://box.kancloud.cn/76ea97f8a03223098a793c2ec1a9301d_487x284.png) ![](https://box.kancloud.cn/706fd201a74a75ab76e9993f46d4eaae_475x281.png) ![](https://box.kancloud.cn/9788733ae3aea0460d5c83c49b137897_477x278.png) ![](https://box.kancloud.cn/23a1f8212a91c03a7b0067c220c6581c_474x277.png) ![](https://box.kancloud.cn/859bea5ad5b6d16b994d93be1c1e6990_475x273.png) 帐号Admin密码zabbix ![](https://box.kancloud.cn/391e773246e92fb04d688687b89de844_210x231.png) 设置中文 ![](https://box.kancloud.cn/fef823e3c41c918a88bdf10f43762455_596x299.png) ## 2.3 zabbix-agent安装部署 ### 2.3.1 安装zaxbbix-agent ``` [root@zabix-66 ~]# yum install zabbix-agent ``` ### 2.3.2 zabbix-agent安装配置 ``` [root@zabix-66 ~]# egrep -v "^#|^$" /etc/zabbix/zabbix_agentd.conf PidFile=/var/run/zabbix/zabbix_agentd.pid LogFile=/var/log/zabbix/zabbix_agentd.log LogFileSize=0 Server=192.168.56.66 ServerActive=192.168.56.66 Hostname=Zabbix server Include=/etc/zabbix/zabbix_agentd.d/*.conf ``` ### 2.3.3 启动zabbix-agent服务 ``` [root@zabix-66 ~]# systemctl start zabbix-agent [root@zabix-66 ~]# systemctl status zabbix-agent ``` ## 2.4 添加监控主机 ![](https://box.kancloud.cn/76765d4d7790551d0dba7a3b320cd2d7_590x236.png) ![](https://box.kancloud.cn/6f603bce833d2b9ac6ad53ee4699b861_575x381.png)   ## 2.5 修复乱码 查看客户端的图表时会显示中文字符乱码 ![](https://box.kancloud.cn/db476c1a0384c0039a1e631587a68b4d_330x251.png) 解决方法:安装字体并替换现有字体 ``` [root@zabix-66 ~]# yum install wqy-microhei-fonts -y [root@zabix-66 ~]# cp /usr/share/zabbix/fonts/graphfont.ttf{,.bak} [root@zabix-66 ~]# cp /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /usr/share/zabbix/fonts/graphfont.ttf cp:是否覆盖"/usr/share/zabbix/fonts/graphfont.ttf"? y [root@zabix-66 ~]# ``` 再次刷新页面发现已经是中文了 ![](https://box.kancloud.cn/61a61e93847916ddb5e56295d1b02067_329x246.png) ## 2.6 报错 客户端连接报错内容: ``` Received empty response from Zabbix Agent at [192.168.56.66]. Assuming that agent dropped connection because of access permissions ``` 查看客户端日志 ``` [root@zabix-66 ~]# tail -f /var/log/zabbix/zabbix_agentd.log 1614:20180201:004008.080 no active checks on server [127.0.0.1:10051]: host [Zabbix server] not monitored 1614:20180201:004208.161 no active checks on server [127.0.0.1:10051]: host [Zabbix server] not monitored 1614:20180201:004408.247 no active checks on server [127.0.0.1:10051]: host [Zabbix server] not monitored 1614:20180201:004608.333 no active checks on server [127.0.0.1:10051]: host [Zabbix server] not monitored ``` 解决方法: 这是因为配置文件里的HostName和本机不一致 ``` [root@zabix-66 ~]# egrep -v "^#|^$" /etc/zabbix/zabbix_agentd.conf PidFile=/var/run/zabbix/zabbix_agentd.pid LogFile=/var/log/zabbix/zabbix_agentd.log LogFileSize=0 Server=192.168.56.66 ServerActive=192.168.56.66 Hostname=Zabbix server Include=/etc/zabbix/zabbix_agentd.d/*.conf 本机Hostname [root@zabix-66 ~]# cat /etc/hostname zabix-66 ``` 修改后重启客户端 ``` [root@zabix-66 ~]# systemctl restart zabbix-agent.service [root@zabix-66 ~]# ```