zabbix是基于LAMP或者LNMP架构的监控软件。本次安装基于LNMP,Linux+Nginx+Mysql+Php(提前配置阿里云yum源)
1.关闭防火墙和selinux
#关闭防火墙
systemctl stop firewalld.service
#关闭安全机制
setenforce 0
vim /etc/selinux/config
2.安装所需要的依赖
#安装MySQL相关依赖
yum -y install gcc-c++ mysql-devel net-snmp-devel libevent-devel
wget http://repo.mysql.com/mysql80-community-release-el7-1.noarch.rpm
安装mysql80-community-release-el7-1.noarch.rpm包
rpm -ivh mysql80-community-release-el7-1.noarch.rpm
安装完成后会在 /etc/yum.repos.d文件夹里面获得两个文件:mysql-community.repo && mysql-community-source.repo
报了个错误 直接 yum install mysql-server --nogpgcheck 安装即可

systemctl start/status/enabled mysqld

mysqld --initialize
cat /var/log/mysqld.log|grep pass

mysql -u root -p alter user 'root'@'localhost' identified by 'Zabbix#0574110';
yum install [https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm](https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm)
yum install [http://rpms.remirepo.net/enterprise/remi-release-7.rpm](http://rpms.remirepo.net/enterprise/remi-release-7.rpm)
### 2.安装yum-utils
yum-config-manager --enable remi-php74
yum -y install php php-cli php-common php-gd php-json php-ldap php-mbstring php-mysqlnd php-pdo php-xml php-devel php-embedded php-mcrytp php-pecl-mongodb php-pecl-redis php-pecl-memcached php-opcache php-fpm php-bcmathphp -v
systemctl start/status/enabled php-fpmvim /etc/yum.repos.d/nginx.repo
yum-config-manager --enable nginx-mainline
yum install -y nginxsystemctl start nginx 检查Nginx配置文件:nginx -t 平滑重载:systemctl reload nginx
或者进入到数据库的页面,导入数据库
cd /usr/local/zabbix/database/mysql/
安装依赖
yum -y install mysql-devel pcre-devel opensll-devel
cd zabbix
// --sysconfdir=/etc/zabbix/ 指定配置文件的目录
// --enable-server 安装的是服务端
./configure --sysconfdir=/etc/zabbix/ --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
groupadd --system zabbix
useradd zabbix -g zabbix -s /sbin/nologin
vim /usr/lib/systemd/system/zabbix-server.service
systemctl start zabbix-server.service
systemctl status zabbix-server.service

systemctl enable zabbix-server.service
/usr/local/zabbix/
mkdir -p /app/code/zabbix
cp -r ui/* /app/code/zabbix
Nginx 配置vim /etc/nginx/conf.d/default.conf vim /etc/php.ini
修改post_max_size为16M
修改max_execution_time为300
修改max_input_time为300
然后重启php
搭建完成mksw@2023
rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/7/x86_64/zabbix-release-6.0-4.el7.noarch.rpm
yum clean allyum install zabbix-agent2 -y
sed -i 's#Server=127.0.0.1#Server=192.168.20.134#g' /etc/zabbix/zabbix_agnet2.conf
修改Server= zabbix-server地址
修改ServerActive=zabbix-server地址
Hostname=本机计算机名
systemctl restart zabbix-agent2
systemctl enable zabbix-agent2
linux防火墙开启的话需要放通10050端口
firewall-cmd --add-port=10050/tcp
firewall-cmd --permanent --add-port=10050/tcpyum install -y zabbix-get
zabbix_get -s '127.0.0.1' -p 10050 -k 'agent.ping'
-
双击安装

直接安装Windows Server防火墙开启需要放通10050端口

yum install -y wqy-microhei-fonts
\cp /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /app/code/zabbix/assets/fonts/DejaVuSans.ttf

也可复制Windows的字体

重命名 mv simkai.ttf DejaVuSans.ttf 重启服务 systemctl restart zabbix-server.service nginx php-fpm.service



(1)导出数据配置,排除历史数据和趋势数据
mysqldump -uroot -p --databases zabbix --ignore-table=zabbix.history --ignore-table=zabbix.history_log --ignore-table=zabbix.history_str --ignore-table=zabbix.history_text --ignore-table=zabbix.history_uint --ignore-table=zabbix.trends --ignore-table=zabbix.trends_uint > /opt/zabbix_config.sql(2)导出排除数据的表结构
mysqldump -d zabbix -uroot -p --tables history history_log history_str history_text history_uint trends trends_uint > /opt/ zabbix_data.sqlmysql -uroot -p zabbix < /opt/zabbix_config.sql mysql -uroot -p zabbix < /opt/zabbix_data.sqluse mysql;
#修改root账户权限
update user set host = '%' where user = 'root';
#刷新权限
flush privileges;
4.创建zabbix库
#创建zabbix库
create database zabbix character set utf8 collate utf8_bin;
#创建zabbix用户
create user zabbix@localhost identified by 'Zabbix#110';
#授权
grant all privileges on zabbix.* to zabbix@localhost;
5.下载zabbix
wget [https://cdn.zabbix.com/zabbix/sources/stable/6.0/zabbix-6.0.12.tar.gz](https://cdn.zabbix.com/zabbix/sources/stable/6.0/zabbix-6.0.12.tar.gz)[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=truetar -zxvf zabbix-6.0.12.tar.gz
mv zabbix-6.0.12 /usr/local mv ./zabbix-6.0.12 zabbix
mysql -uroot -p
use zabbix
source /usr/local/zabbix/database/mysql/schema.sql;
source /usr/local/zabbix/database/mysql/images.sql;
source /usr/local/zabbix/database/mysql/data.sql;
source /usr/local/zabbix/database/mysql/history_pk_prepare.sql;
source /usr/local/zabbix/database/mysql/double.sql;[Unit]
Description=Zabbix Server
After=syslog.target network.target mysqld.service
[Service]
Type=simple
ExecStart=/usr/local/sbin/zabbix_server -f
User=zabbix
[Install]
WantedBy=multi-user.targetvim /etc/zabbix/zabbix_server.conf
LogFile=/usr/local/zabbix/log/zabbix_server.log # 日志目录
DBName=zabbix # 数据库名称
DBUser=zabbix # 数据库用户名称
DBHost=localhost # 数据库地址
DBPassword=Zabbix#110 # 数据库密码
DBPort=3306 # 数据库端口号
##Include=/etc/zabbix/zabbix_server.conf.d/*.conf # 自定义监控配置文件server {
listen 80;
server_name localhost;
root /app/code/zabbix;
location / {
try_files $uri $uri/ /index.html;
index index.html index.php;
autoindex off;
proxy_set_header Host $http_host;
}
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}#!/bin/bash
# 1. 判断系统是否已安装Zabbix Agent
HOSTNAME=$(hostname)
ZABBIX_AGENT=$(rpm -qa | grep zabbix-agent | head -n 1 | sed 's/\(.\{1,12\}\).*/\1/')
if [ "$ZABBIX_AGENT" = "zabbix-agent" ]; then
echo "Zabbix Agent已安装"
exit 0
else
echo "Zabbix Agent未安装"
fi
# 2. 安装Zabbix Agent并替换server地址
echo "添加Zabbix的本地仓库"
wget http://192.168.20.249/data/zabbix.repo /etc/yum.repos.d/zabbix.repo
yum clean && yum makecache
echo "安装 Zabbix Agent"
yum install -y zabbix-agent2
echo "替换 Zabbix Agent 配置文件中的 server 地址,替换为实际的 Zabbix server 地址"
sed -i 's/Server=127.0.0.1/Server=172.16.200.90/g' /etc/zabbix/zabbix_agent2.conf
sed -i 's/ServerActive=127.0.0.1/ServerActive=172.16.200.90/g' /etc/zabbix/zabbix_agent2.conf
sed -i "s/Hostname=Zabbix server/Hostname=$HOSTNAME/g" /etc/zabbix/zabbix_agent2.conf
echo "启动Zabbix Agent 服务"
systemctl start zabbix-agent2
systemctl enable zabbix-agent2
echo "配置防火墙"
if systemctl is-active firewalld >/dev/null 2>&1; then
# 如果防火墙正在运行,放通 10050 端口
firewall-cmd --add-port=10050/tcp
firewall-cmd --add-port=10050/tcp --permanent
echo "Firewall port 10050 has been opened."
fi
echo "Zabbix Agent 已经安装完成"