zabbix源码安装

[TOC]

1、基础配置

  • 软件版本
软件名称 推荐版本 备注
os centos 7.9 x64 示例ip为192.168.4.193
zabbix zabbix 6.0.6
php php 8.0.20
nginx nginx 1.20.1
mysql mysql 8.0.20 zabbix-6.x不支持mysql-5.7
  • 配置 iso.sqlfans.cn 本地下载,加快下载速度
cat /etc/resolv.conf | grep 114 || echo "nameserver 114.114.114.114" >> /etc/resolv.conf
#cat /etc/hosts | grep iso.sqlfans.cn || echo "192.168.20.165 iso.sqlfans.cn" >> /etc/hosts
curl http://iso.sqlfans.cn/123.html
  • 安装基础依赖包
yum install -y lrzsz wget telnet net-tools ntpdate
  • 修改时区
sudo timedatectl set-timezone Asia/Shanghai
ll /etc/localtime
  • iptables设置
iptables -A INPUT -p tcp --dport 10050:10051 -j ACCEPT
iptables -A INPUT -p udp --dport 10050:10051 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp -s 127.0.0.1 --dport 3306 -j ACCEPT
  • 关闭selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0

2、安装mysql

  • 安装mysql
cd /opt
wget -c http://iso.sqlfans.cn/mysql/percona-server-8.0.32-24.tar.gz
wget -c http://iso.sqlfans.cn/mysql/config/8.0/my_innodb.cnf
wget -c http://iso.sqlfans.cn/mysql/install_percona_8032.sh
bash install_percona_8032.sh /opt /data 3306
  • 创建zabbix数据库(注意zabbix字符集)
#mysql -uroot -p -S /tmp/mysql_3306.sock -e"drop database if exists zabbix;"
mysql -uroot -p -S /tmp/mysql_3306.sock -e"create database if not exists zabbix charset utf8 collate utf8_bin;"
mysql -uroot -p -S /tmp/mysql_3306.sock -e"create user 'user_zabbix'@'%' identified with mysql_native_password by 'VuLdP4Jt@9X3waGv';"
mysql -uroot -p -S /tmp/mysql_3306.sock -e"grant all privileges on zabbix.* to 'user_zabbix'@'%';"
mysql -uroot -p -S /tmp/mysql_3306.sock -e"flush privileges;"
mysql -uroot -p -S /tmp/mysql_3306.sock -e"select host,user,plugin,account_locked from mysql.user;"
  • 导入数据库表(一定要按顺序导入)
cd /opt/
wget -c http://iso.sqlfans.cn/linux/zabbix/zabbix-6.0.6.tar.gz
tar xvf zabbix-6.0.6.tar.gz
time mysql -uroot -p -S /tmp/mysql_3306.sock zabbix < /opt/zabbix-6.0.6/database/mysql/schema.sql
time mysql -uroot -p -S /tmp/mysql_3306.sock zabbix < /opt/zabbix-6.0.6/database/mysql/images.sql
time mysql -uroot -p -S /tmp/mysql_3306.sock zabbix < /opt/zabbix-6.0.6/database/mysql/data.sql

3、安装nginx

  • nginx安装
cd /opt
wget -c http://iso.sqlfans.cn/linux/zlib-1.2.11.tar.gz
wget -c http://iso.sqlfans.cn/linux/pcre-8.44.tar.gz
wget -c http://iso.sqlfans.cn/linux/openssl-1.1.1g.tar.gz
wget -c http://iso.sqlfans.cn/linux/nginx-1.20.1.tar.gz
wget -c http://iso.sqlfans.cn/linux/nginx_openssl_conf.conf
wget -c http://iso.sqlfans.cn/linux/install_nginx_1250.sh
bash /opt/install_nginx_1250.sh

4、安装php

  • 安装php
yum install -y curl curl-devel bzip2 bzip2-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel pcre-devel sqlite-devel openssl openssl-devel
yum install -y http://iso.sqlfans.cn/php/oniguruma-6.8.2-2.el7.x86_64.rpm
yum install -y http://iso.sqlfans.cn/php/oniguruma-devel-6.8.2-2.el7.x86_64.rpm

