一、安装环境准备
1、系统环境:
cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
关闭防火墙及selinux
[root@zabbix ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root@zabbix ~]# systemctl stop firewalld.service
[root@zabbix ~]# systemctl disable firewalld.service
[root@zabbix ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
[root@zabbix ~]# grep SELINUX=disabled /etc/selinux/config
SELINUX=disabled
[root@zabbix ~]# setenforce 0
setenforce: SELinux is disabled
二、安装Nginx
1、下载Nginx
[root@zabbix ~]# mkdir /data/tools
[root@zabbix ~]# cd /data/tools/
[root@zabbix tools]# wget http://nginx.org/download/nginx-1.12.0.tar.gz
[root@zabbix tools]# ls
nginx-1.12.0.tar.gz
2、创建Nginx用户
[root@zabbix tools]# groupadd nginx
[root@zabbix tools]# useradd -s /sbin/nologin -g nginx -M nginx
3、安装依赖
[root@zabbix tools]# yum install gc gcc gcc-c++ pcre-devel zlib-devel openssl-devel -y
4、解压
[root@zabbix tools]# tar -zxf nginx-1.12.0.tar.gz
[root@zabbix tools]# cd nginx-1.12.0/
5、编译
[root@zabbix nginx-1.12.0]# ./configure --prefix=/data/app/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-file-aio --with-http_dav_module --with-stream --with-stream_ssl_module --with-stream_ssl_module --with-pcre --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module
[root@zabbix nginx-1.12.0]# make && make install
6、启动Nginx
[root@zabbix ~]# /data/app/nginx/sbin/nginx
三、安装mariadb
1、因为编译安装耗时太长,这里就yum安装。
[root@zabbix ~]# yum install mariadb-server mariadb -y
[root@zabbix ~]# systemctl enable mariadb
[root@zabbix ~]# systemctl start mariadb
[root@zabbix ~]# mysql -uroot -p
Enter password:
因为安装好mariadb后root用户是没有密码的,所以直接回车不用密码就可以直接进入。
2、设置root密码
MariaDB [(none)]> UPDATE mysql.user SET password=password('newpassword') WHERE user='root';
MariaDB [(none)]> flush privileges;
四、安装php
1、添加epel源
[root@zabbix ~]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
[root@zabbix ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
2、安装php
[root@zabbix ~]# yum list | grep php72w
[root@zabbix ~]# yum -y install php72w-cli.x86_64 php72w-mysql.x86_64 php72w-odbc.x86_64 php72w-pear.noarch php72w-fpm.x86_64 php72w-ldap.x86_64 php72w-xml.x86_64 php72w-xmlrpc.x86_64
五、安装zabbix-server
1、安装依赖、组件
[root@zabbix ~]# 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*
2、安装
[root@zabbix ~]# rpm -Uvh https://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
[root@zabbix ~]# yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent -y
安装可能会报错说找不到,需要将zabbix的repo库地址更换为aliyun的。
[root@zabbix ~]# sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#g' /etc/yum.repos.d/zabbix.repo
3、创建数据库
[root@zabbix ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 5.5.64-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)]> grant all privileges on zabbix.* to zabbix@localhost 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)]>
4、导入数据
[root@zabbix zabbix-server-mysql-3.4.15]# zcat /usr/share/doc/zabbix-server-mysql-3.4.15/create.sql.gz | mysql -uzabbix -pzabbix zabbix
5、修改zabbix配置文件
[root@zabbix zabbix-server-mysql-3.4.15]# 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
6、启动zabbix
[root@zabbix ~]# systemctl enable zabbix-server.service
[root@zabbix ~]# systemctl start zabbix-server.service
六、配置Nginx作为zabbix的web服务器
1、编写zabbix的配置文件(yum安装的话zabbix的前段文件默认存放在“/usr/share/zabbix/”下)
[root@zabbix zabbix]# vim /data/app/nginx/conf/vhosts/zabbix.conf
server {
listen 80;
server_name 120.53.13.240;
location / {
root /usr/share/zabbix;
index index.php index.html index.htm;
}
location ~ \.php$ {
root /usr/share/zabbix;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/zabbix$fastcgi_script_name;
include fastcgi_params;
}
}
[root@zabbix zabbix]# /data/app/nginx/sbin/nginx -t
nginx: the configuration file /data/app/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /data/app/nginx/conf/nginx.conf test is successful
[root@zabbix zabbix]# /data/app/nginx/sbin/nginx -s reload
[root@zabbix zabbix]# systemctl stop php-fpm.service
[root@zabbix zabbix]# systemctl start php-fpm.service
2、web访问(下一步后可能会有报错,根据报错修改php.ini的值即可)
3、配置mysql
4、配置zabbix-server
5、确认信息
6、安装成功
完成后会生成“/etc/zabbix/web/zabbix.conf.php”,里面有DB和zabbix_server的信息。
7、默认账户和密码为Admin、zabbix
8、汉化
到这里zabbix3.4.15就安装完成了。