$ yum -y install wget vim tree lrzsz epel-release bash-completion ntpdate ntp
$ setenforce 0 #此为临时生效,建议编辑 /etc/selinux/config ,将SELINUX的值改为disabled
$ systemctl stop firewalld
$ systemctl disable firewalld
$ ntpdate cn.ntp.org.cn
1.准备zabbix用户
[root@mu-node1 src]# groupadd -r zabbix
[root@mu-node1 src]# useradd -r -g zabbix -s /sbin/nologin -d /usr/local/zabbix zabbix
[root@mu-node1 src]# id zabbix
uid=997(zabbix) gid=995(zabbix) 组=995(zabbix)
[root@mu-node1 src]# cat /etc/passwd | grep zabbix
zabbix:x:997:995::/usr/local/zabbix:/sbin/nologin
如果Zabbix server 和 agent 运行在同一台计算机上,建议使用不同的账户运行Server和Agent。否则,如果两个进程使用了同一个用户,Agent就可以访问Server的配置文件,并可轻易地读取Zabbix中任何管理员级别的用户,比如数据库密码。同时,应避免使用诸如root,bin或其他特殊权限的用户运行Zabbix,因为会存在潜在的安全风险。 ——Zabbix官方建议
2.下载源码包
[root@mu-node1 ~]# cd /usr/src/
[root@mu-node1 src]# wget -O /usr/src/zabbix-4.2.0.tar.gz https://ayera.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.2.0/zabbix-4.2.0.tar.gz
[root@mu-node1 src]# tar xf zabbix-4.2.0.tar.gz
3.准备数据库环境
[root@mu-node1 src]# yum install mariadb-server -y
[root@mu-node1 src]# systemctl enable mariadb
[root@mu-node1 src]# systemctl start mariadb
[root@mu-node1 src]# mysql_secure_installation
[root@mu-node1 src]# mysql -uroot -hlocalhost -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
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)]> create database zabbix character set utf8; #暂不直接支持utf8mb4字符集,若需使用,需手动修改官方SQL初始化脚本中的字段长度
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by 'guomai';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges ;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> exit
Bye
4.初始化数据库
[root@mu-node1 src]# cd zabbix-4.2.0/database/mysql/
[root@mu-node1 mysql]# mysql -hlocalhost -uzabbix -p zabbix < schema.sql
Enter password:
[root@mu-node1 mysql]# mysql -hlocalhost -uzabbix -p zabbix < images.sql
Enter password:
[root@mu-node1 mysql]# mysql -hlocalhost -uzabbix -p zabbix < data.sql
Enter password:
[root@mu-node1 mysql]#
1.准备编译环境
[root@mu-node1 mysql]# cd ../../
[root@mu-node1 zabbix-4.2.0]# yum -y install openssl-devel pcre-devel make gcc net-snmp-devel mysql-devel curl-devel libxml2-devel libevent-devel
[root@mu-node1 zabbix-4.2.0]# ./configure --help | less #获取编译帮助
[root@mu-node1 zabbix-4.2.0]# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --with-openssl
Java Gateway
支持,你必须先进行如下操作,然后才添加--enable-java
这一编译选项,否则将出现形如checking for javac... no...configure: error: Unable to find "javac" executable in path
的报错信息#添加Java支持
[root@mu-node1 zabbix-4.2.0]# cd /usr/src/
[root@mu-node1 src]# wget http://192.168.20.55/packages/java/jdk-8u131-linux-x64.rpm
[root@mu-node1 src]# rpm -ivh jdk-8u131-linux-x64.rpm
[root@mu-node1 src]# cat >> /etc/profile
JAVA_HOME=/usr/java/jdk1.8.0_131
JRE_HOME=/usr/java/jdk1.8.0_131/jre
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
CLASSPATH=:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
export JAVA_HOME JRE_HOME PATH CLASSPATH
[root@mu-node1 src]# source /etc/profile
[root@mu-node1 src]# java -version #此处能正常显示Java版本信息即说明添加Java环境成功
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
[root@mu-node1 src]# cd zabbix-4.2.0/
[root@mu-node1 zabbix-4.2.0]# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --enable-java --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --with-openssl
[root@mu-node1 zabbix-4.2.0]# make install
2.查看Zabbix
组件结构
[root@mu-node1 zabbix-4.2.0]# cd /usr/local/zabbix/
[root@mu-node1 zabbix]# tree
.
├── bin
│ ├── zabbix_get
│ └── zabbix_sender
├── etc
│ ├── zabbix_agentd.conf
│ ├── zabbix_agentd.conf.d
│ ├── zabbix_server.conf
│ └── zabbix_server.conf.d
├── lib
│ └── modules
├── sbin
│ ├── zabbix_agentd
│ ├── zabbix_java
│ │ ├── bin
│ │ │ └── zabbix-java-gateway-4.2.0.jar
│ │ ├── lib
│ │ │ ├── android-json-4.3_r3.1.jar
│ │ │ ├── logback-classic-0.9.27.jar
│ │ │ ├── logback-console.xml
│ │ │ ├── logback-core-0.9.27.jar
│ │ │ ├── logback.xml
│ │ │ └── slf4j-api-1.6.1.jar
│ │ ├── settings.sh
│ │ ├── shutdown.sh
│ │ └── startup.sh
│ └── zabbix_server
└── share
├── man
│ ├── man1
│ │ ├── zabbix_get.1
│ │ └── zabbix_sender.1
│ └── man8
│ ├── zabbix_agentd.8
│ └── zabbix_server.8
└── zabbix
├── alertscripts
└── externalscripts
17 directories, 20 files
3.添加环境变量
[root@mu-node1 zabbix]# echo "export PATH=/usr/local/zabbix/sbin:$PATH" >> /etc/profile.d/zabbix.sh
[root@mu-node1 zabbix]# source /etc/profile.d/zabbix.sh
[root@mu-node1 zabbix]# echo $PATH
/usr/local/zabbix/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/java/jdk1.8.0_131/bin:/usr/java/jdk1.8.0_131/jre/bin
4.设定开机自启
[root@mu-node1 zabbix]# echo "/usr/local/zabbix/sbin/zabbix_server" >> /etc/rc.d/rc.local
[root@mu-node1 zabbix]# echo "/usr/local/zabbix/sbin/zabbix_agentd" >> /etc/rc.d/rc.local
[root@mu-node1 zabbix]# chmod +x /etc/rc.d/rc.local #仅Centos 7.x需额外授予此执行权限
5.编辑Zabbix Server
主配置文件
[root@mu-node1 zabbix]# vim etc/zabbix_server.conf
# DBHost=localhost db服务器ip,本示例为本机,故localhost即可(注:需事先在Mariadb/MySQL中授权)
DBName=zabbix #库名,默认zabbix
DBUser=zabbix #账户名,默认zabbix
DBPassword=guomai #数据库密码,需自行配置
DBPort=3306 #服务端口,默认3306
[root@mu-node1 zabbix]# yum -y install php-fpm
[root@mu-node1 zabbix]# yum install -y nginx
[root@mu-node1 zabbix]# cp -r /usr/src/zabbix-4.2.0/frontends/php/ /usr/share/nginx/html/zabbix
[root@mu-node1 zabbix]# systemctl enable nginx
[root@mu-node1 zabbix]# systemctl start nginx
[root@mu-node1 zabbix]# systemctl start php-fpm
[root@mu-node1 zabbix]# vim /etc/nginx/nginx.conf
location / {
root /usr/share/nginx/html;
index index.html index.htm index.php;
}
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
[root@mu-node1 zabbix]# vim /etc/php-fpm.d/www.conf
#修改PHP-FPM执行用户
user = nginx
group = nginx
#修改站点根目录权限
[root@mu-node1 zabbix]# chown -R nginx:nginx /usr/share/nginx/html/zabbix
[root@mu-node1 zabbix]# systemctl restart php-fpm nginx
[root@mu-node1 zabbix]# zabbix_server
[root@mu-node1 zabbix]# zabbix_agentd
http://Your_Zabbix_Server_IP/zabbix/setup.php