cd /opt/
wget -c http://iso.sqlfans.cn/php/php-8.0.20.tar.gz
tar -zxf php-8.0.20.tar.gz
cd /opt/php-8.0.20/
./configure  --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --enable-gd --enable-mbstring --enable-calendar \
--with-jpeg --with-freetype --with-libdir=lib64 --with-openssl --with-gettext --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --enable-mysqlnd --enable-dom --enable-xml --enable-fpm --enable-bcmath

[ $? -eq 0 ] && make -j 4 && make install
  • 配置环境变量
echo 'export PATH=$PATH:/usr/local/php/bin' >> /etc/bashrc
source /etc/bashrc
php --version
  • 查看插件是否支持(1表示支持)
/usr/local/php/bin/php -r 'print_r(gd_info());'
/usr/local/php/bin/php -r 'phpinfo();' | grep enabled | egrep "(^GD|^OpenSSL|^JPEG|^PNG|^FreeType|^mysql)"
  • 修改php配置并启动fastcgi,确认9000端口已启用
\cp /opt/php-8.0.20/php.ini-production /usr/local/php/etc/php.ini
\cp /opt/php-8.0.20/sapi/fpm/php-fpm.conf /usr/local/php/etc/
\cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

sed -i '/^max_execution_time/c max_execution_time=300' /usr/local/php/etc/php.ini
sed -i '/^max_input_time/c max_input_time=300' /usr/local/php/etc/php.ini
sed -i '/^memory_limit/c memory_limit=128M' /usr/local/php/etc/php.ini
sed -i '/^post_max_size/c post_max_size=32M' /usr/local/php/etc/php.ini
sed -i '/^upload_max_filesize/c upload_max_filesize=2M' /usr/local/php/etc/php.ini
sed -i "s/;date.timezone/date.timezone/" /usr/local/php/etc/php.ini
sed -i '/^date.timezone/c date.timezone=Asia/Shanghai' /usr/local/php/etc/php.ini
sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=1/" /usr/local/php/etc/php.ini 
cat /usr/local/php/etc/php.ini | egrep "(max_execution_time|^max_input_time|memory_limit|post_max_size|upload_max_filesize|^date.timezone|mbstring.func_overload|^cgi.fix_pathinfo)"
  • 配置php-fpm服务
cp /opt/php-8.0.20/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
/etc/init.d/php-fpm start
chkconfig --add php-fpm
chkconfig --list php-fpm
service php-fpm restart
netstat -lnpt | grep 9000

5、安装zabbix

安装zabbix

  • 安装zabbix依赖程序
yum install -y gcc automake autoconf libtool make curl curl-devel libssh2 libssh2-devel net-snmp net-snmp-devel mysql-devel
yum install -y openldap openldap-devel OpenIPMI OpenIPMI-devel unixODBC unixODBC-devel libevent-devel
  • 增加zabbix用户和组
groupadd zabbix
useradd -g zabbix -m zabbix -s /usr/sbin/nologin
  • 安装zabbix服务端
cd /opt
wget -c http://iso.sqlfans.cn/linux/zabbix/zabbix-6.0.6.tar.gz
tar -zxf zabbix-6.0.6.tar.gz
cd zabbix-6.0.6
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --enable-proxy --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --with-unixodbc --with-openipmi --with-ldap --with-ssh2 --enable-ipv6
[ $? -eq 0 ] && make -j 4 && make install
  • 检查版本安装
/usr/local/zabbix/sbin/zabbix_server --version | grep zabbix_server
/usr/local/zabbix/sbin/zabbix_agentd --version | grep zabbix_agentd

配置zabbix

  • 设置软件环境变量
cd /opt
wget -c http://iso.sqlfans.cn/linux/zabbix/func_gcc_program_set_env.sh
source func_gcc_program_set_env.sh
func_gcc_program_set_env /usr/local/zabbix "zabbix"
  • 修改zabbix配置文件
mkdir -p /data/logs/zabbix
chown -R zabbix.zabbix /usr/local/zabbix
chown -R zabbix.zabbix /data/logs/zabbix

