CentOS7搭建企业级Zabbix监控(Server端)

一、环境说明

  1. Linux环境
    zabbix安装要求:
    https://www.zabbix.com/documentation/4.0/zh/manual/installation/requirements
[root@localhost ~]# cat /etc/redhat-release        查看系统版本信息
CentOS Linux release 7.4.1708 (Core) 
[root@localhost ~]# systemctl stop firewalld.service       关闭防火墙
[root@localhost ~]# systemctl disable firewalld.service             开机禁止启动防火墙
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# cat /etc/selinux/config       查看selinux配置

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=enforcing           #selinux开启状态
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 


[root@localhost ~]# setenforce 0        临时关闭selinux
[root@localhost ~]# getenforce       检查selinux是否关闭
Permissive   
  1. 搭建LAMP环境
    Zabbix是建立在LAMP或者LNMP环境之上,在此为了方便就使用yum安装LAMP环境
[root@localhost ~]# yum -y install httpd mariadb-server mariadb php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mhash
[root@localhost ~]# rpm -qa httpd php mariadb     安装后查看应用版本
httpd-2.4.6-93.el7.centos.x86_64
php-5.4.16-48.el7.x86_64
mariadb-5.5.65-1.el7.x86_64
  1. 编辑httpd
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
95 ServerName 192.168.88.140:80    修改主机名,URL
164     DirectoryIndex index.html index.php       修改首页文件格式

  1. 编辑配置PHP,将配置信息配置中国时区
[root@localhost ~]# vim /etc/php.ini
 878 ;date.timezone = PRC
  1. 启动mysqld
[root@localhost ~]# systemctl start mariadb      启动mariadb数据库
[root@localhost ~]# systemctl enable mariadb     开机自启mariadb数据库
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@localhost ~]# systemctl status mariadb     查看mariadb状态
● mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2020-06-04 19:45:17 PDT; 25s ago
 Main PID: 35105 (mysqld_safe)
   CGroup: /system.slice/mariadb.service
           ├─35105 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
           └─35267 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysq...

Jun 04 19:45:14 localhost.localdomain mariadb-prepare-db-dir[35020]: MySQL ma...
Jun 04 19:45:14 localhost.localdomain mariadb-prepare-db-dir[35020]: Please r...
Jun 04 19:45:14 localhost.localdomain mariadb-prepare-db-dir[35020]: The late...
Jun 04 19:45:14 localhost.localdomain mariadb-prepare-db-dir[35020]: You can ...
Jun 04 19:45:14 localhost.localdomain mariadb-prepare-db-dir[35020]: http://d...
Jun 04 19:45:14 localhost.localdomain mariadb-prepare-db-dir[35020]: Consider...
Jun 04 19:45:14 localhost.localdomain mariadb-prepare-db-dir[35020]: https://...
Jun 04 19:45:15 localhost.localdomain mysqld_safe[35105]: 200604 19:45:15 mys...
Jun 04 19:45:15 localhost.localdomain mysqld_safe[35105]: 200604 19:45:15 mys...
Jun 04 19:45:17 localhost.localdomain systemd[1]: Started MariaDB database se...
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]# netstat -lntup | grep mysqld      查看服务端口是否存在
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      35267/mysqld  
  1. 初始化数据库,并设置root用户密码
[root@localhost ~]# mysqladmin -u root password liuyong    设置数据库密码
[root@localhost ~]# mysql -uroot -p    登录数据可
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.65-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> CREATE DATABASE zabbix character set utf8 collate utf8_bin;     创建zabbix数据库
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> GRANT all ON zabbix.* TO 'zabbix'@'%' IDENTIFIED BY 'zabbix';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;     刷新权限
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> select user,host from mysql.user;
+--------+-----------------------+
| user   | host                  |
+--------+-----------------------+
| zabbix | %                     |
| root   | 127.0.0.1             |
| root   | ::1                   |
|        | localhost             |
| root   | localhost             |
|        | localhost.localdomain |
| root   | localhost.localdomain |
+--------+-----------------------+
7 rows in set (0.00 sec)

MariaDB [(none)]> drop user ''@localhost;      删除空用户
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> select user,host from mysql.user;
+--------+-----------------------+
| user   | host                  |
+--------+-----------------------+
| zabbix | %                     |
| root   | 127.0.0.1             |
| root   | ::1                   |
| root   | localhost             |
|        | localhost.localdomain |
| root   | localhost.localdomain |
+--------+-----------------------+
6 rows in set (0.00 sec)

