[root@Zabbix ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo [root@Zabbix ~]# yum -y install epel-release [root@Zabbix ~]# yum -y install yum-utils device-mapper-persistent-data lvm2 [root@Zabbix ~]# yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo [root@Zabbix ~]# yum -y install docker-ce-19.03.12 docker-ce-cli-19.03.12 [root@Zabbix ~]# systemctl enable docker --now
[root@Zabbix ~]# wget "https://github.com/docker/compose/releases/download/v2.3.2/docker-compose-$(uname -s)-$(uname -m)" -O /usr/local/bin/docker-compose [root@Zabbix ~]# chmod +x /usr/local/bin/docker-compose [root@Zabbix ~]# docker-compose --version
[root@Zabbix ~]# rpm -ivh http://repo.zabbix.com/zabbix/5.4/rhel/7/x86_64/zabbix-agent-5.4.8-1.el7.x86_64.rpm [root@Zabbix ~]# egrep -v '^$|#' zabbix_agentd.conf PidFile=/var/run/zabbix/zabbix_agentd.pid LogFile=/var/log/zabbix/zabbix_agentd.log LogFileSize=0 Server=127.0.0.1 ServerActive=127.0.0.1 Hostname=Zabbix server Include=/etc/zabbix/zabbix_agentd.d/*.conf [root@Zabbix ~]# systemctl enable zabbix-agent --now
[root@Zabbix ~]# mkdir -p /app/zabbix [root@Zabbix ~]# cd /app/zabbix/ [root@Zabbix zabbix]# cat <<END > docker-compose.yml version: "3" services: mysql-server: image: mysql:5.7 ports: - "3306:3306" volumes: - "/app/mysql:/var/lib/mysql" # 配置数据卷 (防止监控数据丢失) environment: MYSQL_ROOT_PASSWORD: 123123 TZ: Asia/Shanghai command: --character-set-server=utf8 --collation-server=utf8_bin restart: always zabbix-server: image: zabbix/zabbix-server-mysql:5.4.8-centos environment: DB_SERVER_HOST: 127.0.0.1 DB_SERVER_PORT: 3306 MYSQL_DATABASE: zabbix MYSQL_USER: root MYSQL_PASSWORD: 123123 TZ: Asia/Shanghai depends_on: - mysql-server restart: always network_mode: "host" # 使用主机网络 zabbix-web: image: zabbix/zabbix-web-nginx-mysql:5.4.8-centos ports: - "8000:8080" # Zabbix WebUI 映射端口 volumes: # 当在 Web 界面配置成中文后,监控界面会出现乱码 - "./simkai.ttf:/usr/share/zabbix/assets/fonts/DejaVuSans.ttf" environment: DB_SERVER_HOST: mysql-server DB_SERVER_PORT: 3306 MYSQL_DATABASE: zabbix MYSQL_USER: root MYSQL_PASSWORD: 123123 TZ: Asia/Shanghai ZBX_SERVER_HOST: 192.168.1.1 depends_on: - mysql-server - zabbix-server restart: always END [root@Zabbix zabbix]# docker-compose up -d [root@Zabbix zabbix]# docker-compose ps
[root@Zabbix ~]# echo "UnsafeUserParameters=1" >> /etc/zabbix/zabbix_agentd.conf
[root@Zabbix ~]# yum -y install nginx
[root@Zabbix ~]# cat <<END > /etc/nginx/conf.d/status.conf
server {
listen 80;
server_name 127.0.0.1;
location /status {
stub_status on;
allow 127.0.0.1;
allow 192.168.1.0/24;
deny all;
}
}
END[root@Zabbix ~]# mkdir /etc/zabbix/scripts
[root@Zabbix ~]# vim /etc/zabbix/scripts/nginx_status.sh
#!/bin/bash
HOST="127.0.0.1"
PORT="80"
# 监控 Nginx 进程是否存在
function Ping {
/sbin/pidof nginx | wc -l
}
# 监控 Nginx 状态信息
function Active {
/usr/bin/curl "http://$HOST:$PORT/status" 2> /dev/null | grep "Active" | awk '{print $NF}'
}
function Reading {
/usr/bin/curl "http://$HOST:$PORT/status" 2> /dev/null | grep "Reading" | awk '{print $2}'
}
function Writing {
/usr/bin/curl "http://$HOST:$PORT/status" 2> /dev/null | grep "Writing" | awk '{print $4}'
}
function Waiting {
/usr/bin/curl "http://$HOST:$PORT/status" 2> /dev/null | grep "Waiting" | awk '{print $6}'
}
function Server {
/usr/bin/curl "http://$HOST:$PORT/status" 2> /dev/null | awk NR==3 | awk '{print $1}'
}
function Accepts {
/usr/bin/curl "http://$HOST:$PORT/status" 2> /dev/null | awk NR==3 | awk '{print $2}'
}
function Requests {
/usr/bin/curl "http://$HOST:$PORT/status" 2> /dev/null | awk NR==3 | awk '{print $3}'
}
# 执行 function
$1
[root@Zabbix ~]# chmod +x /etc/zabbix/scripts/nginx_status.sh[root@Zabbix ~]# cat <<"END" > /etc/zabbix/zabbix_agentd.d/nginx_status.conf UserParameter=nginx.status[*],/etc/zabbix/scripts/nginx_status.sh $1 END [root@Zabbix ~]# systemctl restart zabbix-agent
[root@Zabbix ~]# docker exec -it zabbix-zabbix-server-1 /bin/bash
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70003733/viewspace-2886831/ ,如需转载,请注明出处,否则将追究法律责任。