zabbix5.0 服务端安装配置
服务器停止firewall或者iptables和selinx
1: 临时停止
systemctl stop firewalld.service
setenforce 0
2:永久停止
systemctl stop firewalld.service
systemctl disable firewalld.service
setenforce 0
sed -i ‘s@SELINUX=*@SELINUX=disabled@gi’ /etc/sysconfig/selinux
获取zabbix源代码
1: debian包
https://repo.zabbix.com/zabbix/5.0/debian/pool/main/z/zabbix-release/
2: rpm包
https://repo.zabbix.com/zabbix/5.0/rhel/8/x86_64/
https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/
3:源码包
https://cdn.zabbix.com/zabbix/sources/stable/
依赖环境包安装
apt-get install build-essential gcc curl wget libsnmp-dev libcurl4-gnutls-dev libxml2-dev unixODBC unixODBC-dev chkconfig
下载zabbix5.0 并安装
root@debian1:/data/soft# cd /data/soft
root@debian1:/data/soft# wget https://cdn.zabbix.com/zabbix/sources/stable/5.0/zabbix-5.0.7.tar.gz
root@debian1:/data/soft# tar xf zabbix-5.0.7.tar.gz
root@debian1:/data/soft# cd zabbix-5.0.7
root@debian1:/data/soft/zabbix-5.0.7# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --enable-java --enable-proxy -with-mysql --with-net-snmp --with-libcurl --with-libxml2 --with-unixodbc --with-ssh2 --with-openipmi --with-openssl --with-java-gateway && make install
#参数说明
--prefix #编译安装路径
--enable-server #启动server端
--enable-agent #启动agent端
--with-mysql #编译连接mysql相关依赖包
--with-net-snmp #启动snmp相关,用于snmp监控设备
--with-libcurl #启动curl相关
--with-libxml2 #启动xml相关
--with-unixodbc #启动odbc相关用于监控数据库
--enable-java #启动java-agent 用于监控java类
报错处理方式
1 configure: error: MySQL library not found
#apt-get install libghc6-hsql-mysql-dev
2 configure: error: Jabber library not found
#apt-get install libphp-jabber
#apt-get install libnet-jabber-loudmouth-perl
#apt-get install jabber-dev
#apt-get install libiksemel-dev (* this packet important)
3 configure: error: Not found curl Library
#apt-get install libcurl4-openssl-dev
4 configure: error : Not found NET-SNMP library
#apt-get install libsnmp-dev
#apt-get install snmp
配置导入mysql
MySQL [(none)]> CREATE DATABASE `zabbix` /*!40100 DEFAULT CHARACTER SET utf8 */; #创建zabbinx数据库
MySQL [zabbix]> use zabbix; #切换zabbix数据库
MySQL [zabbix]> source /data/soft/zabbix-5.0.7/database/mysql/schema.sql; #导入表结构
MySQL [zabbix]> source /data/soft/zabbix-5.0.7/database/mysql/images.sql; #导入图片数据
MySQL [zabbix]> source /data/soft/zabbix-5.0.7/database/mysql/data.sql; #导入模块数据相关
配置zabbix-server文件
cat /usr/local/zabbix/etc/zabbix_server.conf
LogFile=/tmp/zabbix_server.log
DBHost=localhost
DBName=zabbix
DBUser=root
DBPassword=hanye131
DBSocket=/tmp/mysql.sock
ListenIP=0.0.0.0
Timeout=4
LogSlowQueries=3000
StatsAllowedIP=127.0.0.1
zabbix_server 和 zabbix_agent 启动脚本配置
cp zabbix-5.0.7/misc/init.d/fedora/core/zabbix_agentd /etc/init.d/
cp zabbix-5.0.7/misc/init.d/fedora/core/zabbix_server /etc/init.d/
chkconfig --add /etc/init.d/zabbix_server
chkconfig --add /etc/init.d/zabbix_agentd
sed -i 's/DAEMON=\/usr\/local\/sbin/DAEMON=\/usr\/local\/zabbix\/sbin/' /etc/init.d/zabbix_server
sed -i 's/DAEMON=\/usr\/local\/sbin/DAEMON=\/usr\/local\/zabbix\/sbin/' /etc/init.d/zabbix_agentd
配置php.ini文件
memory_limit = 256
post_max_size = 100M
upload_max_filesize=500M
max_execution_time=600
max_input_time=300
date.timezone=Asia/Shanghai
nginx配置支持zabbix的web端代码
server {
listen 80;
server_name _;
access_log /data/wwwlogs/access_nginx.log main;
root /data/soft/zabbix-5.0.7/ui;
index index.html index.htm index.php;
#error_page 404 /404.html;
#error_page 502 /502.html;
location /nginx_status {
stub_status on;
access_log off;
allow 192.168.31.0/24;
deny all;
}
location ~ [^/]\.php(/|$) {
#fastcgi_pass remote_php_ip:9000;
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
expires 30d;
access_log off;
}
location ~ .*\.(js|css)?$ {
expires 7d;
access_log off;
}
location ~ ^/(\.user.ini|\.ht|\.git|\.svn|\.project|LICENSE|README.md) {
deny all;
}
}
登录配置访问
下载配置文件
登录服务器 把文件上传存放到指定目录:
[root@k8s-master01 zabbix-5.0.7]# cd /data/soft/zabbix-5.0.7/ui/conf/
[root@k8s-master01 conf]# rz
在点击下一步 完成部署
默认账号Admin
默认密码为zabbix
修改语言为中文
配置客户端
编译安装server和agent,并支持将数据放入mysql数据中,可使用类似如下配置命令:
./configure --prefix=/usr/local/zabbix --enable-server ---enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-ssh2
如果仅安装server,并支持将数据库放入mysql数据库中,可使用类似如下配置命令:
./configure --prefix=/usr/local/zabbix --enable-server --with-mysql --with-net-snmp --with-libcurl
如果仅安装proxy,并支持将数据放入mysql数据库中,可使用类似如下配置命令:
./configure --prefix=/usr/local/zabbix --enable-proxy --with-net-snmp --with-mysql --with-ssh2
如果仅安装agent,可使用类似如下配置命令:
./configure --prefix=/usr/local/zabbix --enable-agent
而后编译安装zabbix即可:
#make install
客户端调用自带模板监控Mysql数据库
配置Mysql脚本
[root@k8s-master01 zabbix-5.0.7]# mkdir /var/lib/zabbix/
[root@k8s-master01 zabbix-5.0.7]# cat /usr/local/zabbix/etc/zabbix_agentd.conf
添加: Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/
进入/usr/local/zabbix/etc/zabbix_agentd.conf.d/目录
[root@k8s-master01 zabbix-5.0.7]# cd /usr/local/zabbix/etc/zabbix_agentd.conf.d/
[root@k8s-master01 zabbix_agentd.conf.d]# vim mysql_zabbix_agent_monionr.conf
#Mysql监控
UserParameter=mysql.ping[*],/usr/local/mysql/bin/mysqladmin -h"$1" -P"$2" ping
UserParameter=mysql.get_status_variables[*],/usr/local/mysql/bin/mysql -h"$1" -P"$2" -sNX -e "show global status"
UserParameter=mysql.version[*],/usr/local/mysql/bin/mysqladmin -s -h"$1" -P"$2" version
UserParameter=mysql.db.discovery[*],/usr/local/mysql/bin/mysql -h"$1" -P"$2" -sN -e "show databases"
UserParameter=mysql.dbsize[*],/usr/local/mysql/bin/mysql -h"$1" -P"$2" -sN -e "SELECT SUM(DATA_LENGTH + INDEX_LENGTH) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='$3'"
UserParameter=mysql.replication.discovery[*],/usr/local/mysql/bin/mysql -h"$1" -P"$2" -sNX -e "show slave status"
UserParameter=mysql.slave_status[*],/usr/local/mysql/bin/mysql -h"$1" -P"$2" -sNX -e "show slave status"
创建 /var/lib/zabbix/ 目录
[root@k8s-master01 shell]# cat /var/lib/zabbix/.my.cnf
[client]
user=root
password=hanye131
socket=/tmp/mysql.sock
zabbix添加客户端主机 并 关联 Mysql模板
简单的报错处理
[root@k8s-master01 shell]# zabbix_get -s 127.0.0.1 -k "ERP.status[anyou]"
sed: couldn't open temporary file /etc/sedQknkgv: Permission denied
修改
root@debian1:/usr/local# vim /usr/local/zabbix/shell/etc/zabbix_agentd.conf
新增: AllowRoot=1
重启客户端:
root@debian1:/usr/local/# /etc/init.d/zabbix-agent restart
zabbix 基础监控服务器
链接:https://pan.baidu.com/s/1QFYLvRFNqulAXxN_SurhaQ
提取码:9nig