1、前期环境
主机名
IP地址
操作系统
备注
zabbix-10
192.168.2.10
CentOS Linux release 7.4
zabbix服务端
agent-15
192.168.2.15
CentOS Linux release 7.4
zabbix客户端
2.2、主机
[root@zabbix-10 ~]# systemctl stop firewalld
[root@zabbix-10 ~]# systemctl disable firewalld
[root@zabbix-10 ~]# setenforce 0
[root@zabbix-10 ~]# vim /etc/selinux/config
SELINUX=disabled
2.3、软件详情
vmware:版本VMware10
Linux:CentOS Linux release 7.4
Nginx:nginx-2.14.2
PHP:php-7.3.28
zabbix:5.0 LTS
软件包地址:
链接:https://pan.baidu.com/s/1JMXE68PKsN-jafNaTP_cdQ
提取码:e7lf
1、安装php依赖组件(包含Nginx依赖)
yum install -y gcc-c++ autoconf make \
libjpeg libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 libxml2-devel \
zlib zlib-devel unzip \
zip libzip-devel \
glibc glibc-devel \
glib2 glib2-devel \
bzip2 bzip2-devel \
curl curl-devel libcurl-devel \
ncurses openssl-devel \
gdbm-devel db4-devel libXpm-devel \
libX11-devel gd-devel gmp-devel \
readline-devel libxslt-devel \
expat-devel xmlrpc-c xmlrpc-c-devel \
libicu-devel libmcrypt-devel \
libmemcached-devel \
oniguruma oniguruma-devel \
sqlite-devel \
2、创建www用户,解压
[root@zabbix-10 ~]# useradd -s /sbin/nologin www
[root@zabbix-10 ~]# id www
uid=1000(www) gid=1000(www) 组=1000(www)
[root@zabbix-10 iso]# tar -xvf php-7.3.28.tar.bz2
[root@zabbix-10 iso]# cd php-7.3.28
3、源码编译、安装
[root@zabbix-10 php-7.3.28]# ./configure --prefix=/usr/local/php --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip
可能会报错,提示需要安装zlib
查看yum是否安装,安装了还是提示错误的话就卸载了自己下载源码包编译安装,
如果zlib版本大于2.2的话可能会提示cmake版本过低,要求升级cmake
下载Cmake
[root@zabbix iso]# wget https://cmake.org/files/v3.6/cmake-3.6.2.tar.gz
[root@zabbix iso]# tar -xvf cmake-3.6.2.tar.gz
[root@zabbix iso]# mv cmake-3.6.2 /usr/local/cmake3
[root@zabbix iso]# cd /usr/local/cmake3/
[root@zabbix cmake3]# ./configure
[root@zabbix cmake3]# make && make install
4、移除旧的libzip:
[root@zabbix iso]# yum remove libzip
5、安装新版本:
[root@zabbix iso]# curl -O https://libzip.org/download/libzip-2.5.2.tar.gz
[root@zabbix iso]# tar -zxvf libzip-2.5.2.tar.gz
[root@zabbix iso]# cd libzip-2.5.1
[root@zabbix libzip-2.5.1]# mkdir build
[root@zabbix libzip-2.5.1]# cd build
[root@zabbix build]# cmake ..
[root@zabbix build]# make && make install
6、再次执行
[root@zabbix-10 php-7.3.28]# ./configure --prefix=/usr/local/php --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip
[root@zabbix-10 php-7.3.28]# make && make install
提示:若无报错执行下一步安装,如果编译过程中出现错误,根据报错安装依赖包,通常不会出现这种问题。
7、完成安装后配置php.ini文件
[root@zabbix-10 php-7.3.28]# cp php.ini-development /usr/local/php/etc/php.ini
[root@zabbix-10 php-7.3.28]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@zabbix-10 php-7.3.28]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
8、修改 php.ini 相关参数
[root@zabbix-10 ~]# vim /usr/local/php/etc/php.ini
date.timezone = Asia/Shanghai //设置时区
max_execution_time = 300 //最大执行时间,秒
post_max_size = 32M //POST数据最大容量
max_input_time = 300 //服务器接收数据的时间限制
memory_limit = 128M //内存容量限制
9、配置www.conf
[root@zabbix-10 ~]# vim /usr/local/php/etc/php-fpm.d/www.conf
user = www
group = www
10、创建system系统单元文件php-fpm启动脚本
[root@zabbix-10 ~]# vim /usr/lib/systemd/system/php-fpm.service
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=simple
PIDFile=/usr/local/php/var/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
[Install]
WantedBy=multi-user.target
或者
[root@zabbix-10 php-7.4.19]# cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/php-fpm.service
然后修改/usr/lib/systemd/system/php-fpm.service
ExecStart=/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf
[root@zabbix-10 php-7.4.19]# systemctl restart php-fpm
[root@zabbix-10 php-7.4.19]# systemctl enable php-fpm
1、安装依赖、减压
[root@zabbix-10 iso]# yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
[root@zabbix-10 iso]# tar -xvf nginx-2.14.2.tar.gz
[root@zabbix-10 iso]# cd nginx-2.14.2
[root@zabbix-10 nginx-2.14.2]# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-stream --with-http_stub_status_module
[root@zabbix-10 nginx-2.14.2]# make && make install
2、配置nginx.conf
[root@zabbix-10 ~]# vim /usr/local/nginx/conf/nginx.conf
… …
http{
… …
fastcgi_buffers 8 16k; #缓存php生成的页面内容,8个16k
fastcgi_buffer_size 32k; #缓存php生产的头部信息
fastcgi_connect_timeout 300; #连接PHP的超时时间
fastcgi_send_timeout 300; #发送请求的超时时间
fastcgi_read_timeout 300; #读取请求的超时时间
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location ~ \.php$ {
#root html;
#index index.html index.htm;
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
[root@zabbix-10 ~]# /usr/local/nginx/sbin/nginx
[root@zabbix-10 ~]# ss -tunlp| grep nginx
tcp LISTEN 0 128 *:80 *:* users:(("nginx",pid=26768,fd=6),("nginx",pid=26766,fd=6))
3、测试是否能解析php
vim /usr/local/nginx/html/test2.php
<?php
$i="This is a test Page";
echo $i;
?>
浏览器输入:http://192.168.4.5/test2.php ,出现如下说明解析php成功。
This is a test Page
1、卸载mariadb相关包
[root@zabbix-10 iso]# yum install -y mariadb mariadb-devel mariadb-server
2、设置MySQL字符集
[root@zabbix-10 ~]# vim /etc/my.cnf
[mysqld]
character-set-server=utf8
[root@zabbix-10 ~]# systemctl restart mariadb
3、修改密码
[root@zabbix-10 ~]# mysql -p
Enter password:
mysql> alter user root@localhost identified by 'Jluo520!';
Query OK, 0 rows affected (0.00 sec)
//新修改的密码中 必须包含 大小写字母数字及符号
4、测试php能否连接mysql
vim /usr/local/nginx/html/test2.php
<?php
$mysqli = new mysqli('localhost','root','密码','mysql');
//注意:root为mysql账户名称,密码需要修改为实际mysql密码,无密码则留空即可
//localhost是数据库的域名或IP,mysql是数据库的名称
if (mysqli_connect_errno()){
die('Unable to connect!'). mysqli_connect_error();
}
$sql = "select * from user";
$result = $mysqli->query($sql);
while($row = $result->fetch_array()){
printf("Host:%s",$row[0]);
printf("</br>");
printf("Name:%s",$row[1]);
printf("</br>");
}
?>
浏览器输入: http://192.168.4.5/test2.php ,出现如下图说明连接数据库成功。
1、源码安装Zabbix Server
多数源码包都是需要依赖包的,zabbix也一样,源码编译前需要先安装相关依赖包。
[root@zabbix zabbix-5.0.12]# yum -y install net-snmp-devel curl-devel libevent-devel
[root@zabbix zabbix-5.0.12]# ./configure --prefix=/usr/local/zabbix --enable-server --enable-proxy --enable-agent --with-mysql=/usr/bin/mysql_config --with-net-snm --with-libcurl --enable-java
//prefix=/usr/local/zabbix 指定安装位置
// --enable-server安装部署zabbix服务器端软件
// --enable-agent安装部署zabbix被监控端软件
// --enable-proxy安装部署zabbix代理相关软件
// --with-mysql配置mysql_config路径
// --with-net-snmp允许zabbix通过snmp协议监控其他设备
// --with-libcurl安装相关curl库文件,这样zabbix就可以通过curl连接http等服务,测试被监控主机服务的状态
//--enable-java开启jmx监控,需要安装java,即:yum -y install java java-devel
[root@zabbix zabbix-5.0.12]# make && make install
2、初始化Zabbix
创建数据库,上线Zabbix的Web页面
[root@zabbix zabbix-5.0.12]# mysql -p
Enter password:
mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on zabbix.* to zabbix@'localhost' identified by 'Zabbix520!';
Query OK, 0 rows affected, 1 warning (0.00 sec)
[root@zabbix zabbix-5.0.12]# cd database/mysql/
[root@zabbix mysql]# ls
data.sql double.sql images.sql Makefile Makefile.am Makefile.in schema.sql
//刚刚创建是空数据库,zabbix源码包目录下,有提前准备好的数据
//使用mysql导入这些数据即可(注意导入顺序)
[root@zabbix mysql]# mysql -uzabbix -pZabbix520! zabbix < schema.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@zabbix mysql]# mysql -uzabbix -pZabbix520! zabbix < images.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@zabbix mysql]# mysql -uzabbix -pZabbix520! zabbix < data.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
3、上线Zabbix的Web页面
[root@zabbix zabbix-5.0.12]# cp -r ui/* /usr/local/nginx/html/
[root@zabbix zabbix-5.0.12]# chown -R www:www /usr/local/nginx/*
4、修改Zabbix_server配置文件,设置数据库相关参数,启动Zabbix_server服务
[root@zabbix zabbix-5.0.12]# cd /usr/local/zabbix/
[root@zabbix zabbix]# mkdir logs
[root@zabbix zabbix]# vim etc/zabbix_server.conf
//数据库主机,默认该行被注释
DBHost=localhost
//设置数据库名称
DBName=zabbix
//设置数据库账户
DBUser=zabbix
//设置数据库密码,默认该行被注释
DBPassword=Zabbix520!
//设置日志,仅查看以下即可
LogFile=/usr/local/zabbix/logs/zabbix_server.log
//不创建用户无法启动服务
[root@zabbix zabbix]# useradd -s /sbin/nologin zabbix
[root@zabbix zabbix]# chown -R zabbix:zabbix /usr/local/zabbix/*
[root@zabbix zabbix]# ./sbin/zabbix_server -c etc/zabbix_server.conf
[root@zabbix zabbix]# ss -tunlp | grep 10051
tcp LISTEN 0 128 *:10051 *:* users:(("zabbix_server",pid=12777,fd=4)
提示:如果是因为配置文件不对,导致服务无法启动时,不要重复执行启动zabbix_server,一定要先使用killall zabbix_server关闭服务后,再重新启动一次。
5、修改Zabbix_agent配置文件,启动Zabbix_agent服务
[root@zabbix zabbix]# vim etc/zabbix_agentd.conf
Server=127.0.0.1,192.168.2.10 //允许哪些主机监控本机
ServerActive=127.0.0.1,192.168.2.10 //允许哪些主机通过主动模式监控本机
Hostname=zabbix_server //设置本机主机名
LogFile=/usr/local/zabbix/logs/zabbix_agentd.log //设置日志文件
UnsafeUserParameters=1
[root@zabbix zabbix]# ./sbin/zabbix_agentd -c etc/zabbix_agentd.conf
[root@zabbix zabbix]# ss -tunlp | grep 10050
tcp LISTEN 0 128 *:10050 *:* users:(("zabbix_agentd",pid=13644,fd=4)
提示:如果是因为配置文件不对,导致服务无法启动时,不要重复执行启动zabbix_agentd,一定要先使用killall zabbix_agentd关闭服务后,再重新启动一次。
提示:
安装docker环境(可参考https://www.onemonitor.top/docs/kubernetes-jluo-20210715)
本次zabbix版本5.4.6
docker版本20.10.7
1、创建目录
mkdir /data/app/zabbix -p
cd /data/app/zabbix
mkdir data/mysql -p
mkdir data/zabbix_server/{alertscripts,data,externalscripts,fonts}
mkdir data/zabbix_agent/{scripts,zabbix_agentd.d}
2、字体设置
下载字体:https://www.aliyundrive.com/s/L5Pq25n3Aw3/folder/6177a1549a2694aeb21344a69a9638b65c5c8eb7
放到目录/data/app/zabbix/data/zabbix_server/fonts下
ls /data/app/zabbix/data/zabbix_server/fonts
DejaVuSans.ttf
3、编写yaml文件
cd /data/app/zabbix
vi docker-compose.yml
version: "3" #定义类型为 3
networks:
default:
external:
name: zabbix-net
services:
mysql-server:
image: mysql:5.7
hostname: mysql-zabbix
container_name: mysql-zabbix
restart: always
networks:
default:
ipv4_address: 172.88.88.9
ports:
- "3306:3306"
command:
--character-set-server=utf8 #定义字符集
environment:
MYSQL_ROOT_PASSWORD: 123456 #定义mysql root密码
MYSQL_DATABASE: zabbix # 创建数据库
MYSQL_USER: zabbix #定义用户
MYSQL_PASSWORD: 123456 #用户密码
volumes:
- ./data/mysql:/var/lib/mysql
- /etc/localtime:/etc/localtime:ro
zabbix-server:
image: zabbix/zabbix-server-mysql:5.4.6-centos
hostname: zabbix-server
container_name: zabbix-server
ports:
- "10051:10051" #声明端口
networks:
default:
ipv4_address: 172.88.88.11
environment:
DB_SERVER_HOST: mysql-zabbix #连接mysql
DB_SERVER_PORT: 3306 # 连接端口
MYSQL_DATABASE: zabbix
MYSQL_USER: zabbix
MYSQL_PASSWORD: 123456
ZBX_JAVAGATEWAY: zabbix-java-gateway
volumes:
- ./data/zabbix_server/data:/usr/lib/zabbix
- ./data/zabbix_server/alertscripts:/usr/lib/zabbix/alertscripts
- ./data/zabbix_server/externalscripts:/usr/lib/zabbix/externalscripts
- /etc/localtime:/etc/localtime
depends_on:
- mysql-server #在mysql启动之后再启动
- zabbix-java-gateway
zabbix-web:
image: zabbix/zabbix-web-nginx-mysql:5.4.6-centos #镜像
hostname: zabbix-web
container_name: zabbix-web
ports:
- "8080:8080" #声明端口
- "8443:8443"
networks:
default:
ipv4_address: 172.88.88.12
environment:
DB_SERVER_HOST: mysql-server #连接mysql
DB_SERVER_PORT: 3306 # 连接端口
MYSQL_DATABASE: zabbix
MYSQL_USER: zabbix
MYSQL_PASSWORD: 123456
PHP_TZ: Asia/Shanghai #声明时区为亚洲/上海
ZBX_SERVER_HOST: zabbix-server
volumes:
- ./data/zabbix_server/fonts/DejaVuSans.ttf:/usr/share/zabbix/assets/fonts/DejaVuSans.ttf #解决图形中文乱码字体
- /etc/localtime:/etc/localtime
depends_on:
- mysql-server #在mysql启动之后再启动
- zabbix-java-gateway
zabbix-java-gateway:
image: zabbix/zabbix-java-gateway:5.4.6-centos #镜像
hostname: zabbix-java-gateway
container_name: zabbix-java-gateway
restart: always
networks:
default:
ipv4_address: 172.88.88.10
zabbix-agent:
image: zabbix/zabbix-agent:5.4.6-centos
hostname: zabbix-agent
container_name: zabbix-agent
environment:
- ZBX_HOSTNAME=zabbix-agent
- ZBX_SERVER_HOST=zabbix-server
- ZBX_SERVER_PORT=10051
volumes:
- ./data/zabbix_agent/zabbix_agentd.d/:/etc/zabbix/zabbix_agentd.d/
- ./data/zabbix_agent/scripts/:/etc/zabbix/scripts/
ports:
- 10050:10050
networks:
default:
ipv4_address: 172.88.88.13
4、启动zabbix
docker network create -d bridge --subnet 172.88.88.0/24 zabbix-net
cd /data/app/zabbix
docker-compose up -d
docker ps
访问http://ip:8080
用户名:admin
密码:zabbix
5、钉钉告警设置
cd /data/app/zabbix/data/zabbix_server/alertscripts
vi dingding.sh
#!/bin/bash
to=$1
subject=$2
text=$3
#此处的 xxxxx 就是刚刚复制存留的 api 接口地址。
curl -i -X POST \
'https://oapi.dingtalk.com/robot/send?access_token=XXX' \
-H 'Content-type':'application/json' \
-d '
{
"msgtype": "text",
"text": {
"content": "'监控报警:''"$text"'"
},
"at":{
"atMobiles":[
"'"$1"'"
],
"isAtAll":false
}
}'
1、新建目录
mkdir /data/app/zabbix_agent -p
cd /data/app/zabbix_agent
mkdir data/zabbix_agent/{scripts,zabbix_agentd.d} -p
2、编写yaml
vi docker-compose.yml
version: "3" #定义类型为 3
networks:
zabbix-net:
driver: bridge
services:
zabbix-agent:
image: zabbix/zabbix-agent:5.4.6-centos
environment:
- ZBX_HOSTNAME=zabbix-agent-236
- ZBX_SERVER_HOST=192.168.110.239 #zabbix-server主机地址
- ZBX_SERVER_PORT=10051 #zabbix-server主机端口
volumes:
- ./data/zabbix_agent/zabbix_agentd.d/:/etc/zabbix/zabbix_agentd.d/
- ./data/zabbix_agent/scripts/:/etc/zabbix/scripts/
ports:
- 10050:10050
networks:
- zabbix-net
3、启动
cd /data/app/zabbix_agent
docker-compose up -d
从官网下载如下三个rpm包
监控项包括表空间、用户状态、实例状态、锁、大量等待事件、闪回区使用率等。此类监控项需要给其设置触发器,一旦出现异常,及时告警。
监控项包括常见的等待事件发生的次数,命中率、硬解析比例等。
下面表格中列出附件中模板的监控项
[root@iZ882wldxleZ iso]# ls
oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm
oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm
oracle-instantclient11.2-sqlplus-11.2.0.4.0-1.x86_64.rpm
[root@iZ882wldxleZ iso]# rpm -ivh *.rpm
Preparing... ################################# [100%]
Updating / installing...
1:oracle-instantclient11.2-basic-11################################# [ 33%]
2:oracle-instantclient11.2-devel-11################################# [ 67%]
3:oracle-instantclient11.2-sqlplus-################################# [100%]
https://pypi.org/project/cx-Oracle/5.2.1/#files
wget https://files.pythonhosted.org/packages/93/d8/3acdd4d3176a877a396647f55191549b8624f1157bf2e1ada6bb1f92615d/cx_Oracle-5.2.1-11g-py27-1.x86_64.rpm
wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
参考文档
https://www.cnblogs.com/ddzj01/p/10769448.html
1、前提
nginx编译安装时使用--with-http_stub_status_module开启状态页面模块
nginx配置
[root@zabbix ~]# vim /usr/local/nginx/conf/nginx.conf
location = /basic_status {
stub_status;
}
[root@zabbix ~]# /usr/local/nginx/sbin/nginx -s reload
[root@zabbix ~]# ss -tunlp | grep :80
[root@zabbix ~]# curl 10.0.4.16/basic_status
Active connections: 3
server accepts handled requests
31694 31694 33585
Reading: 0 Writing: 1 Waiting: 2
2、使用zabbix默认模板
zabbix引用模板
3、查看数据是否收集到,显然数据已经成功收集到了。
4、到此监控nginx就结束了。
5、创建聚合图形
手机扫一扫
移动阅读更方便
你可能感兴趣的文章