MariaDB [(none)]>  exit

二、安装zabbix
安装依赖包+组件

[root@localhost ~]# yum -y install net-snmp net-snmp-devel curl curl-devel libxml2 libxml2-devel libevent-devel.x86_64 javacc.noarch javacc-javadoc.noarch javacc-maven-plugin.noarch javacc*
[root@localhost ~]# yum -y install php-bcmath php-mbstring     安装php支持zabbix组件
[root@localhost ~]# rpm -ivh http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm   安装zabbix(通过yum源安装)
[root@localhost ~]# yum -y install zabbix-server-mysql zabbix-web-mysql    安装zabbix组件
[root@localhost ~]# zcat /usr/share/doc/zabbix-server-mysql-4.0.21/create.sql.gz | mysql -uzabbix -p -h 192.168.88.140 zabbix
Enter password:           这里输入zabbix数据库密码:zabbix
[root@localhost ~]# 

Enter password: #导入数据到数据库zabbix中(最后一个zabbix是数据库zabbix),且因为用户zabbix是%(任意主机),所以登录时需要加上当前主机ip(-h 192.168.88.140)密码是用户zabbix登陆密码zabbix

[root@localhost ~]# vim /etc/zabbix/zabbix_server.conf
 38 LogFile=/var/log/zabbix/zabbix_server.log
 49 LogFileSize=0
 72 PidFile=/var/run/zabbix/zabbix_server.pid
 82 SocketDir=/var/run/zabbix
 100 DBName=zabbix 
 116 DBUser=zabbix
 124   DBPassword= zabbix      把注释打开写zabbix库的密码
 356 SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
 473 Timeout=4
 516 AlertScriptsPath=/usr/lib/zabbix/alertscripts
 527 ExternalScripts=/usr/lib/zabbix/externalscripts
 563 LogSlowQueries=3000

修改zabbix时区

[root@localhost ~]# vim /etc/httpd/conf.d/zabbix.conf
#
# Zabbix monitoring system php web frontend
#

Alias /zabbix /usr/share/zabbix

<Directory "/usr/share/zabbix">
    Options FollowSymLinks
    AllowOverride None
    Require all granted

    <IfModule mod_php5.c>
        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 always_populate_raw_post_data -1
        php_value date.timezone Asia/Shanghai        修改为上海时区
    </IfModule>
</Directory>
[root@localhost ~]# systemctl enable zabbix-server      将zabbix服务加入开机自启动
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service.
[root@localhost ~]# systemctl start zabbix-server 
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl enable httpd       启动httpd服务并加入开机自启动
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

通过浏览器访问 http://192.168.88.140/zabbix
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
这里Username:Admin password:zabbix
在这里插入图片描述

在这里插入图片描述
zabbix网站页面进行汉化
在这里插入图片描述
在这里插入图片描述
到这里有可能汉化后中文会乱码,这里可以进行字体更换解决:

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
把这个字体文件传至部署zabbix的CentOS中:/usr/share/zabbix/assets/fonts
在这里插入图片描述
修改配置文件字体名称

[root@localhost fonts]# vim /usr/share/zabbix/include/defines.inc.php
  72 define('ZBX_GRAPH_FONT_NAME',           'simhei'); // font file name
  113 define('ZBX_FONT_NAME', 'simhei');

在这里插入图片描述
在这里插入图片描述
这样就可以显示中文字体了

安装zbbix-agent客户端

[root@localhost ~]# yum -y install zabbix-agent
[root@localhost ~]# vim /etc/zabbix/zabbix_agentd.conf
[root@localhost ~]# grep -n '^'[a-Z] /etc/zabbix/zabbix_agentd.conf
 13 PidFile=/var/run/zabbix/zabbix_agentd.pid
 32 LogFile=/var/log/zabbix/zabbix_agentd.log
 43 LogFileSize=0
 98 Server=192.168.88.140 
 139 ServerActive=127.0.0.1
 150 Hostname=Zabbix server
 268 Include=/etc/zabbix/zabbix_agentd.d/*.conf    
 [root@localhost ~]# systemctl start zabbix-agent.service      启动客户端
 [root@localhost ~]# systemctl enable zabbix-agent.service      开机启动zabbix客户端
 Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值