CentOS7.X系统部署Zabbix6.0版本(可跟做)
CentOS 7.X 系统默认不支持Yum方式安装Zabbix 6.0 服务端(CentOS 8.X支持),所以服务端采用编译安装方式!注意:数据库使用MariaDB和MySQL都是可以的,如果有现成的数据库也可以直接拿来用,本篇文章使用MariaDB进行演示。2、创建用户,用来启动zabbix(zabbix禁止使用root用户启动)访问地址:http://IP:9780/index.php。2、
文章目录
一、部署环境说明
操作系统:CentOS 7.X
CentOS 7.X 系统默认不支持Yum方式安装Zabbix 6.0 服务端(CentOS 8.X支持),所以服务端采用编译安装方式!
部署组件:
序号 | 组件 | 版本 | 备注 |
---|---|---|---|
1 | Nginx | 1.20.1 | 基本环境(LNMP) |
2 | PHP | 72w | 基本环境(LNMP) |
3 | MySQL|MariaDB | 8.0.36|10.5.25 | 基本环境(LNMP),二选一 MariaDB版本要求在10.5及以上 |
4 | zabbix-server | 6.0 | 使用编译安装 |
5 | zabbix-agent2 | 6.0 | 使用Yum安装 |
二、基本环境部署步骤
1、环境初始化操作
1、关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
2、定时时间同步
yum -y install ntpdate
ntpdate ntp1.aliyun.com
echo "0 1 * * * ntpdate ntp1.aliyun.com" >> /var/spool/cron/root
crontab -l
2、部署并配置Nginx
1、部署Nginx
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
yum clean all
yum -y install nginx
nginx -v
2、添加Nginx虚拟主机配置
vim /etc/nginx/conf.d/zabbix.conf
server {
listen 9780;
location / {
root /usr/share/nginx/html/zabbix;
index index.php index.html index.htm;
}
location ~ \.php$ {
root /usr/share/nginx/html/zabbix;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
access_log /var/log/nginx/zabbix_access.log;
error_log /var/log/nginx/zabbix_error.log;
}
}
3、启动Nginx并且加入开机自启动
nginx -t
systemctl start nginx
systemctl enable nginx
3、部署并配置PHP
1、部署PHP
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-gd php72w-mbstring php72w-pdo php72w-xml php72w-fpm php72w-mysqlnd php72w-opcache php72w-ldap php72w-bcmath
php -v
2、修改PHP启动用户/组配置
vim /etc/php-fpm.d/www.conf
user = nginx
group = nginx
3、修改PHP优化配置
vim /etc/php.ini
max_execution_time = 300
max_input_time = 600
post_max_size = 80M
date.timezone = Asia/Shanghai
4、启动PHP并且加入开机自启动
systemctl start php-fpm
systemctl enable php-fpm
4、测试Nginx+PHP环境
1、创建php页面
mkdir /usr/share/nginx/html/zabbix
vim /usr/share/nginx/html/zabbix/index.php
<?php
phpinfo();
?>
2、浏览器访问,显示如下图表示无误!
访问地址:http://IP:9780/index.php
5、部署并配置MariaDB
注意:数据库使用MariaDB和MySQL都是可以的,如果有现成的数据库也可以直接拿来用,本篇文章使用MariaDB进行演示
1、安装MariaDB
cat > /etc/yum.repos.d/mariadb.repo << EOF
[mariadb]
name = MariaDB
baseurl = http://mirrors.aliyun.com/mariadb/yum/10.5/centos7-amd64/
gpgkey = http://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck = 1
enabled=1
EOF
yum install -y mariadb-server mariadb
2、启动MariaDB并加入开机自启动
systemctl start mariadb
systemctl enable mariadb
3、查看版本
mysql -e "SELECT VERSION();"
4、初始化数据库
mysql
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NTQ34tg*@19VF.';
CREATE DATABASE zabbix character set utf8 collate utf8_bin;
GRANT all ON zabbix.* TO 'zabbix'@'localhost' IDENTIFIED BY 'NTQ34tg*@19VFZabbix.';
GRANT all ON zabbix.* TO 'zabbix'@'%' IDENTIFIED BY 'NTQ34tg*@19VFZabbix.';
flush privileges;
exit;
如果使用的是MySQL8.X,请执行下面SQL
create user "zabbix"@"localhost" identified WITH mysql_native_password by "NTQ34tg*@19VFZabbix.";
grant all on zabbix.* to "zabbix"@"localhost";
create user "zabbix"@"%" identified WITH mysql_native_password by "NTQ34tg*@19VFZabbix.";
grant all on zabbix.* to "zabbix"@"%";
flush privileges;
exit;
执行后MariaDB账号信息为:
账号 | 允许连接地址 | 密码 |
---|---|---|
root | localhost | NTQ34tg*@19VF. |
zabbix | localhost | NTQ34tg*@19VFZabbix. |
zabbix | 所有地址 | NTQ34tg*@19VFZabbix. |
三、Zabbix-Server部署步骤
1、编译安装Zabbix-Server
1、安装编译环境依赖
yum install -y mysql-devel pcre-devel openssl-devel zlib-devel libxml2-devel net-snmp-devel net-snmp libssh2-devel OpenIPMI-devel libevent-devel openldap-devel libcurl-devel fping gcc gcc-c++ make
2、下载zabbix源代码
wget https://cdn.zabbix.com/zabbix/sources/stable/6.0/zabbix-6.0.31.tar.gz --no-check-certificate
tar zxf zabbix-6.0.31.tar.gz -C /opt/
3、编译安装
cd /opt/zabbix-6.0.31/
./configure \
--sysconfdir=/etc/zabbix/ \
--bindir=/etc/zabbix/bin/ \
--sbindir=/etc/zabbix/bin/ \
--libexecdir=/etc/zabbix/libexec \
--sharedstatedir=/etc/zabbix/sharedstatedir \
--localstatedir=/etc/zabbix/statedir \
--runstatedir=/etc/zabbix/run \
--libdir=/etc/zabbix/lib \
--includedir=/etc/zabbix/include \
--oldincludedir=/etc/zabbix/oldinclude\
--datarootdir=/etc/zabbix/share \
--datadir=/etc/zabbix/data \
--enable-server \
--with-mysql \
--with-net-snmp \
--with-libxml2 \
--with-ssh2 \
--with-openipmi \
--with-zlib \
--with-libpthread \
--with-libevent \
--with-openssl \
--with-ldap \
--with-libcurl \
--with-libpcre
make install
2、导入Zabbix初始化库
zabbix-server的初始化库在源码包中/opt/zabbix-6.0.31/database/mysql
注意:按照顺序导入SQL:
cd /opt/zabbix-6.0.31/database/mysql
mysql -uzabbix -pNTQ34tg*@19VFZabbix. zabbix < schema.sql
mysql -uzabbix -pNTQ34tg*@19VFZabbix. zabbix < images.sql
mysql -uzabbix -pNTQ34tg*@19VFZabbix. zabbix < data.sql
mysql -uzabbix -pNTQ34tg*@19VFZabbix. zabbix < double.sql
mysql -uzabbix -pNTQ34tg*@19VFZabbix. zabbix < history_pk_prepare.sql
3、配置Zabbix前端UI
zabbix-server的前端文件在源码包中/opt/zabbix-6.0.31/ui
放到Nginx 根目录即可!
cp -rp /opt/zabbix-6.0.31/ui/* /usr/share/nginx/html/zabbix/
4、启动Zabbix-Server
1、修改zabbix配置
vim /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=NTQ34tg*@19VFZabbix.
2、创建用户,用来启动zabbix(zabbix禁止使用root用户启动)
sudo useradd -r -s /sbin/nologin zabbix6
chown -R zabbix6:zabbix6 /etc/zabbix/
3、添加systemd管理
cat > /usr/lib/systemd/system/zabbix-server.service << EOF
[Unit]
Description=Zabbix Server with MySQL DB
After=syslog.target network.target mysqld.service
[Service]
Type=simple
ExecStart=/etc/zabbix/bin/zabbix_server -f
User=zabbix6
Restart=on-failure
RestartSec=30s
KillMode=control-group
KillSignal=SIGTERM
TimeoutStopSec=30s
[Install]
WantedBy=multi-user.target
EOF
4、启动zabbix-server
systemctl start zabbix-server
systemctl enable zabbix-server
5、WEB页面配置
访问:http://IP:9780/
注意:我这里直截了修改的图片,如果一下截图中没有,那就直接下一步即可!
如果配置没问题后,显示如下图:
默认账号密码:Admin/zabbix
四、扩展功能
1、Zabbix-Agent部署步骤
1、部署Zabbix-Agent
rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/7/x86_64/zabbix-release-6.0-4.el7.noarch.rpm
sed -i 's#https://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo
yum install zabbix-agent2 zabbix-agent2-plugin-* -y
2、修改配置,指定zabbix-server地址
vim /etc/zabbix/zabbix_agent2.conf
Server=16.32.15.201
3、启动并加入开机自启动
systemctl start zabbix-agent2
systemctl enable zabbix-agent2
2、解决Web页面中文乱码问题
1、安装字体
yum install -y wqy-microhei-fonts
2、替换默认字体
cp -f /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /usr/share/nginx/html/zabbix/assets/fonts/DejaVuSans.ttf
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
所有评论(0)