mv /usr/local/zabbix/etc/zabbix_server.conf /usr/local/zabbix/etc/zabbix_server.conf.$(date +%Y%m%d%H%M%S)
cat > /usr/local/zabbix/etc/zabbix_server.conf <<EOF
ListenPort=10051
LogFile=/data/logs/zabbix/zabbix_server.log
LogFileSize=100
PidFile=/tmp/zabbix_server.pid
DBHost=192.168.4.193
DBName=zabbix
DBUser=user_zabbix
DBPassword=VuLdP4Jt@9X3waGv
DBPort=3306
StartPollers=20
StartTrappers=20
StartPingers=4
StartDiscoverers=4
CacheSize=256M
StartDBSyncers=16
HistoryCacheSize=64M
TrendCacheSize=8M
ValueCacheSize=16M
Timeout=10
AlertScriptsPath=/usr/local/zabbix/share/zabbix/alertscripts
ExternalScripts=/usr/local/zabbix/share/zabbix/externalscripts
LogSlowQueries=3000
EOF
  • 确认一下配置
cat /usr/local/zabbix/etc/zabbix_server.conf | grep -n ^[^#]
cat /usr/local/zabbix/etc/zabbix_agentd.conf | grep -n ^[^#]
cat /usr/local/zabbix/etc/zabbix_proxy.conf | grep -n ^[^#]
  • 拷贝启动脚本
mkdir -p /usr/local/sbin
ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/
ln -s /usr/local/zabbix/bin/* /usr/local/bin/
\cp -r /opt/zabbix-6.0.6/misc/init.d/fedora/core5/* /etc/init.d/
chmod +x /etc/init.d/zabbix_*
  • 配置zabbix server服务,默认端口10051
chkconfig --add zabbix_server
chkconfig --list zabbix_server
chkconfig zabbix_server on
chkconfig --list zabbix_server
service zabbix_server start
service zabbix_server restart
#tail -n20 /data/logs/zabbix/zabbix_server.log
  • 配置zabbix agent服务,默认端口10050
chkconfig --add zabbix_agentd
chkconfig --list zabbix_agentd
chkconfig zabbix_agentd on
chkconfig --list zabbix_agentd
service zabbix_agentd start
service zabbix_agentd restart
#tail -n20 /tmp/zabbix_agentd.log
netstat -nltp | grep 'zabbix'  #.检查端口
  • 拷贝web站点,修改nginx配置,并启动进程(以nobody用户启动)
mkdir -p /data/logs/nginx
mkdir -p /data/wwwroot/zabbix
\cp -r /opt/zabbix-6.0.6/ui/* /data/wwwroot/zabbix/

mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.$(date +%Y%m%d%H%M%S)
curl http://iso.sqlfans.cn/linux/zabbix/nginx.conf > /usr/local/nginx/conf/nginx.conf
chown -R zabbix.zabbix /data/wwwroot/zabbix
chmod 777 /data/wwwroot/zabbix/conf

/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload
#tail -n20 /data/logs/nginx/error.log
netstat -nltp | grep 'zabbix'  #.检查端口

在线配置zabbix

  • 浏览器打开 http://192.168.4.193/zabbix
Step1:欢迎界面,下一步;
Step2:php需求检查,必须全部通过;
Step3:mysql配置:输入mysql的连接信息;★不要勾选 Database TLS encryption
Step4:settings信息:Zabbix server name输入:Zabbix
Step5:zabbix安装前信息列表,下一步;
Step6:安装完成。默认用户名:Admin,密码:zabbix

x.重来一遍

  • 清理nginx
/usr/local/nginx/sbin/nginx -s stop
rm -rf /usr/local/nginx
userdel -r nginx 2> /dev/null
sed -i '/nginx/d' /etc/rc.local
  • 清理mysql
ps -ef | grep mysql | grep -v grep | awk '{print $2}' | xargs kill -9 2> /dev/null
userdel -r mysql 2> /dev/null
rm -f /opt/install_percona*.sh
rm -f /opt/my_innodb.cnf
rm -rf /opt/mysql
rm -rf /data/mysql_*
sed -i '/mysql/d' /etc/rc.local
  • 清理zabbix
ps aux | grep zabbix | grep -v grep | awk '{print $2}' | xargs kill -9 2> /dev/null
rm -rf /data/{logs,zabbix}
rm -rf /usr/local/zabbix
rm -f /usr/local/bin/zabbix*
rm -f /usr/local/sbin/zabbix*
rm -f /etc/init.d/zabbix*
rm -f /tmp/zabbix*
userdel -r zabbix 2> /dev/null
sed -i '/zabbix/d' /etc/rc.local
Copyright © www.sqlfans.cn 2024 All Right Reserved更新时间: 2024-04-29 13:46:34

results matching ""

    No results matching ""