1、zabbix 6.0后 版本后 对php版本至少7.2+
2、2G2核
3、zabbix-server服务端安装
# 1、nginx配置
[root@centos7 conf.d]# cat << EOF > /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/7/\$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
EOF
[root@centos7 conf.d]# yum install -y nginx
[root@centos7 conf.d]# vim /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name localhost; # 默认使用localhost(如果使用域名,修改在本地hosts解析)
root /app/zbx; # 需要创建好该目录,否则报错Not Found
location / {
index index.php;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
include fastcgi_params;
}
}
# 2、检查安装结果
rpm -qa |egrep 'nginx'
# 3、检查nginx配置
[root@centos7 conf.d]# nginx -t
# 1、php配置
[root@centos7 conf.d]# cat << EOF > /etc/yum.repos.d/php.repo
[php-webtatic]
name = PHP Repository
baseurl = http://us-east.repo.webtatic.com/yum/el7/x86_64/
gpgcheck = 0
EOF
[root@centos7 conf.d]# yum -y install php71w php71w-cli php71w-common php71w-devel php71w-embedded php71w-gd php71w-mcrypt php71w-mbstring php71w-pdo php71w-xml php71w-fpm php71w-mysqlnd php71w-opcache php71w-pecl-memcached php71w-pecl-redis php71w-pecl-mongodb
[root@centos7 ~]# sed -ri '/^(user|group)/s#apache#nginx#g' /etc/php-fpm.d/www.conf
[root@centos7 ~]# vim /etc/php.ini
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date.timezone = Asia/Shanghai
# 2、进行检查
[root@centos7 ~]# egrep '^(user|group)' /etc/php-fpm.d/www.conf
user = nginx
group = nginx
[root@centos7 ~]# rpm -qa |grep 'nginx|php'x
# 3、创建目录测试文件
[root@centos7 ~]# mkdir -p /app/zbx
[root@centos7 ~]# vim /app/zbx/info.php
<?php
phpinfo();
?>
# 4、启动nginx+php
[root@centos7 ~]# systemctl enable nginx php-fpm && systemctl start nginx php-fp
# 5、验证结果
# 1、mariadb配置
[root@centos7 ~]# vim /etc/yum.repos.d/mariadb.repo
[mariadb]
name = MariaDB
baseurl = https://mirrors.aliyun.com/mariadb/yum/10.5/centos7-amd64/
gpgkey=https://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1
enabled=1
[root@centos7 ~]# yum install -y mariadb-server
# 2、进行检查
[root@centos7 ~]# rpm -qa |grep -i mariadb
# 3、启动服务
[root@centos7 ~]# systemctl enable mariadb && systemctl start mariadb
# 4、查看
[root@centos7 ~]# netstat -lntp
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 1871/php- 854/rpcbind
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1874/nginx: master
tcp6 0 0 :::3306 :::* LISTEN 2181/mariadbd
# 5、基本配置
数据库初始化
mysql_secure_installation 仅1次。
Enter current password for root (enter for none): 回车
Switch to unix_socket authentication [Y/n] 输入n
Change the root password? [Y/n] 输入Y 设置root密码
Remove anonymous users? [Y/n] 输入Y
Disallow root login remotely? [Y/n] 输入Y
Remove test database and access to it? [Y/n] 输入Y
Reload privilege tables now? [Y/n] 输入Y
Thanks for using MariaDB! 表示完成
[root@centos7 ~]# mysql -uroot -p
1、创建数据库要指定字符集
create database zabbix charset utf8 collate utf8_bin;
2、创建zabbix用户
grant all on zabbix.* to 'zabbix'@'localhost' identified by 'zabbix' ;
#如果数据库与zbx,php不在一起
#grant all on zabbix.* to 'zabbix'@'172.16.1.%' identified by 'zabbix' ;
# 3、刷新配置
flush privileges;
zabbix官网 www.zabbix.com
# 1、安装包下载
[root@centos7 zabbix]# wget https://cdn.zabbix.com/zabbix/sources/stable/6.0/zabbix-6.0.0.tar.gz
# 2、创建zabbix用户
[root@centos7 zabbix]# useradd -M -s /sbin/nologin zabbix
# 3、下载依赖包(有些依赖是通过现在下载的包的依赖关系同步下载下来的)
[root@centos7 zabbix]# yum -y install libevent-devel net-snmp-devel libxml2-devel libcurl-devel gcc gcc-c++ make pcre pcre-devel openssl openssl-devel zlib zlib-devel
# 4、编译安装
[root@centos7 zabbix]# ./configure --prefix=/usr/local/zabbix --enable-server --enable-proxy --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2
按提示编译安装make install,或先make一下再make install都行,make install的过程中会自动make
# mkdir /usr/local/zabbix/log # 可以随便指定目录
# chown -R zabbix:zabbix /usr/local/zabbix/
# 5、修改配置文件
安装完成后,找到zabbix_server的配置文件,可查看./configure产生的配置列表或用find工具全局查找也行
修改其中一下内容
[root@centos7 zabbix]# vi /usr/local/zabbix/etc/zabbix_server.conf
LogFile=/usr/local/zabbix/log/zabbix_server.log #日志文件地址,目录没有需要创建并授权
DBHost=localhost #数据库地址
DBName=zabbix #数据库名
DBUser=zabbix #数据库用户名
DBPassword=123456 #数据库密码
DBSocket=/var/lib/mysql/mysql.sock #数据库sock文件路径
DBPort=3306 #数据库端口
Timeout=30
AlertScriptsPath=/usr/local/zabbix/alertscripts #告警脚本存放位置
ExternalScripts=/usr/local/zabbix/externalscripts #告警脚本存放位置
LogSlowQueries=3000
Include=/usr/local/zabbix/etc/zabbix_server.conf.d/*.conf #自定义监控配置文件
# 6、导入数据库
[root@centos7 ~]# cd /usr/share/doc/zabbix-server-mysql-6.*/
[root@centos7 zabbix-server-mysql-6.*]# zcat create.sql.gz | mysql -uroot -p'123456' zabbix
[root@centos7 ~]# ll
-rw-r--r-- 1 root root 21471836 11月 19 00:03 zabbix-6.0.0.tar (提前下载好,下载方式见下文)
drwxr-xr-x 13 1000 1000 4096 11月 2 16:54 zabbix-6.0.0
# 7、文件授权
[root@centos7 ~]# ll
-rw-r--r-- 1 root root 21471836 11月 19 00:03 zabbix-5.0.29.tar (提前下载好,下载方式见下文)
drwxr-xr-x 13 1000 1000 4096 11月 2 16:54 zabbix-5.0.29
[root@centos7 ~]# cp -r zabbix-6.0.0/ui/* /app/zbx/
[root@centos7 ~]# chown -R nginx: /app/zbx/
# 8、启动服务
[root@centos7 ~]#systemctl restart nginx php-fpm.service mariadb zabbix-server.service zabbix-agent.service
# 9、ip访问
192.168.15.9/zabbix 依次完成
默认用户 Admin 密码zabbix
# 1、安装
[root@centos7 ~]# rpm -Uvh https://mirrors.aliyun.com/zabbix/zabbix/6.0/rhel/7/x86_64/zabbix-release-6.0-1.el7.noarch.rpm?spm=a2c6h.25603864.0.0.33d67a109uoRvt
[root@centos7 ~]# sed -i 's#https://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo
[root@centos7 ~]# yum install zabbix-server-mysql zabbix-agent -y
[root@centos7 ~]# yum install centos-release-scl -y
[root@centos7 yum.repos.d]# yum install zabbix-web-mysql-scl zabbix-nginx-conf-scl
# 2、创建zabbix依赖数据库(因为提前创建了,可以忽略)
# 3、修改zabbix配置文件
[root@centos7 ~]# grep '^DBPa' /etc/zabbix/zabbix_server.conf
DBPassword=123456
DBHost=localhost
# 4、创建zabbix库(因为提前创建了,可以忽略)
# 5、导入数据库
[root@centos7 ~]# cd /usr/share/doc/zabbix-server-mysql-6.*/
[root@centos7 zabbix-server-mysql-6.*]# zcat create.sql.gz | mysql -uroot -p'123456' zabbix
[root@centos7 ~]# ll
-rw-r--r-- 1 root root 21471836 11月 19 00:03 zabbix-6.0.0.tar (提前下载好,下载方式见下文)
drwxr-xr-x 13 1000 1000 4096 11月 2 16:54 zabbix-6.0.0
[root@centos7 ~]# cp -r zabbix-5.0.29/ui/* /app/zbx/
[root@centos7 ~]# chown -R nginx: /app/zbx/
# 6、启动服务
[root@centos7 ~]#systemctl restart nginx php-fpm.service mariadb zabbix-server.service zabbix-agent.service
# 7、文件授权 (因为提前创建了,可以忽略)
# 8、ip访问
192.168.15.9/zabbix 依次完成
默认用户 Admin 密码zabbix
# 0、下载epel源
[root@centos7 ~]# yum install epel-release -y
# 1 、获取zabbix官方源
[root@centos7 ~]# rpm -Uvh https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
# 2、修改配置源文件
[root@centos7 ~]# sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo
[root@centos7 ~]# yum clean all && yum makecache
# 3、安装zabbix server和agent
[root@centos7 ~]# yum install zabbix-server-mysql zabbix-agent -y
# 4、安装software collections便于安装高版本的php (yum默认php是5.4)
[root@centos7 ~]# yum install centos-release-scl -y
# 5、修改zabbix前端源
[root@centos7 ~]# vim /etc/yum.repos.d/zabbix.repo
[zabbix-frontend]
name=Zabbix Official Repository frontend - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/$basearch/frontend
enabled=1 #修改为1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
# 6、安装zabbix前端环境
[root@centos7 ~]# yum install zabbix-web-mysql-scl zabbix-apache-conf-scl -y
# 7、创建zabbix依赖数据库(因为提前创建了,可以忽略)
[root@centos7 ~]# mysql -uroot -p
1、创建zabbix库及授权
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by '123456';
mysql> grant all privileges on zabbix.* to zabbix@'192.168.11.%' identified by '123456';
mysql> flush privileges;
mysql> exit
# 8、导入数据库
[root@centos7 ~]# cd /usr/share/doc/zabbix-server-mysql-5.*/
[root@centos7 zabbix-server-mysql-5.*]# zcat create.sql.gz | mysql -uroot -p'123456' zabbix
# 9、修改zabbix配置文件
1、修改zabbix.conf文件
[root@centos7 ~]# egrep '^DB' /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=123456
2、zabbix.conf完整操作
[root@centos7 ~]# egrep '^[a-Z]' /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
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=123456
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
3、文件授权
[root@centos7 ~]# ll
-rw-r--r-- 1 root root 21471836 11月 19 00:03 zabbix-5.0.29.tar (提前下载好,下载方式见下文)
drwxr-xr-x 13 1000 1000 4096 11月 2 16:54 zabbix-5.0.29
[root@centos7 ~]# cp -r zabbix-5.0.29/ui/* /app/zbx/
[root@centos7 ~]# chown -R nginx: /app/zbx/
# 10、启动服务
[root@centos7 ~]#systemctl restart nginx php-fpm.service mariadb zabbix-server.service zabbix-agent.service
# 11、ip访问
192.168.15.9/zabbix 依次完成
默认用户 Admin 密码zabbix
# 1、缺少依赖
[root@centos7 conf]# rpm -qa |grep php*
[root@centos7 conf]# yum -y install php72w-ldap
[root@centos7 conf]# yum install php72w-bcmath
# 2、修改php文件
[root@centos7 ~]# vim /etc/php.ini
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date.timezone = Asia/Shanghai
# 3、重新服务
[root@centos7 conf]# systemctl restart php-fpm.service
centos7 Minimum required PHP version is 7.2.0
# 1、开始升级PHP更新源
[root@centos7 conf]# rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
[root@centos7 conf]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
[root@centos7 conf]# yum remove php-common -y
[root@centos7 conf]# yum install -y php72w php72w-opcache php72w-xml php72w-mcrypt php72w-gd php72w-devel php72w-mysql php72w-intl php72w-mbstring
[root@centos7 conf]# yum install php72w-fpm
# 2、删除旧的依赖,重新安装php7.2的依赖
[root@centos7 conf]# rpm -e mod_php71w-7.1.33-1.w7.x86_64
[root@centos7 conf]# yum install -y php72w php72w-opcache php72w-xml php72w-mcrypt php72w-gd php72w-devel php72w-mysql php72w-intl php72w-mbstring php72w-fpm
# 3、查看版本:
[root@centos7 conf]# php -v
PHP 7.2.34 (cli) (built: Oct 1 2020 13:37:37) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.34, Copyright (c) 1999-2018, by Zend Technologies
# 4、启动php
[root@centos7 conf]# systemctl start php-fpm.service //启动php
# 1、修改配置
[root@centos7 zabbix]# cd /app/zbx/conf/
[root@centos7 conf]# ll
总用量 12
drwxr-xr-x 2 nginx nginx 6 11月 2 16:54 certs
-rw-r--r-- 1 nginx nginx 1036 10月 25 17:32 maintenance.inc.php
-rw-r--r-- 1 nginx nginx 1470 10月 28 14:42 zabbix.conf.php.example
[root@centos7 conf]# mv zabbix.conf.php.example zabbix.conf.php
[root@centos7 conf]# head zabbix.conf.php
<?php
// Zabbix GUI configuration file.
$DB['TYPE'] = 'MYSQL';
$DB['SERVER'] = 'localhost';
$DB['PORT'] = '3306';
$DB['DATABASE'] = 'zabbix';
$DB['USER'] = 'zabbix';
$DB['PASSWORD'] = '123456';
# 2、重新服务
[root@centos7 conf]# systemctl restart php-fpm.service
# 1、在数据库主机上运行以下代码。
[root@centos7 conf]# mysql -uroot -p
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> create user zabbix@localhost identified by 'password';
mysql> grant all privileges on zabbix.* to zabbix@localhost;
mysql> quit;
# 2、导入初始架构和数据,系统将提示您输入新创建的密码。
[root@centos7 conf]# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
# 3、Zabbix server配置数据库
[root@centos7 ~]# grep '^DBPa' /etc/zabbix/zabbix_server.conf
DBPassword=123456
# 4、启动服务
[root@centos7 conf]# systemctl restart zabbix-server zabbix-agent