#一台虚拟机
hostname:Zabbix-server
ip:server_ip_address
[root@Zabbix-server ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@Zabbix-server ~]# setenforce 0 && getenforce
Permissive
[root@Zabbix-server ~]# sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/sysconfig/selinux
[root@Zabbix-server ~]# cat /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# disabled - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of disabled.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# 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@Zabbix-server ~]# firewall-cmd --state && firewall-cmd --list-ports
running
80/tcp
# 假设zabbix-agent端口为10050
[root@Zabbix-server ~]# firewall-cmd --zone=public --permanent --add-port=10050/tcp && firewall-cmd --reload && firewall-cmd --list-ports
success
success
80/tcp 10050/tcp
#假设zabbix-server端口为10051
[root@Zabbix-server ~]# firewall-cmd --zone=public --permanent --add-port=10051/tcp && firewall-cmd --reload && firewall-cmd --list-ports
success
success
80/tcp 10051/tcp 10050/tcp
#假设httpd端口为8480
[root@Zabbix-server ~]# firewall-cmd --zone=public --permanent --add-port=8480/tcp && firewall-cmd --reload && firewall-cmd --list-ports
success
success
80/tcp 10051/tcp 8480/tcp 10050/tcp
[root@Zabbix-server tools]# rpm -qa|grep httpd
[root@Zabbix-server tools]# yum install -y httpd
[root@Zabbix-server tools]# rpm -qa|grep httpd
httpd-2.4.6-97.el7.centos.x86_64
httpd-tools-2.4.6-97.el7.centos.x86_64
[root@Zabbix-server tools]# systemctl enable httpd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@Zabbix-server tools]# cd /etc/httpd/conf
[root@Zabbix-server conf]# vi httpd.conf +42
[root@Zabbix-server conf]# grep 8480 httpd.conf
Listen 8480
[root@Zabbix-server conf]# systemctl start httpd && echo $?
0
[root@Zabbix-server conf]# systemctl status httpd.service
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since 二 2021-01-19 12:42:20 CST; 1min 43s ago
Docs: man:httpd(8)
man:apachectl(8)
Process: 125278 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=1/FAILURE)
Main PID: 125293 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup: /system.slice/httpd.service
├─125293 /usr/sbin/httpd -DFOREGROUND
├─125294 /usr/sbin/httpd -DFOREGROUND
├─125295 /usr/sbin/httpd -DFOREGROUND
├─125296 /usr/sbin/httpd -DFOREGROUND
├─125297 /usr/sbin/httpd -DFOREGROUND
└─125298 /usr/sbin/httpd -DFOREGROUND
1月 19 12:42:20 Zabbix-server systemd[1]: Starting The Apache HTTP Server...
1月 19 12:42:20 Zabbix-server httpd[125293]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, ...message
1月 19 12:42:20 Zabbix-server systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@Zabbix-server conf]# lsof -i:8480
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
httpd 125293 root 4u IPv6 6790155 0t0 TCP *:8480 (LISTEN)
httpd 125294 apache 4u IPv6 6790155 0t0 TCP *:8480 (LISTEN)
httpd 125295 apache 4u IPv6 6790155 0t0 TCP *:8480 (LISTEN)
httpd 125296 apache 4u IPv6 6790155 0t0 TCP *:8480 (LISTEN)
httpd 125297 apache 4u IPv6 6790155 0t0 TCP *:8480 (LISTEN)
httpd 125298 apache 4u IPv6 6790155 0t0 TCP *:8480 (LISTEN)
注意:因为7版本的mysql要收费,所以我们这里安装mariadb代替mysql
[root@Zabbix-server tools] rpm -qa|grep mariadb
[root@Zabbix-server tools]# yum install -y mariadb mariadb-server
[root@Zabbix-server tools]# rpm -qa|grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
mariadb-server-5.5.68-1.el7.x86_64
mariadb-5.5.68-1.el7.x86_64
[root@Zabbix-server tools]# systemctl enable mariadb.service
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@Zabbix-server ~]# systemctl start mariadb.service
[root@Zabbix-server ~]# systemctl status mariadb.service
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Active: active (running) since 二 2021-01-19 13:04:26 CST; 1h 21min ago
Main PID: 127665 (mysqld_safe)
CGroup: /system.slice/mariadb.service
├─127665 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
└─127830 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/l...
1月 19 13:04:24 Zabbix-server systemd[1]: Starting MariaDB database server...
1月 19 13:04:24 Zabbix-server mariadb-prepare-db-dir[127630]: Database MariaDB is probably initialized in /var/lib/mysql already, noth...done.
1月 19 13:04:24 Zabbix-server mariadb-prepare-db-dir[127630]: If this is not the case, make sure the /var/lib/mysql is empty before ru...-dir.
1月 19 13:04:24 Zabbix-server mysqld_safe[127665]: 210119 13:04:24 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
1月 19 13:04:24 Zabbix-server mysqld_safe[127665]: 210119 13:04:24 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
1月 19 13:04:26 Zabbix-server systemd[1]: Started MariaDB database server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@Zabbix-server ~]# lsof -i:3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 127830 mysql 14u IPv4 6797577 0t0 TCP *:mysql (LISTEN)
[root@Zabbix-server ~]# mysql #默认是没有密码的
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.60-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)]> select version();
+----------------+
| version() |
+----------------+
| 5.5.60-MariaDB |
+----------------+
1 row in set (0.00 sec)
MariaDB [(none)]> exit;
Bye
注意:要先输入当前密码,一般初次安装的默认密码为空
[root@Zabbix-server tools]# mysql_secure_installation
.
.
.
注意:zabbix-server也要监控自身,所以也要同时安装zabbix-agent
[root@Zabbix-server tools]# rpm -qa|grep zabbix
[root@Zabbix-server ~]# cd /home/tools/ && wget https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
[root@Zabbix-server tools]# ll zabbix-release-5.0-1.el7.noarch.rpm
-rw-r--r--. 1 root root 14532 5月 11 2020 zabbix-release-5.0-1.el7.noarch.rpm
[root@Zabbix-server tools]# ll /etc/yum.repos.d/
总用量 38
-rw-r--r--. 1 root root 1664 12月 9 2015 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 12月 9 2015 CentOS-CR.repo
-rw-r--r--. 1 root root 649 12月 9 2015 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 290 12月 9 2015 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 12月 9 2015 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 12月 9 2015 CentOS-Sources.repo
-rw-r--r--. 1 root root 1952 12月 9 2015 CentOS-Vault.repo
-rw-r--r--. 1 root root 951 10月 3 2017 epel.repo
-rw-r--r--. 1 root root 1050 10月 3 2017 epel-testing.repo
[root@Zabbix-server tools]# yum install -y zabbix-release-5.0-1.el7.noarch.rpm
[root@Zabbix-server tools]# rpm -qa|grep zabbix
zabbix-release-5.0-1.el7.noarch
[root@Zabbix-server tools]# ll /etc/yum.repos.d/
总用量 40
-rw-r--r--. 1 root root 1664 12月 9 2015 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 12月 9 2015 CentOS-CR.repo
-rw-r--r--. 1 root root 649 12月 9 2015 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 290 12月 9 2015 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 12月 9 2015 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 12月 9 2015 CentOS-Sources.repo
-rw-r--r--. 1 root root 1952 12月 9 2015 CentOS-Vault.repo
-rw-r--r--. 1 root root 951 10月 3 2017 epel.repo
-rw-r--r--. 1 root root 1050 10月 3 2017 epel-testing.repo
-rw-r--r--. 1 root root 853 5月 11 2020 zabbix.repo ###安装rpm包之后产生的###
[root@Zabbix-server tools]# sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo
[root@Zabbix-server tools]# yum install zabbix-server-mysql zabbix-agent -y
[root@Zabbix-server tools]# rpm -qa |grep zabbix
zabbix-server-mysql-5.0.7-1.el7.x86_64
zabbix-release-5.0-1.el7.noarch
zabbix-agent-5.0.7-1.el7.x86_64
注意: 安装 Software Collections是便于后续安装高版本的 php,默认 yum 安装的 php 版本为 5.4 过低。
[root@Zabbix-server tools]# rpm -qa |grep centos-release-scl
[root@Zabbix-server tools]# yum install centos-release-scl -y
[root@Zabbix-server tools]# rpm -qa |grep centos-release-scl
centos-release-scl-rh-2-3.el7.centos.noarch
centos-release-scl-2-3.el7.centos.noarch
[root@Zabbix-server tools]# ll /etc/yum.repos.d/
总用量 48
-rw-r--r--. 1 root root 1664 12月 9 2015 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 12月 9 2015 CentOS-CR.repo
-rw-r--r--. 1 root root 649 12月 9 2015 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 290 12月 9 2015 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 12月 9 2015 CentOS-Media.repo
-rw-r--r--. 1 root root 998 12月 11 2018 CentOS-SCLo-scl.repo ###新产生的###
-rw-r--r--. 1 root root 971 10月 29 2018 CentOS-SCLo-scl-rh.repo ###新产生的###
-rw-r--r--. 1 root root 1331 12月 9 2015 CentOS-Sources.repo
-rw-r--r--. 1 root root 1952 12月 9 2015 CentOS-Vault.repo
-rw-r--r--. 1 root root 951 10月 3 2017 epel.repo
-rw-r--r--. 1 root root 1050 10月 3 2017 epel-testing.repo
-rw-r--r--. 1 root root 897 1月 19 12:35 zabbix.repo
启用下载 zabbix 的前端源,将[zabbix-frontend]下的 enabled 改为 1
[root@Zabbix-server tools]# vi /etc/yum.repos.d/zabbix.repo
[root@Zabbix-server tools]# yum install zabbix-web-mysql-scl zabbix-apache-conf-scl -y
[root@Zabbix-server tools]# rpm -qa |grep zabbix
zabbix-release-5.0-1.el7.noarch
zabbix-agent-5.0.7-1.el7.x86_64
zabbix-web-mysql-scl-5.0.7-1.el7.noarch #####
zabbix-apache-conf-scl-5.0.7-1.el7.noarch #####
zabbix-server-mysql-5.0.7-1.el7.x86_64
zabbix-web-5.0.7-1.el7.noarch #####
zabbix-web-deps-scl-5.0.7-1.el7.noarch #####
执行上面的命令时rh-php72-php作为依赖被安装
[root@Zabbix-server tools]# rpm -qa |grep rh-php72-php
rh-php72-php-zip-7.2.24-1.el7.x86_64
rh-php72-php-process-7.2.24-1.el7.x86_64
rh-php72-php-mysqlnd-7.2.24-1.el7.x86_64
rh-php72-php-mbstring-7.2.24-1.el7.x86_64
rh-php72-php-xml-7.2.24-1.el7.x86_64
rh-php72-php-bcmath-7.2.24-1.el7.x86_64
rh-php72-php-json-7.2.24-1.el7.x86_64
rh-php72-php-cli-7.2.24-1.el7.x86_64
rh-php72-php-gd-7.2.24-1.el7.x86_64
rh-php72-php-fpm-7.2.24-1.el7.x86_64
rh-php72-php-pdo-7.2.24-1.el7.x86_64
rh-php72-php-ldap-7.2.24-1.el7.x86_64
rh-php72-php-common-7.2.24-1.el7.x86_64
rh-php72-php-pear-1.10.5-1.el7.noarch
[root@Zabbix-server zabbix]# systemctl enable rh-php72-php-fpm
[root@Zabbix-server zabbix]# systemctl enable zabbix-server.service
[root@Zabbix-server zabbix]# systemctl enable zabbix-agent.service
[root@Zabbix-server ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.68-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;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> create user zabbix@localhost identified by 'zabbix123456'; ##这里和后面配置文件设置密码保持一致##
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost;
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| ejucms |
| mysql |
| performance_schema |
| zabbix |
+--------------------+
[root@Zabbix-server ~]# rpm -qa |grep zabbix-server-mysql
zabbix-server-mysql-5.0.7-1.el7.x86_64
[root@Zabbix-server ~]# rpm -ql zabbix-server-mysql
/etc/logrotate.d/zabbix-server
/etc/zabbix/zabbix_server.conf
/usr/lib/systemd/system/zabbix-server.service
/usr/lib/tmpfiles.d/zabbix-server.conf
/usr/lib/zabbix/alertscripts
/usr/lib/zabbix/externalscripts
/usr/sbin/zabbix_server_mysql
/usr/share/doc/zabbix-server-mysql-5.0.7
/usr/share/doc/zabbix-server-mysql-5.0.7/AUTHORS
/usr/share/doc/zabbix-server-mysql-5.0.7/COPYING
/usr/share/doc/zabbix-server-mysql-5.0.7/ChangeLog
/usr/share/doc/zabbix-server-mysql-5.0.7/NEWS
/usr/share/doc/zabbix-server-mysql-5.0.7/README
/usr/share/doc/zabbix-server-mysql-5.0.7/create.sql.gz #######
/usr/share/doc/zabbix-server-mysql-5.0.7/double.sql
/usr/share/man/man8/zabbix_server.8.gz
/var/log/zabbix
/var/run/zabbix
[root@Zabbix-server ~]# cd /usr/share/doc/zabbix-server-mysql-5.0.7/
[root@Zabbix-server zabbix-server-mysql-5.0.7]# ll
总用量 2784
-rw-r--r--. 1 root root 98 12月 14 18:27 AUTHORS
-rw-r--r--. 1 root root 1165388 12月 21 17:38 ChangeLog
-rw-r--r--. 1 root root 17990 12月 14 18:27 COPYING
-rw-r--r--. 1 root root 1644549 12月 21 18:24 create.sql.gz ###也可以先使用gunzip命令解压再导入###
-rw-r--r--. 1 root root 282 12月 14 18:27 double.sql
-rw-r--r--. 1 root root 52 12月 14 18:27 NEWS
-rw-r--r--. 1 root root 1317 12月 14 18:27 README
[root@Zabbix-server zabbix-server-mysql-5.0.7]# zcat /usr/share/doc/zabbix-server-mysql-5.0.7/create.sql.gz | mysql -uzabbix -p zabbix
Enter password:
[root@Zabbix-server zabbix-server-mysql-5.0.7]# echo $?
0
[root@Zabbix-server zabbix-server-mysql-5.0.7]# cd /etc/zabbix/
[root@Zabbix-server zabbix]# ll
总用量 40
drwxr-xr-x. 2 apache apache 32 1月 19 12:40 web
-rw-r--r--. 1 root root 15101 12月 21 18:27 zabbix_agentd.conf
drwxr-xr-x. 2 root root 6 12月 21 18:27 zabbix_agentd.d
-rw-r-----. 1 root zabbix 21531 12月 21 18:27 zabbix_server.conf
配置文件修改前:
[root@Zabbix-server zabbix]# egrep -v "^$|^#" 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
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
配置文件修改后:
和主机连接91行(取消注释)
[root@Zabbix-server zabbix]# egrep -v "^$|^#" zabbix_server.conf
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
SocketDir=/var/run/zabbix
DBHost=localhost ###主机连接地址 第91行###
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix123456 ### 设置数据库密码 第124行###
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
[root@Zabbix-server zabbix]# vi /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
#最后一行添加以下内容修改时区
php_value[date.timezone] = Asia/Shanghai
[root@Zabbix-server zabbix]# systemctl restart mariadb.service
[root@Zabbix-server zabbix]# systemctl restart httpd
[root@Zabbix-server zabbix]# systemctl restart rh-php72-php-fpm
[root@Zabbix-server zabbix]# systemctl restart zabbix-server.service
[root@Zabbix-server zabbix]# systemctl restart zabbix-agent.service
[root@Zabbix-server tools]# netstat -lntup
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:22 0.0.0.0:* LISTEN 1461/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1693/master
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 128031/zabbix_agent
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 128039/zabbix_serve
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 128029/php-fpm: mas
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 127830/mysqld
tcp 0 0 0.0.0.0:8480 0.0.0.0:* LISTEN 21789/nginx: master
tcp6 0 0 :::22 :::* LISTEN 1461/sshd