centos7 zabbix5 nginx 安装

张映 发表于 2020-12-09

分类目录: 服务器相关

标签:, ,

关于服务器监控的文章写过很多了,例如:nagios,munin,cacti等,有兴趣的在博客里面搜索一下。

一,zabbix服务端安装

1,zabbix是什么

zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。
zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。

2,关闭selinux和防火墙

# systemctl stop firewalld      //停止
# systemctl disable firewalld   //关闭自启动
# iptables -L //查看
# sed -i s/SELINUX=enforcing/SELINUX=disabled/g /etc/selinux/config //关闭selinux,最好重启下

3,安装源

# yum install epel-release
# yum install centos-release-scl

centos-release-scl这个源可以装php72,根zabbix有依赖关系,不建议其他的源装php,如果不用就会报以下错误

--> 解决依赖关系完成
错误:软件包:zabbix-web-mysql-scl-5.0.6-1.el7.noarch (zabbix-frontend)
需要:rh-php72-php-mysqlnd

4,安装mysql

# wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
# rpm -ivh mysql57-community-release-el7-11.noarch.rpm
# yum install mysql-community-server mysql mysql-community-devel
# systemctl start mysqld && systemctl enable mysqld

# grep 'temporary password' /var/log/mysqld.log
2020-12-07T05:55:40.116097Z 1 [Note] A temporary password is generated for root@localhost: r:d+TA2tWG6g 

# mysql -u root -p
mysql> alter user 'root'@'localhost' identified by '*******';

在这里要注意,centos7默认安装的是mariadb的。如果已经装了mariadb,删除掉yum remove mariadb mariadb-libs

5,安装zabbix5

# wget https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
# rpm -ivh zabbix-release-5.0-1.el7.noarch.rpm

# vim /etc/yum.repos.d/zabbix.repo
[zabbix-frontend]
name=Zabbix Official Repository frontend - $basearch
baseurl=http://repo.zabbix.com/zabbix/5.0/rhel/7/$basearch/frontend
enabled=1 //0改成1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591

# yum clean all
# yum makecache 

# yum install zabbix-server-mysql zabbix-agent2 zabbix-web-mysql-scl zabbix-nginx-conf-scl //安装

在这里要注意,zabbix5.2和zabbix5.1已经出了,但是有很多包没有,或者是beta版,alpha版的。所有选择了zabbix5.0

6,创建zabbix用户,数据库,导入数据

# mysql -u root -p
mysql> grant all privileges on zabbix.* to zabbix@"10.0.%" identified by 'xxxxxxxxx';
mysql> flush privileges;
mysql> create database zabbix character set utf8 collate utf8_bin;
# gzip /usr/share/doc/zabbix-server-mysql*/create.sql.gz -d /root

# mysql -u root -p
mysql> use zabbix
mysql> set names utf8;
mysql> source /root/create.sql;
mysql> source /root/double.sql;
mysql> show tables;

.............省略...............
| usrgrp |
| valuemaps |
| widget |
| widget_field |
+----------------------------+
166 rows in set (0.00 sec) //166张表

7,配置nginx和php

# vim /etc/opt/rh/rh-nginx116/nginx/conf.d/zabbix.conf
server {
 listen 80; //去掉前面注释
 server_name 10.0.10.11; //去掉前面注释

# vim /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
[zabbix]
user = apache
group = apache

listen = /var/opt/rh/rh-php72/run/php-fpm/zabbix.sock
listen.acl_users = apache,nginx //修改
listen.allowed_clients = 127.0.0.1

pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35

php_value[session.save_handler] = files
php_value[session.save_path] = /var/opt/rh/rh-php72/lib/php/session/

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[max_input_vars] = 10000
php_value[date.timezone] = Asia/Shanghai //去掉前面的注释,改时区

# egrep -v "(^#|^$)" /etc/zabbix/zabbix_server.conf  //zabbix server 配置
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=***********
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

# systemctl restart zabbix-server zabbix-agent2 rh-nginx116-nginx rh-php72-php-fpm
# systemctl enable zabbix-server zabbix-agent2 rh-nginx116-nginx rh-php72-php-fpm

# netstat  -tpnl  //检查端口,是不是启动了
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      21615/nginx: master
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1105/sshd
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1677/master
tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN      100512/zabbix_serve
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      22144/php-fpm: mast
tcp6       0      0 :::80                   :::*                    LISTEN      21615/nginx: master
tcp6       0      0 :::22                   :::*                    LISTEN      1105/sshd
tcp6       0      0 ::1:25                  :::*                    LISTEN      1677/master
tcp6       0      0 :::10050                :::*                    LISTEN      100482/zabbix_agent
tcp6       0      0 :::10051                :::*                    LISTEN      100512/zabbix_serve
tcp6       0      0 :::3306                 :::*                    LISTEN      76536/mysqld

8,界面安装zabbix,http://服务器IP,一路安装就好,安装好了后,默认管理员账号密码为 Admin/zabbix

以上操作都是在zabbix sever端操作的,虽然服务端装了zabbix agent2,但是没有配置,也是可以监控的,zabbix sever上面的agent用127.0.0.1,切换成中文

zabbix中文设置

zabbix中文设置

二,客户端安装

1,关闭防火墙和selinux

# systemctl stop firewalld      //停止
# systemctl disable firewalld   //关闭自启动
# iptables -L //查看
# sed -i s/SELINUX=enforcing/SELINUX=disabled/g /etc/selinux/config //关闭selinux,最好重启下

2,安装zabbix-agent2

# rpm -ivh zabbix-release-5.0-1.el7.noarch.rpm
# yum install zabbix-agent2 zabbix-get -y

推荐大家使用zabbix-agent2,多了不少模板,配置也简单些。

3,配置zabbix-agent2

# /etc/zabbix/zabbix_agent2.conf //修改以下内容
Server=10.0.10.11 //zabbix服务端内网IP
ServerActive=10.0.10.11 //zabbix服务端内网IP,Active表示agent主动推送
Hostname=tidb1 //zabbix客户端主机名称

# systemctl start zabbix-agent2
# systemctl enable zabbix-agent2

# netstat -tpnl |grep zabbix
tcp6 0 0 :::10050 :::* LISTEN 4250/zabbix_agent2

三,zabbix管理后台,添加主机

zabbix添加主机

zabbix添加主机

选择模板

选择模板

最新数据

最新数据

zabbix添加成功

zabbix添加成功

最新数据,只要有内容,就说明客户端添加成功了

四,图表乱码

zabbix乱码

zabbix乱码

1,下载字体,支持中文就行

2,将字段copy到/usr/share/zabbix/assets/fonts

3,修改配置文件

# ll /usr/share/zabbix/assets/fonts
总用量 2332
lrwxrwxrwx 1 root root 33 12月 7 13:56 graphfont.ttf -> /etc/alternatives/zabbix-web-font
-rwxr-xr-x 1 root root 2386140 12月 7 16:38 simfang.ttf

# vim /usr/share/zabbix/include/defines.inc.php
define('ZBX_FONTPATH', realpath('assets/fonts')); // 字体路径,默认
define('ZBX_GRAPH_FONT_NAME', 'simfang'); // 将graphfont改成simfang


转载请注明
作者:海底苍鹰
地址:http://blog.51yip.com/server/2424.html

留下评论

留下评论
  • (必需)
  • (必需) (will not be published)
  • (必需)   1X2=?