一、环境准备
# 需要提前安装PHP、MySQL、nginx服务
# 下载zabbix安装包
zabbix-7.0.2.tar.gz
二、安装部署
2.1、安装zabbix.sh
#!/bin/bash
install_zabbix () {
version='7.0.2'
user=zabbix
echo "##### 检测网络 #####"
if ! ping -c1 -W1 www.baidu.com &> /dev/null
then
echo "网络不可以用, 请检查网络"
exit 1
fi
echo "##### 安装依赖 #####"
packages=(gcc libxml2 libxml2-devel net-snmp net-snmp-devel OpenIPMI OpenIPMI-devel libevent libevent-devel curl curl-devel libssh2-devel java java-devel mysql-devel unixODBC-devel openldap openldap-devel pcre pcre-devel fping)
for pkg in $(echo ${packages[*]})
do
yum install -y ${pkg} >/dev/null 2>&1
if [ $? -ne 0 ]
then
echo "install '$pkg' error,try again."
exit 2
fi
done
chmod u+s /usr/sbin/fping
echo "##### 创建$user用户 #####"
id $user &> /dev/null
if [ $? -eq 0 ];then
echo "$user 已存在"
else
useradd -M -s /sbin/nologin $user &> /dev/null
echo "$user 创建成功"
fi
# 解压安装
echo "##### 下载和解压zabbix #####"
# wget https://cdn.zabbix.com/zabbix/sources/stable/7.0/zabbix-7.0.2.tar.gz >/dev/null 2>&1
if [ $? -ne 0 ]
then
echo -e "\033[31m 下载 'zabbix' 失败\033[0m"
exit 3
fi
tar -xf zabbix-$version.tar.gz
if [ $? -ne 0 ]
then
echo -e "\033[31m tar xvf 'zabbix' failed\033[0m"
exit 4
fi
cd zabbix-$version
if [ $? -ne 0 ]
then
echo -e "\033[31m cd 'zabbix' failed\033[0m"
exit 5
fi
echo "##### 安装zabbix #####"
./configure --prefix=/usr/local/zabbix \
--enable-server \
--enable-agent \
--enable-java \
--with-mysql \
--enable-ipv6 \
--with-net-snmp \
--with-libcurl \
--with-libxml2 \
--with-unixodbc \
--with-openipmi \
--enable-ipv6 \
--with-openssl \
--with-ssh2 \
--with-iconv \
--with-libpcre \
--with-iconv-include \
--with-iconv-lib \
--with-libevent \
--with-libevent-include \
--with-zlib \
--with-zlib-include \
--with-zlib-lib \
--with-libpthread \
--with-libpthread-include \
--with-libpthread-lib \
--with-libevent-lib \
--with-ldap >/dev/null 2>&1
if [ $? -ne 0 ]
then
echo -e "\033[31m ./configure 'zabbix' failed\033[0m"
exit 6
fi
make -j $(nproc) >/dev/null 2>&1
if [ $? -ne 0 ]
then
echo -e "\033[31m make 'zabbix' failed\033[0m"
exit 7
fi
make install >/dev/null 2>&1
if [ $? -ne 0 ]
then
echo -e "\033[31m make install 'zabbix' failed\033[0m"
exit 8
fi
echo "ok !!!!"
}
install_zabbix
三、MySQL创建zabbix用户
# 创建和配置数据库和用户
mysql -uroot -p<password>
mysql> create database zabbix character set utf8mb4 collate utf8mb4_bin;
mysql> create user 'zabbix'@'localhost' identified by 'zabbix@123';
mysql> grant all privileges on zabbix.* to 'zabbix'@'localhost';
mysql> SET GLOBAL log_bin_trust_function_creators = 1;
mysql> quit;
# 将数据导入数据库,并将 utf8mb4 字符集设置为默认字符集。 对于 Zabbix 代理数据库,只应导入 schema.sql(不导入 images.sql 或 data.sql)。
cd database/mysql
mysql -uzabbix -p<password> zabbix < schema.sql
# 如果您正在为 Zabbix proxy创建数据库,请在此处停止
mysql -uzabbix -p<password> zabbix < images.sql
mysql -uzabbix -p<password> zabbix < data.sql
# 成功导入schema后,可以禁用 log_bin_trust_function_creators:
mysql -uroot -p<password>
mysql> SET GLOBAL log_bin_trust_function_creators = 0;
mysql> quit;
四、zabbix配置
4.1、zabbixUI拷贝
# 拷贝UI文件
cp -r /root/zabbix-7.0.2/ui/ /var/www/zabbix/
# 更改share为nginx用户(这里nginx的用户是www)
chown -R www:www /var/www/zabbix/
4.2、配置zabbix_server
# vim /usr/local/zabbix/etc/zabbix_server.conf
LogFile=/tmp/zabbix_server.log
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix@123
DBSocket=/tmp/mysql.sock
DBPort=3306
Timeout=4
LogSlowQueries=3000
StatsAllowedIP=127.0.0.1
EnableGlobalScripts=0
4.3、配置nginx
# vim /usr/local/nginx/conf/vhost/zabbix.conf
server {
listen 8111;
server_name _;
root /var/www/zabbix/ui/;
index index.html index.htm index.php zabbix.php;
location ~ [^/]\.php(/|$) {
fastcgi_pass 127.0.0.1:9000;
#fastcgi_pass unix:/dev/shm/php-cgi.sock;
index index.php;
fastcgi_index index.php;
include fastcgi.conf;
}
}
4.4、配置systemd
4.4.1、zabbix-agent
# vim /etc/systemd/system/zabbix-agent.service
[Unit]
Description=Zabbix Agent
After=network.target
[Service]
Type=simple
PIDFile=/tmp/zabbix_agentd.pid
ExecStart=/usr/local/zabbix/sbin/zabbix_agentd -c /usr/local/zabbix/etc/zabbix_agentd.conf
ExecReload=/bin/kill -HUP $MAINPID
TimeoutStopSec=20
Restart=on-failure
RestartSec=10
[Install]
WantedBy=multi-user.target
4.4.2、zabbix-server
# vim /etc/systemd/system/zabbix-server.service
[Unit]
Description=Zabbix Server
After=network.target
[Service]
Type=simple
PIDFile=/tmp/zabbix_server.pid
ExecStart=/usr/local/zabbix/sbin/zabbix_server -c /usr/local/zabbix/etc/zabbix_server.conf
ExecReload=/bin/kill -HUP $MAINPID
TimeoutStopSec=20
Restart=on-failure
RestartSec=10
[Install]
WantedBy=multi-user.target
4.4.3、启动服务
sudo systemctl daemon-reload
sudo systemctl enable zabbix-server
sudo systemctl enable zabbix-agent
sudo systemctl start zabbix-server
sudo systemctl start zabbix-agent
4.4.4、访问zabbix
主机ip:8111
标签:部署,echo,--,zabbix,mysql,033,server,安装
From: https://blog.csdn.net/qq_56189058/article/details/142364150