页面“Zabbix 调用API 批量添加主机”与“Zabbix 5 4 and 3 LTS安装入门教程”之间的差异

来自linux中国网wiki
(页面间的差异)
跳到导航 跳到搜索
 
→‎pre
 
第1行: 第1行:
[[category:ops]] [[category:zabbix]]  
+
==站内资源==
=pre=
+
[[Zabbix 调用API 批量添加主机]]
 +
== zabbix server ==
 +
===pre ===
 +
[[lnmp]]
 +
这些是官网官方安装文档,记得一定要看
  
已有 salt [[Salt yum安装]]
+
https://www.zabbix.com/documentation/5.0/zh/manual/installation/install
  
可以见 批量添加 salt  Salt-ssh批量自动安装被控端minion
+
https://www.zabbix.com/documentation/3.0/manual/installation/install
  
=批量添加zabbix agent=
+
https://www.zabbix.org/wiki/InstallOnCentOS_RHEL
==直接用cmd.run==
 
  salt 'prod-mq03' cmd.run 'yum install  -y zabbix-agent' #systemctl  restart zabbix-agent  systemctl  enable zabbix-agent
 
  
==zabbix state.sls ==
+
[https://blog.csdn.net/qq_34156628/article/details/106844695 Python自动化运维-zabbix-监控系统的实现原理]
  有空要试一下
 
  
 +
<pre>wget -c  https://cdn.zabbix.com/zabbix/sources/stable/5.0/zabbix-5.0.12.tar.gz
 +
#https://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.0.8/zabbix-3.0.8.tar.gz
  
 +
#wget -c http://tenet.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.2.13/zabbix-2.2.13.tar.gz</pre>
  
 +
===#配置php变量===
 +
<pre>vi /etc/php.ini
  
 +
如果是php7.3
 +
find / -name php.ini
 +
/etc/php/7.3/cli/php.ini
 +
/etc/php/7.3/fpm/php.ini
  
[https://www.cnblogs.com/LYCong/p/7879805.html salt 使用state文件来配置zabbix客户端文件]
 
  
[https://blog.csdn.net/u011075143/article/details/78615691 salt 使用state文件来配置zabbix客户端文件]
+
date.timezone = Asia/Shanghai
 +
post_max_size = 32M
 +
max_execution_time = 300
 +
max_input_time = 300
 +
注:更改完之后需要重启nginx和php</pre>
  
[https://www.cnblogs.com/Jackie-Chen/articles/10795003.html SaltStack批量安装zabbix-agent(yum安装)]
+
===#安装zabbix所需的组件 ===
 +
<pre>yum -y install net-snmp-devel curl-devel
 +
#yum -y install curl curl-devel net-snmp net-snmp-devel perl-DBI php-gd php-xml php-bcmath
 +
groupadd zabbix && useradd -g zabbix zabbix
  
[https://www.cnblogs.com/xiewenming/p/7713660.html SaltStack安装zabbix-agent-第九篇]
+
#if debian10
 +
apt install libmariadb-dev-compat libmariadb-dev  libxml2-dev libsnmp-dev snmp  libxml++2.6-dev libevent-dev libcurl4-openssl-dev
  
[https://www.cnblogs.com/python-study/p/5504501.html SaltStack 使用pillar安装配置管理zabbix]
+
tar xvf zabbix-3.0.8.tar.gz && cd zabbix-3.0.8
 +
#tar xvf zabbix-2.2.13.tar.gz && cd zabbix-2.2.13
  
[https://blog.csdn.net/reblue520/article/details/76286843 saltstack自动化运维系列⑦SaltStack实践配置管理安装zabbix]
+
#./configure –enable-server –enable-agent –with-mysql –enable-ipv6 –with-net-snmp –with-libcurl –with-libxml2
  
[https://www.cnblogs.com/LYCong/p/7879805.html salt 使用state文件来源码安装和配置zabbix客户端文件]
+
##或者默认安装路径 make是不用的
 +
./configure --sysconfdir=/etc/zabbix --enable-server --enable-proxy --enable-agent --with-mysql=/usr/local/mysql/bin/mysql_config --with-net-snmp --with-libcurl --with-libxml2 && make install
  
=批量修改zabbix agent配置=
+
 
 +
#2021 5.0 lst 官方  不要忘记了make install
 +
./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 && make install
 +
 
 +
 
 +
#如果要配置 Zabbix server 和 Zabbix proxy 的源代码,您可以运行以下内容:
 +
./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
 +
 
 +
</pre>
 +
 
 +
===添加zabbix服务对应的端口(可以省略,但是官方建议有)===
 +
<pre>cat >>/etc/services<< EOF
 +
zabbix-agent 10050/tcp #Zabbix Agent
 +
zabbix-agent 10050/udp #Zabbix Agent
 +
zabbix-trapper 10051/tcp #Zabbix Trapper
 +
zabbix-trapper 10051/udp #Zabbix Trapper
 +
EOF</pre>
 +
 
 +
===配置文件===
 +
<pre>##好像是这个起效果的呢 –sysconfdir=/etc/zabbix 有这个,不用下面的命令了
 +
#vim /usr/local/etc/zabbix_server.conf
 +
#cd zabbix-2.0.7
 +
 
 +
#mkdir /etc/zabbix
 +
#cp conf/*.conf /etc/zabbix
 +
 
 +
mkdir /var/log/zabbix ;chown zabbix:zabbix /var/log/zabbix;
 +
 
 +
 
 +
#zabbix web代码 3.0
 +
mkdir -p /data/www/zabbix;
 +
cp -r frontends/php/* /data/www/zabbix
 +
 
 +
#5.0 web  参考 debian lnmp
 +
[https://wiki.linuxchina.net/index.php/Lnmp debina lnmp]
 +
cp -a  ui/* /var/www/html/z.cn
 +
 
 +
http://z.cn/setup.php #最后跑起来后 要下载配置文件的 有如mediawiki
 +
 
 +
 
 +
find / -name php.ini
 +
/etc/php/7.3/cli/php.ini
 +
/etc/php/7.3/fpm/php.ini
 +
 
 +
 
 +
 
 +
 
 +
 
 +
修改zabbix连接的数据库的用户名和密码
 +
vi /etc/zabbix/zabbix_server.conf
 +
 
 +
DBHost=127.0.0.1
 +
DBName=zabbix
 +
DBUser=zabbix
 +
DBPassword='123'
 +
DBPort=3306 #如果数据库是用sock文件的方式,这里可以是sock文件的路径
 +
 
 +
添加数据库Lib文件位置到/etc/ld.so.conf中,并使其生效
 +
echo ‘/usr/local/mysql/lib/mysql/’ >> /etc/ld.so.conf
 +
 
 +
ldconfig
 +
 
 +
为zabbix的启动、关闭和重启的脚本文件做链接,方便系统可以找得到
 +
 
 +
给zabbix服务端程序做软链接 我用默认的config 应该是不用的
 +
cd /usr/local/zabbix/bin/
 +
for i in *;do ln -s /usr/local/zabbix/bin/${i} /usr/bin/${i};done
 +
cd /usr/local/zabbix/sbin/
 +
for i in *;do ln -s /usr/local/zabbix/sbin/${i} /usr/sbin/${i};done
 +
 
 +
拷贝zabbix服务端和客户端启动脚本到/etc/init.d目录下.
 +
cp  misc/init.d/tru64/{zabbix_agentd,zabbix_server}  /etc/init.d/;chmod o+x /etc/init.d/zabbix_*
 +
  307  /etc/init.d/zabbix_server start
 +
  308  /etc/init.d/zabbix_server status
 +
 
 +
 
 +
#这些老的
 +
cd misc/init.d/
 +
cp fedora/core/zabbix_server /etc/init.d/
 +
cp fedora/core/zabbix_agentd /etc/init.d/
 +
chmod +x /etc/init.d/zabbix_agentd
 +
chmod +x /etc/init.d/zabbix_server
 +
 
 +
成功说明
 +
 
 +
 
 +
config.status: executing depfiles commands
 +
configure: WARNING: unrecognized options: --with-libxml
 +
 
 +
 
 +
 
 +
Libraries:              -lmariadb        -lnetsnmp    -lz -lpthread -levent    -lcurl -lm -ldl  -lresolv -lpcre
 +
    Configuration file:    /usr/local/etc/zabbix_server.conf
 +
    External scripts:      /usr/local/share/zabbix/externalscripts
 +
    Alert scripts:        /usr/local/share/zabbix/alertscripts
 +
    Modules:              /usr/local/lib/modules
 +
 
 +
  Enable proxy:          no
 +
 
 +
  Enable agent:          yes
 +
  Agent details:
 +
    TLS:                  no
 +
    Linker flags:                -rdynamic 
 +
    Libraries:              -lz -lpthread    -lcurl -lm -ldl  -lresolv -lpcre
 +
    Configuration file:    /usr/local/etc/zabbix_agentd.conf
 +
    Modules:              /usr/local/lib/modules
 +
 
 +
 
 +
 
 +
 
 +
</pre>
 +
 
 +
===3 Create Zabbix database===
 +
<pre>SQL scripts are provided for creating database schema and inserting the dataset
 +
#https://www.zabbix.com/documentation/3.0/manual/appendix/install/db_scripts
 +
#https://www.zabbix.com/documentation/2.2/manual/appendix/install/db_scripts
 +
 
 +
mysql>create database zabbix character set utf8 collate utf8_bin;;grant all on zabbix.* to zabbix@localhost identified by '123';flush privileges;
 +
 
 +
将zabbix源码包中的数据导入到新建的zabbix数据库
 +
##这个和老的版本有点不同 第一个是zabbix的数据库表结构,要先导入。
 +
 
 +
. /etc/profile
 +
cd ../..
 +
mysql -uroot -p'evan' zabbix< database/mysql/schema.sql
 +
mysql -uroot -p'evan' zabbix< database/mysql/images.sql
 +
mysql -uroot -p'evan' zabbix< database/mysql/data.sql
 +
 
 +
vi /etc/init.d/zabbix_server # 的可以不改,修改一下变量的值 因为我是默认用 configure
 +
# base zabbix dir
 +
BASEDIR=/usr/local
 +
# binary file
 +
ZABBIX_SUCKERD=$BASEDIR/sbin/zabbix_server</pre>
 +
 
 +
===fping的安装和使用详解===
 +
<pre>http://rickie622.blog.163.com/blog/static/2123881120121121111720941/
 +
http://netsecurity.51cto.com/art/201101/242200.htm
 +
#当然 下载zip包也是可以的
 +
git clone https://github.com/schweikert/fping.git
 +
cd fping
 +
./autogen.sh
 +
./configure
 +
make -j2 && make install
 +
 
 +
#修改一下配置文件
 +
vim /etc/zabbix_server.conf
 +
#vim /usr/local/etc/zabbix_server.conf
 +
FpingLocation=/usr/local/sbin/fping</pre>
 +
 
 +
===启动zabbix,并且添加开机自启动===
 +
<pre>service zabbix_server start
 +
service zabbix_agentd start #启动服务
 +
 
 +
chkconfig zabbix_server on
 +
chkconfig zabbix_agentd on #开机自启动
 +
 
 +
在Nginx服务中添加zabbix虚拟主机
 +
#vim /usr/local/nginx/conf/vhosts/monitor.conf
 +
 
 +
这些都不要,不然没有web安装向导的
 +
#cd zabbix/conf
 +
#cp zabbix.conf.php.example zabbix.conf.php ;
 +
#chmod 777 zabbix.conf.php
 +
 
 +
iptables -I INPUT -p tcp –dport 80 -j ACCEPT
 +
 
 +
zabbix server is not running
 +
Zabbix Server is not running: the information displayed may not be current
 +
http://song49.blog.51cto.com/4480450/1200151</pre>
 +
 
 +
===(4)设置zabbix服务IP和端口,name可以忽略===
 
<pre>
 
<pre>
Server=148.66.11.55
+
ps:
ServerActive=148.66.11.55
+
post_max_size = 16M
Hostname=prod-sns-mq01
+
PHP option “max_execution_time” 30 300 Fail
 +
PHP option “max_input_time” 60 300 Fail
 +
PHP option “date.timezone” unknown Fai
 +
date.timezone = Asia/Shanghai
  
 +
PHP option “always_populate_raw_post_data” must be set to “-1”
  
 +
port 10051
  
sed -i '/^Hostname/ s/.*/Hostname=zabbix_hk/' /etc/zabbix/zabbix_agentd.conf
+
Zabbix frontend is ready! The default user name is Admin, password zabbix.</pre>
 +
===超级用户密码修改 ===
 +
<pre>
 +
2.2 用户名第一个字母要大写 也就是Admin
 +
默认的用户名:admin 密码:zabbix
  
#zbx hostname
+
哪里改登录用户和密码呢
salt 'prod-mq03' cmd.run 'hostname'
+
use zabbix;
prod-mq03:
+
select userid,alias,passwd from users; #查看
    prod-mq03
 
  
 +
+--------+------------+----------------------------------+
 +
| userid | alias      | passwd                          |
 +
+--------+------------+----------------------------------+
 +
|      1 | Admin      | 5fce1b3e34b520afeffb37ce08c7cd66 |
  
#这里可以取出 hostname 作变量 和作循环
 
Server=148.66.01.05
 
ServerActive=148.66.01.05
 
  
myhost=`salt 'prod-mq03' cmd.run 'hostname' |sed -n '2p' |awk '{print $1}'`
+
#如果为zabbix 3.0  直接这样就行了
salt 'prod-sns-mq02' cmd.run "sed -i '/^Hostname/ s/.*/Hostname=$myhost/'  /etc/zabbix/zabbix_agentd.conf"
+
update users set passwd=MD5('12345') where userid=1;
  
#这个替换太多了 不太好写匹配  要如下添加 =  or  直接 inser 就是了
 
salt 'prod-mq03' cmd.run "sed -i '/^Server=/ s/.*/Server=$Server/'  /etc/zabbix/zabbix_agentd.conf"
 
salt 'prod-mq03' cmd.run "sed -i '/^ServerActive=/ s/.*/ServerActive=$ServerActive/'  /etc/zabbix/zabbix_agentd.conf"
 
  
 +
#zabbix 2.x
 +
重新开个终端,生成一个MD5加密的密码,这里密码设置的是redhat
  
注意  ""  结果不太对的
+
[root@localhost ~]# echo -n 12345678 |openssl md5 #-n就表示不输入回车符,不加-n,否则就不是这个结果了。
salt 'prod-sns-mq02' cmd.run "hostname |sed -n '2p' |awk '{print $1}'"
+
(stdin)= 25d55ad283aa400af464c76d713c07ad
prod-sns-mq02:
 
  
</pre>
+
接着上面的为admin用户设定一个密码
=利用api批量添加主机 =
+
 
zbx_server version 4.0
+
mysql> update users set passwd='25d55ad283aa400af464c76d713c07ad' where userid = '1';
 +
#或者直接使用update users set passwd=md5(“12345678”) where userid=’1′;
 +
Query OK, 1 row affected (0.01 sec)
 +
Rows matched: 1 Changed: 1 Warnings: 0
 +
 
 +
mysql> flush privileges;
 +
Query OK, 0 rows affected (0.01 sec)
 +
 
 +
mysql> quit
 +
Bye
 +
 
 +
zabbix登陆账户admin密码修改
 +
http://pvbutler.blog.51cto.com/7662323/1734003
 +
 
 +
yum install ntp ntpdate -y
 +
chkconfig ntpd on
 +
/etc/init.d/ntpd start
 +
 
 +
*/30 * * * * /usr/sbin/ntpdate pool.ntp.org
 +
 
 +
在29行这后添加
 +
sed -i ’29a user=mysql’ /etc/my.cnf
 +
sed -i ’29a character-set-server=utf8′ /etc/my.cnf
 +
sed -i ’29ainnodb_file_per_table=1′ /etc/my.cnf
 +
重启mysqld</pre>
 +
 
 +
===防火墙设置 ===
 +
<pre>这个要看一下先,尽量用严格些的防火墙设置
 +
 
 +
#on zabbix-agent
 +
 
 +
iptables -A INPUT -s zabbixserverip  -p tcp -m tcp --dport 10050 -m comment --comment "zabbix_server listen " -j ACCEPT
 +
#iptables -A INPUT -s zabbixserverip  -p tcp -m tcp --dport 10050 -m comment --comment "zabbix_agentd listen " -j ACCEPT
 +
 
 +
#这下面的防火墙rule 不要用
 +
vi /etc/sysconfig/iptables
 +
-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT
 +
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
 +
-A INPUT -m state –state NEW -m tcp -p tcp –dport 10050 -j ACCEPT
 +
-A INPUT -m state –state NEW -m tcp -p tcp –dport 10051 -j ACCEPT
 +
 
 +
/etc/init.d/iptables restart
 +
 
 +
中文在右上角的用户里面哦
 +
 
 +
Starting php_fpm /usr/local/php/bin/php-cgi: error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such file or directory
 +
failed
 +
 
 +
by default install the daemon binaries (zabbix_server, zabbix_agentd, zabbix_proxy) in /usr/local/sbin and the client binaries (zabbix_get, zabbix_sender) in /usr/local/bin.</pre>
  
== get token  获得自己的token ==
+
===4.0 5.2 图像显示字体乱码的解决方法===
===py2===
 
 
<pre>
 
<pre>
cat aip.sh
 
# -*- coding:utf-8 -*-
 
#py2
 
import urllib2
 
import json
 
#u zbx server ip or domain
 
url = 'http://myzabbix.com/api_jsonrpc.php'
 
header = {'Content-Type': 'application/json'}
 
  
req = json.dumps(
+
1.替换支持中文的字体
    {
+
#传输字体
        "jsonrpc": "2.0",
+
#50fbe46d4c5c        zabbix/zabbix-web-nginx-pgsql:alpine-5.2-latest
        "method": "user.login",
+
docker cp simkai.ttf 50fbe46d4c5c:/usr/share/zabbix/assets/fonts
        "params": {
 
            "user": "Admin",
 
            "password": "123456"
 
        },
 
        "id": 0,
 
    }
 
)
 
  
def auth():
+
cp  /root/STKAITI.TTF  /usr/share/zabbix/assets/fonts
    r = urllib2.Request(url=url, headers=header, data=req)
+
 
    response = urllib2.urlopen(r)
+
2.修改字体配置 php文件
    token = json.loads(response.read())
+
#修改 指定的字体 或者直接把你的家体改成和默认同名,而默认的那个先删除 连重启都不用 反正在docker
    print(token)
+
  grep  -rn  BX_GRAPH_FONT_NAM  /usr/share/zabbix/include/defines.inc.php
 +
67:define('ZBX_GRAPH_FONT_NAME', 'DejaVuSans'); // font file name
  
if __name__ == '__main__':
+
修改
 +
sed  -i  's!DejaVuSans!simkai!' include/defines.inc.php
 +
define('ZBX_GRAPH_FONT_NAME',          'simkai'); 
 +
</pre>
  
    auth()
+
===zabbix-get===
 +
<pre>
 +
root@zabbix-server ~]#zabbix_get  -s 10.3.10.139 -k "system.hostname"
 +
dev-hello-market
  
#token
 
{u'jsonrpc': u'2.0', u'result': u'1794bcbe6d818069bff5aa499a07a960', u'id': 0}
 
  
 +
不过使用zabbix_get时必须开启客户端被动模式,要求暴露客户端监听端口。
 
</pre>
 
</pre>
===py3===
+
[https://blog.csdn.net/cx55887/article/details/83818696 自动化监控--zabbix-get安装使用详解]
 +
 
 +
==第二 agent==
 
<pre>
 
<pre>
#!/usr/bin/env python
+
 
# Version = 3.5.2
+
#4.0 #centos7 快速安装和自动配置 2019年 8月23日 星期五 11时45分01秒 CST
# __auth__ = ''
+
 
import json
+
#国外
from urllib import request, parse
+
rpm -ivh http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
 +
 
 +
#国内
 +
https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
 +
 
 +
手工直接添加  repo文件 ,如果有时 不小心 像上次删除了 reop文件 一样 ,搞半天
 +
 
 +
cat <<EOF > /etc/yum.repos.d/zabbix.repo
 +
[zabbix]
 +
name=Zabbix Official Repository - \$basearch
 +
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/\$basearch/
 +
enabled=1
 +
gpgcheck=1
 +
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
 
   
 
   
ZABBIX_URL = 'http://z.cn'
+
[zabbix-non-supported]
ZABBIX_USERNAME = "Admin"
+
name=Zabbix Official Repository non-supported - \$basearch
ZABBIX_PASSWORD = "zabbix"
+
baseurl=https://mirrors.aliyun.com/zabbix/non-supported/rhel/7/\$basearch/
 +
enabled=1
 +
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
 +
gpgcheck=1
 +
EOF
 +
 
 +
curl https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX-A14FE591 \
 +
-o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
 
   
 
   
url = "{}/api_jsonrpc.php".format(ZABBIX_URL)
+
curl https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX \
header = {"Content-Type": "application/json"}
+
-o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
# auth user and password
+
 
data = {
+
 
    "jsonrpc": "2.0",
+
 
    "method": "user.login",
+
yum install zabbix-agent -y
    "params": {
+
 
        "user": ZABBIX_USERNAME,
+
yum install ntp  -y
        "password": ZABBIX_PASSWORD
+
timedatectl set-ntp true
    },
+
 
    "id": 1,
+
HOSTNAME=prod-java-02
}
+
 
# 由于API接收的是json字符串,故需要转化一下
+
#config
value = json.dumps(data).encode('utf-8')
+
sed -i "s/^Server=127.0.0.1/Server=172.16.1.9/ " /etc/zabbix/zabbix_agentd.conf
   
+
 
# 对请求进行包装
+
sed -i "s/^ServerActive=127.0.0.1/ServerActive=172.16.1.9/" /etc/zabbix/zabbix_agentd.conf
req = request.Request(url, headers=header, data=value)
+
sed  -i "s/^Hostname=Zabbix server/Hostname=test-market/" /etc/zabbix/zabbix_agentd.conf
   
+
 
# 验证并获取Auth ID
+
 
try:
+
 
    # 打开包装过的url
+
#这个用了HOSTNAME 变量  而上面的要指定hostname
    result = request.urlopen(req)
+
sed  -i 's/127.0.0.1/23.67.81.95/g' /etc/zabbix/zabbix_agentd.conf
except Exception as e:
+
sed -i "s/Hostname=Zabbix server/Hostname=${HOSTNAME}/g" /etc/zabbix/zabbix_agentd.conf
    print("Auth Failed, Please Check Your Name And Password:", e)
+
grep "^\s*[^# \t].*$" /etc/zabbix/zabbix_agentd.conf
else:
+
 
    response = result.read()
+
systemctl  enable  zabbix-agent.service
    # 上面获取的是bytes类型数据,故需要decode转化成字符串
+
systemctl restart zabbix-agent
    page = response.decode('utf-8')
+
 
    # 将此json字符串转化为python字典
+
 
    page = json.loads(page)
+
下面是老的信息 和解说
    result.close()
+
 
    print("Auth Successful. The Auth ID Is: {}".format(page.get('result')))
+
cat /etc/zabbix/zabbix_agentd.conf
 +
Hostname=主机名
 +
Server=zabbix server ip
 +
LogFile= 可以不改
  
 +
##最好这样3个
 +
Server=10.6.1.181
 +
ServerActive=10.6.1.181
 +
Hostname=zabbix-client-1
  
python3  tmp/zapi3.py
 
Auth Successful. The Auth ID Is: cef1be0881b355e801678036cdc8c685
 
  
</pre>
+
#rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/6/x86_64/zabbix-release-3.0-1.el6.noarch.rpm
 +
#rpm -ivh http://repo.zabbix.com/zabbix/2.2/rhel/6/x86_64/zabbix-release-2.2-1.el6.noarch.rpm
 +
#http://repo.zabbix.com/zabbix/2.0/rhel/5/x86_64/zabbix-release-2.0-1.el5.noarch.rpm
  
[https://blog.51cto.com/freshair/2132748 Python调用Zabbix api之从入门到放弃——登录并获取身份验证令牌]
 
  
[https://www.jianshu.com/p/7a014f316e35 zabbix api token获取]
+
rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
  
== 我们获取必要的相关信息 ,eg所有主机list信息==
+
</pre>
===获得 groupid ===
+
===agent on debian===
 
<pre>
 
<pre>
cat getgroupid.sh
+
#用系统的源
#获取指定groupid
+
apt-get install zabbix-agent
curl -s -X POST -H 'Content-Type:application/json' -d '
+
 
{
+
 
    "jsonrpc": "2.0",
+
#config 其实和yum的也一样 只是启动不一样而已
    "method": "hostgroup.get",
+
HOSTNAME=wiki
    "params": {
+
sed -i "s/^Server=127.0.0.1/Server=207.148.106.229/ " /etc/zabbix/zabbix_agentd.conf
        "output": "extend",
+
 
        "filter": {
+
sed -i "s/^ServerActive=127.0.0.1/ServerActive=207.148.106.229/" /etc/zabbix/zabbix_agentd.conf
            "name": [
+
sed  -i "s/^Hostname=Zabbix server/Hostname=wiki/" /etc/zabbix/zabbix_agentd.conf
                "Zabbix servers",
+
 
                "Linux servers",
+
grep "^\s*[^# \t].*$" /etc/zabbix/zabbix_agentd.conf
                "sns servers"
 
            ]
 
        }
 
    },                                       
 
    "auth": "1794bcbe6d818069bff5aa423a07a960",
 
    "id": 1
 
}'  http://myzabbix.com//api_jsonrpc.php | python3 -m json.tool
 
  
#这里的id一定是1
+
service zabbix-agent start
 +
 
 +
 
 +
zabbix_get -s 138.68.59.0 -k "system.hostname"
 +
 
 +
 
 +
#用zbx的源
 +
  https://repo.zabbix.com/zabbix/4.0/debian/pool/main/z/zabbix-release/zabbix-release_4.0-3+buster_all.deb       
 +
dpkg -i zabbix-release_stretch_all.deb
 +
# apt-get update
 
</pre>
 
</pre>
[https://www.cnblogs.com/zdoubly/p/9777122.html zabbix--api学习之路--get_hostgroup获取]
+
https://www.zabbix.com/documentation/3.2/manual/installation/install_from_packages/repository_installation
 +
 
 +
https://www.zabbix.com/documentation/4.0/zh/manual/installation/install_from_packages/rhel_centos#%E5%AE%89%E8%A3%85_agent
 +
 
 +
 
 +
国内zabbix源总结
 +
 
 +
https://www.cnblogs.com/caidingyu/p/11423089.html
 +
 
 +
https://blog.cactifans.com/2019/01/21/Zabbix%E5%9B%BD%E5%86%85%E6%BA%90%E4%BD%BF%E7%94%A8/
 +
 
 +
==docker zabbix 5.0==
 +
 
 +
[https://juejin.im/entry/57be598d0a2b58006cd17c0f 用 Zabbix 和 Docker 搭建监控平台]
 +
 
 +
 
 +
[https://outmanzzq.github.io/2018/08/12/zabbix-docker/ Docker Compose 快速搭建zabbix监控系统]
 +
 
 +
我的没有 zabbix web ui 明天搞一下
 +
暴露端口 8888 用于访问页面,10051 用于和 Zabbix-agent 通信;
  
https://www.zabbix.com/documentation/4.0/zh/manual/api/reference/hostgroup/get
+
[https://www.zabbix.com/cn/whats_new_5_0 Zabbix 5.0 LTS新功能]
  
=== templateid===
+
[https://www.cnblogs.com/itzgr/p/9963156.html  011.Docker Compose部署Zabbix实战 ]
 +
 
 +
[https://www.cnblogs.com/rongfengliang/p/12925792.html  zabbix docker-compose 运行配置 ]
 +
 
 +
==debian10 zabbix5==
 +
[https://blog.csdn.net/yudeyi123/article/details/113988937  Debian 10 Buster上安装和配置Zabbix 5.0]
 +
 
 +
 
 +
[https://blog.csdn.net/weixin_42257277/article/details/107582322  源码安装Zabbix5.0监控系统]
 +
 
 +
==Usage==
 +
5.0查看 Latest data -->右边 Graph
 +
 
 +
 
 +
 
 +
添加主机要添加 模板  不然 在监控--主机那 图形没东西
 +
https://www.zabbix.com/documentation/current/manual/quickstart/host
 +
 
 +
 
 +
[https://blog.csdn.net/zzy287dy/article/details/105814204?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control  zabbix将多台机器的数据聚合到一个图中]
 +
 
 +
==== 查看hostid====
 +
 
 +
http://z.cn/hosts.php?form=update&hostid=10084
 +
[https://blog.csdn.net/zuimeng520/article/details/89890802  一种简单的zabbix客户端 主机hostid查看方法]
 +
 
 +
==添加用户 和用户组==
 +
 
 +
添加用户前 要添加用户组 然后在里面指定用户是哪个组 看到哪些项目
 +
 
 +
[https://www.cnblogs.com/fanlong0212/p/12248049.html  zabbix4.4新建用户组和用户权限设置 ]
 +
 
 +
[https://www.zabbix.com/documentation/4.0/zh/manual/quickstart/login 登陆和配置用户]
 +
 
 +
 
 +
=Zabbix配置Telegram告警=
 
<pre>
 
<pre>
#!/bin/bash
 
#跑在我的freebsd12
 
#获取指定groupid
 
curl -s -X POST -H 'Content-Type:application/json' -d '
 
{
 
    "jsonrpc": "2.0",
 
    "method": "hostgroup.get",
 
    "params": {
 
        "output": "extend",
 
        "filter": {
 
            "name": [
 
                "Zabbix servers",
 
                "Linux servers"
 
            ]
 
        }
 
    },                                       
 
    "auth": "1794bcbe6d818069bff5aa423a07a960",
 
    "id": 1
 
}'  http://148.66.11.55/zabbix/api_jsonrpc.php | python3 -m json.tool
 
  
 
#output
 
"result": [
 
        {
 
            "groupid": "2",
 
            "name": "Linux servers",
 
            "internal": "0",
 
            "flags": "0"
 
        },
 
        {
 
            "groupid": "4",
 
            "name": "Zabbix servers",
 
  
 
</pre>
 
</pre>
  
=== hostadd===
+
https://www.zabbix.com/cn/integrations/telegram#tab:official1
  
https://www.zabbix.com/documentation/4.0/manual/api/reference/host/create
+
[https://blog.csdn.net/weixin_33699914/article/details/92336106 配置zabbix+telegram告警]
<pre>
 
批量添加版  用法 分别添加 ip and hostname
 
  
 +
[https://www.cnblogs.com/yeyu1314/p/10071279.html  zabbix+telegram的API接口(告警) ]
  
#!/bin/bash
+
[https://blog.51cto.com/13555423/2469571 Zabbix配置Telegram告警(无坑文档)]
#注释中文导致不成功
 
#"host": "'prod-sns-mq02'",    #这里一般改为你要的hostname
 
IP=(
 
40.243.52
 
41.102.111
 
40.218.197
 
40.216.19
 
)
 
HOSTNAME=(
 
prod-sns-php01
 
prod-sns-php02
 
prod-sns-mq01
 
prod-sns-mq03
 
)
 
  
myend=`expr ${#IP[@]} - 1`
+
[https://my.oschina.net/u/4302302/blog/3830481 zabbix 用Telegram报警!!!]
  
for no in `seq 0 ${myend}`
+
[https://www.cnblogs.com/yeyu1314/p/10071279.html zabbix+telegram的API接口(告警) ]
#for  no in `seq 2 3` #这个是手工决定 数量
 
do
 
  
curl -s -X POST -H 'Content-Type:application/json' -d '
+
= 故障及回顾=
{
+
<pre>
    "jsonrpc": "2.0",
+
问题1.  zabbix server 没有打开 10051端口 前端图形没显示
    "method": "host.create",
 
    "params": {
 
        "host": "'${HOSTNAME[$no]}'", 
 
 
 
        "interfaces": [
 
            {
 
                "type": 1,
 
                "main": 1,
 
                "useip": 1,
 
                "ip": "'${IP[$no]}'",
 
                "dns": "",
 
                "port": "10050"
 
            }
 
        ],
 
        "groups": [
 
            {
 
                "groupid": "2",
 
                "groupid": "16"
 
            }
 
        ],
 
        "templates": [
 
            {
 
                "templateid": "10001"
 
            }
 
        ]
 
      },
 
    "auth": "1794bcbe6d818069bff5aa4207a960",
 
    "id": 1
 
  }' http://zbx.com/zabbix/api_jsonrpc.php | python -m json.tool
 
 
done
 
  
#要添加多一个群组
+
版本zabbix 2.2
  
 +
没有看到 10051 是因为 
  
 +
DBPassword=‘123’ 改为 DBPassword=123
  
  
 +
日志查看
 +
tail  /tmp/zabbix_server.log
  
 +
14659:20170525:171042.257 [Z3001] connection to database 'zabbix' failed: [1045] Access denied for user 'zabbix'@'localhost' (using password: YES)
  
  
#!/bin/bash
+
正确如下
#注释中文导致不成功
+
[root@ zabbix]# netstat  -nlpt
#"host": "'prod-sns-mq02'",    #这里一般改为你要的hostname
+
Active Internet connections (only servers)
IP="
+
Proto Recv-Q Send-Q Local Address              Foreign Address            State      PID/Program name 
121.41.103.113
+
tcp        0     0 0.0.0.0:10051
+
</pre>
for node_ip in ${IP};
+
=== 经常报Zabbix agent on Zabbix server is unreachable for 5 minutes ===
do
+
<pre>
curl -s -X POST -H 'Content-Type:application/json' -d '
 
{
 
     "jsonrpc": "2.0",
 
    "method": "host.create",
 
    "params": {
 
        "host": "'prod-sns-es01'", 
 
 
 
        "interfaces": [
 
            {
 
                "type": 1,
 
                "main": 1,
 
                "useip": 1,
 
                "ip": "'${node_ip}'",
 
                "dns": "",
 
                "port": "10050"
 
            }
 
        ],
 
        "groups": [
 
            {
 
                "groupid": "2",
 
                "groupid": "16"
 
            }
 
        ],
 
        "templates": [
 
            {
 
                "templateid": "10001"
 
            }
 
        ]
 
      },
 
    "auth": "1794bcbe6d818069bff5aa423a07a960",
 
    "id": 1
 
}' http://148.66.11.55/zabbix/api_jsonrpc.php | python -m json.tool
 
done
 
  
#要添加多一个群组
+
我上次的处理是 重启 zbx server 就好了
  
 
</pre>
 
</pre>
 +
[https://medium.com/@pmatv/zabbix-compilation-dependencies-c545b7a3ad43 zabbix-compilation-dependencies]
  
==批量改 agent 配置==
+
 
===ssh 方式 ===
+
[https://blog.csdn.net/weixin_34226706/article/details/85080769 解决Zabbix使用一段时间后总报Zabbix Agent不可到达的问题]
 +
 
 +
[https://blog.csdn.net/weixin_33721344/article/details/92968417 防火墙导致 zabbix监控大批量报警zabbix agent on **** unreachable for 5 minute]
 +
 
 +
===zabbix server is running | No.解决方法===
 
<pre>
 
<pre>
 +
zabbix 5
  
IP=(
+
根据日志报错排查
172.31.27.83
+
cat /var/log/zabbix/zabbix_server.log
172.31.25.239
 
172.31.16.171
 
172.31.26.183
 
172.31.31.249
 
172.31.25.199
 
172.31.22.218
 
172.31.24.104
 
172.31.19.164
 
)
 
  
myend=`expr ${#IP[@]} - 1`
+
zabbix进程查看
 +
ps aux |grep zabbix
  
for  no in `seq 0 ${myend}`
+
查看监听zabbix server---------zabbix agent    10050---10051端口
do
+
netstat -nplut |grep zabbix
ssh -i  id_rsa -o "StrictHostKeyChecking no"  root@${IP[$no]} "sed -i 's!Server=148.66.11.55!Server=38.20.125.2!' /etc/zabbix/zabbix_agentd.conf && systemctl  restart zabbix-agent"
 
  
 +
登陆报错解决    zabbix server is running | No.
  
done
+
解决方法1
</pre>
 
  
=进阶=
+
setsebool -P httpd_can_network_connect on  selinux 允许它通过httpd服务
写成通用的py脚本  ?
 
  
[https://www.jianshu.com/p/e087cace8ddf 利用zabbix API(python)批量查询主机、模板、添加删除主机]
+
关闭selinux
  
[https://www.cnblogs.com/reblue520/p/7614347.html 通过zabbix自带api进行主机的批量添加操作信息填写成列表]
+
永久关闭vi /etc/selinux/config
  
 +
#SELINUX=disabled
  
 +
#SELINUXTYPE=targeted
  
[http://aishad.top/wordpress/?p=460 zabbix高级使用五:通过zabbix API添加监控主机has used]
+
临时关闭 setenforce 0
  
 +
关闭防火墙
  
 +
永久关闭 chkconfig iptables off
  
[https://blog.51cto.com/13120271/2163782 Zabbix 调用API 批量添加主机等]
+
临时生效 iptables -F
  
[https://blog.csdn.net/qq_34355232/article/details/83823680 zabbix api获取指定组中的主机的名字并将其修改]
+
解决方法2
  
[https://blog.csdn.net/weixin_42290927/article/details/88292931  zabbix 添加主机 API基础 ]
+
cd /etc/zabbix/web/
  
[https://blog.csdn.net/weixin_34107955/article/details/89821524 Zabbix 调用API 批量添加主机 (读取Excel)]
+
修改配置文件
  
 +
vi zabbix.conf.php
  
[https://blog.csdn.net/weixin_34242509/article/details/92306225 zabbix调用api接口批量添加主机]
+
修改lochlhost为 自己服务器的IP地址
  
=zabbix api 数据展示=
+
修改$DB['SERVER']  = '192.168.30.6';
  
[https://www.zhihu.com/question/62351896 如何通过zabbix的api获取前端最近20个问题?]
+
修改$ZBX_SERVER    = '192.168.30.6';
  
先 [https://blog.csdn.net/u011085172/article/details/77374879  python 通过zabbix api来获取当前trigger(告警)并打印出信息]
+
重启服务
[https://blog.csdn.net/u011085172/article/details/77480245  django bootstrap 获取zabbix告警信息并展示]
 
  
 +
service httpd restart
  
应该最终是出图
+
service zabbix-agent restart
  
[https://blog.csdn.net/weixin_39658619/article/details/111984197?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-5&spm=1001.2101.3001.4242 python做监控界面_Zabbix与Python不得不说的基情——用Python定制自己的zabbix界面]
+
service zabbix-server restart
  
[https://blog.csdn.net/qq_35465132/article/details/78963269?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-15.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-15.control  前端调用zabbix告警数据]
+
</pre>
  
=see also=
+
==参考==
  
[https://www.jianshu.com/p/1fdcc595fed0 python脚本对接zabbix API添加监控]
+
[https://www.howtoforge.com/tutorial/install-zabbix-monitoring-server-and-agent-on-debian-9/ Install Zabbix Monitoring Server and Agent on Debian]
  
[https://blog.csdn.net/wuyongpeng0912/article/details/108708053 Python调用Zabbix API实现自定义功能]
+
[https://www.cnblogs.com/yanjieli/p/13651859.html zabbix--5.0.2部署使用手册 ]
  
[https://segmentfault.com/a/1190000014241994 调用ZABBIX的API获取节点主机信息小记]
+
[https://blog.csdn.net/weixin_42743410/article/details/81482728  zabbix 3.0使用教程]
  
[https://www.cnblogs.com/ssgeek/p/9279775.html zabbix api的使用]
+
[http://blog.51cto.com/guoxh/2089204 Zabbix 3.0 详解:从添加主机到发送报警通知]
  
[https://blog.51cto.com/zengestudy/1850578 通过Zabbix API 添加host]
+
[https://my.oschina.net/zhouyuntai/blog/1788830 Zabbix监控系统 (3) 之 添加自定义监控项目、配置邮件告警、测试告警]
  
[https://www.cnblogs.com/wumingxiaoyao/p/7478749.html python3 + zabbix api 的使用]
+
http://blog.linuxchina.net/?p=1711
  
[https://blog.csdn.net/yqw7410/article/details/105619139?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-0&spm=1001.2101.3001.4242 基于Zabbix api二次封装开发_获取数据和页面展示]
+
[https://www.cnblogs.com/enjoycode/p/zabbix_3_installation_on_centos_7.html  Zabbix 3.0  with apache安装笔记]
  
 +
[https://www.cnblogs.com/zhenglisai/p/6547402.html 【zabbix】自定义监控项key值]
  
[https://blog.csdn.net/sdewendong/article/details/103583236?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-4.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-4.control  zabbix二次开发详细例子说明]
 
  
 +
[https://blog.csdn.net/zhengchaooo/article/details/79499991 zabbix添加自定义py脚本]
  
[https://blog.csdn.net/lihaiyong92/article/details/83057584?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-3.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-3.control  通过http请求 zabbix api 获取监控的流量数据]
+
[https://juejin.cn/entry/6844903442452856845 用 Zabbix 和 Docker 搭建监控平台]
  
[https://blog.51cto.com/nginxs/1889120  运维python进行(三) 用python写一个自己zabbix的调用方法 原创 ]
+
 [[category:zabbix]]

2021年7月10日 (六) 13:13的版本

站内资源

Zabbix 调用API 批量添加主机

zabbix server

pre

lnmp 这些是官网官方安装文档,记得一定要看

https://www.zabbix.com/documentation/5.0/zh/manual/installation/install

https://www.zabbix.com/documentation/3.0/manual/installation/install

https://www.zabbix.org/wiki/InstallOnCentOS_RHEL

Python自动化运维-zabbix-监控系统的实现原理

wget -c  https://cdn.zabbix.com/zabbix/sources/stable/5.0/zabbix-5.0.12.tar.gz
#https://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.0.8/zabbix-3.0.8.tar.gz

#wget -c http://tenet.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.2.13/zabbix-2.2.13.tar.gz

#配置php变量

vi /etc/php.ini

如果是php7.3 
find / -name php.ini
/etc/php/7.3/cli/php.ini
/etc/php/7.3/fpm/php.ini


date.timezone = Asia/Shanghai
post_max_size = 32M
max_execution_time = 300
max_input_time = 300
注:更改完之后需要重启nginx和php

#安装zabbix所需的组件

yum -y install net-snmp-devel curl-devel
#yum -y install curl curl-devel net-snmp net-snmp-devel perl-DBI php-gd php-xml php-bcmath
groupadd zabbix && useradd -g zabbix zabbix

#if debian10 
apt install libmariadb-dev-compat libmariadb-dev  libxml2-dev libsnmp-dev snmp  libxml++2.6-dev libevent-dev libcurl4-openssl-dev

tar xvf zabbix-3.0.8.tar.gz && cd zabbix-3.0.8
#tar xvf zabbix-2.2.13.tar.gz && cd zabbix-2.2.13

#./configure –enable-server –enable-agent –with-mysql –enable-ipv6 –with-net-snmp –with-libcurl –with-libxml2

##或者默认安装路径 make是不用的
./configure --sysconfdir=/etc/zabbix --enable-server --enable-proxy --enable-agent --with-mysql=/usr/local/mysql/bin/mysql_config --with-net-snmp --with-libcurl --with-libxml2 && make install


#2021 5.0 lst 官方  不要忘记了make install 
./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 && make install 


#如果要配置 Zabbix server 和 Zabbix proxy 的源代码,您可以运行以下内容:
./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2

添加zabbix服务对应的端口(可以省略,但是官方建议有)

cat >>/etc/services<< EOF
zabbix-agent 10050/tcp #Zabbix Agent
zabbix-agent 10050/udp #Zabbix Agent
zabbix-trapper 10051/tcp #Zabbix Trapper
zabbix-trapper 10051/udp #Zabbix Trapper
EOF

配置文件

##好像是这个起效果的呢 –sysconfdir=/etc/zabbix 有这个,不用下面的命令了
#vim /usr/local/etc/zabbix_server.conf
#cd zabbix-2.0.7

#mkdir /etc/zabbix
#cp conf/*.conf /etc/zabbix

mkdir /var/log/zabbix ;chown zabbix:zabbix /var/log/zabbix;


#zabbix web代码 3.0
mkdir -p /data/www/zabbix;
cp -r frontends/php/* /data/www/zabbix

#5.0 web  参考 debian lnmp 
[https://wiki.linuxchina.net/index.php/Lnmp debina lnmp]
cp -a  ui/* /var/www/html/z.cn

http://z.cn/setup.php #最后跑起来后 要下载配置文件的 有如mediawiki


find / -name php.ini
/etc/php/7.3/cli/php.ini
/etc/php/7.3/fpm/php.ini





修改zabbix连接的数据库的用户名和密码
vi /etc/zabbix/zabbix_server.conf

DBHost=127.0.0.1
DBName=zabbix
DBUser=zabbix
DBPassword='123'
DBPort=3306 #如果数据库是用sock文件的方式,这里可以是sock文件的路径

添加数据库Lib文件位置到/etc/ld.so.conf中,并使其生效
echo ‘/usr/local/mysql/lib/mysql/’ >> /etc/ld.so.conf

ldconfig

为zabbix的启动、关闭和重启的脚本文件做链接,方便系统可以找得到

给zabbix服务端程序做软链接 我用默认的config 应该是不用的
cd /usr/local/zabbix/bin/
for i in *;do ln -s /usr/local/zabbix/bin/${i} /usr/bin/${i};done
cd /usr/local/zabbix/sbin/
for i in *;do ln -s /usr/local/zabbix/sbin/${i} /usr/sbin/${i};done

拷贝zabbix服务端和客户端启动脚本到/etc/init.d目录下.
cp  misc/init.d/tru64/{zabbix_agentd,zabbix_server}  /etc/init.d/;chmod o+x /etc/init.d/zabbix_*
  307  /etc/init.d/zabbix_server start 
  308  /etc/init.d/zabbix_server status 


#这些老的 
cd misc/init.d/
cp fedora/core/zabbix_server /etc/init.d/
cp fedora/core/zabbix_agentd /etc/init.d/
chmod +x /etc/init.d/zabbix_agentd
chmod +x /etc/init.d/zabbix_server

成功说明


config.status: executing depfiles commands
configure: WARNING: unrecognized options: --with-libxml



 Libraries:              -lmariadb        -lnetsnmp    -lz -lpthread -levent    -lcurl -lm -ldl  -lresolv -lpcre 
    Configuration file:    /usr/local/etc/zabbix_server.conf
    External scripts:      /usr/local/share/zabbix/externalscripts
    Alert scripts:         /usr/local/share/zabbix/alertscripts
    Modules:               /usr/local/lib/modules

  Enable proxy:          no

  Enable agent:          yes
  Agent details:
    TLS:                   no
    Linker flags:                -rdynamic   
    Libraries:              -lz -lpthread    -lcurl -lm -ldl  -lresolv -lpcre 
    Configuration file:    /usr/local/etc/zabbix_agentd.conf
    Modules:               /usr/local/lib/modules




3 Create Zabbix database

SQL scripts are provided for creating database schema and inserting the dataset
#https://www.zabbix.com/documentation/3.0/manual/appendix/install/db_scripts
#https://www.zabbix.com/documentation/2.2/manual/appendix/install/db_scripts

mysql>create database zabbix character set utf8 collate utf8_bin;;grant all on zabbix.* to zabbix@localhost identified by '123';flush privileges;

将zabbix源码包中的数据导入到新建的zabbix数据库
##这个和老的版本有点不同 第一个是zabbix的数据库表结构,要先导入。

. /etc/profile
cd ../..
mysql -uroot -p'evan' zabbix< database/mysql/schema.sql
mysql -uroot -p'evan' zabbix< database/mysql/images.sql
mysql -uroot -p'evan' zabbix< database/mysql/data.sql

vi /etc/init.d/zabbix_server # 的可以不改,修改一下变量的值 因为我是默认用 configure
# base zabbix dir
BASEDIR=/usr/local
# binary file
ZABBIX_SUCKERD=$BASEDIR/sbin/zabbix_server

fping的安装和使用详解

http://rickie622.blog.163.com/blog/static/2123881120121121111720941/
http://netsecurity.51cto.com/art/201101/242200.htm
#当然 下载zip包也是可以的
git clone https://github.com/schweikert/fping.git
cd fping
./autogen.sh
./configure
make -j2 && make install

#修改一下配置文件
vim /etc/zabbix_server.conf
#vim /usr/local/etc/zabbix_server.conf
FpingLocation=/usr/local/sbin/fping

启动zabbix,并且添加开机自启动

service zabbix_server start
service zabbix_agentd start #启动服务

chkconfig zabbix_server on
chkconfig zabbix_agentd on #开机自启动

在Nginx服务中添加zabbix虚拟主机
#vim /usr/local/nginx/conf/vhosts/monitor.conf

这些都不要,不然没有web安装向导的
#cd zabbix/conf
#cp zabbix.conf.php.example zabbix.conf.php ;
#chmod 777 zabbix.conf.php

iptables -I INPUT -p tcp –dport 80 -j ACCEPT

zabbix server is not running
Zabbix Server is not running: the information displayed may not be current
http://song49.blog.51cto.com/4480450/1200151

(4)设置zabbix服务IP和端口,name可以忽略

ps:
post_max_size = 16M
PHP option “max_execution_time” 30 300 Fail
PHP option “max_input_time” 60 300 Fail
PHP option “date.timezone” unknown Fai
date.timezone = Asia/Shanghai

PHP option “always_populate_raw_post_data” must be set to “-1”

port 10051

Zabbix frontend is ready! The default user name is Admin, password zabbix.

超级用户密码修改

2.2 用户名第一个字母要大写 也就是Admin
默认的用户名:admin 密码:zabbix

哪里改登录用户和密码呢
use zabbix;
select userid,alias,passwd from users; #查看

+--------+------------+----------------------------------+
| userid | alias      | passwd                           |
+--------+------------+----------------------------------+
|      1 | Admin      | 5fce1b3e34b520afeffb37ce08c7cd66 |


#如果为zabbix 3.0  直接这样就行了 
update users set passwd=MD5('12345') where userid=1;


#zabbix 2.x 
重新开个终端,生成一个MD5加密的密码,这里密码设置的是redhat

[root@localhost ~]# echo -n 12345678 |openssl md5 #-n就表示不输入回车符,不加-n,否则就不是这个结果了。
(stdin)= 25d55ad283aa400af464c76d713c07ad

接着上面的为admin用户设定一个密码

mysql> update users set passwd='25d55ad283aa400af464c76d713c07ad' where userid = '1';
#或者直接使用update users set passwd=md5(“12345678”) where userid=’1′;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> quit
Bye

zabbix登陆账户admin密码修改
http://pvbutler.blog.51cto.com/7662323/1734003

yum install ntp ntpdate -y
chkconfig ntpd on
/etc/init.d/ntpd start

*/30 * * * * /usr/sbin/ntpdate pool.ntp.org

在29行这后添加
sed -i ’29a user=mysql’ /etc/my.cnf
sed -i ’29a character-set-server=utf8′ /etc/my.cnf
sed -i ’29ainnodb_file_per_table=1′ /etc/my.cnf
重启mysqld

防火墙设置

这个要看一下先,尽量用严格些的防火墙设置

#on zabbix-agent

iptables -A INPUT -s zabbixserverip  -p tcp -m tcp --dport 10050 -m comment --comment "zabbix_server listen " -j ACCEPT 
#iptables -A INPUT -s zabbixserverip  -p tcp -m tcp --dport 10050 -m comment --comment "zabbix_agentd listen " -j ACCEPT 

#这下面的防火墙rule 不要用 
vi /etc/sysconfig/iptables
-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 10050 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 10051 -j ACCEPT

/etc/init.d/iptables restart

中文在右上角的用户里面哦

Starting php_fpm /usr/local/php/bin/php-cgi: error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such file or directory
failed

by default install the daemon binaries (zabbix_server, zabbix_agentd, zabbix_proxy) in /usr/local/sbin and the client binaries (zabbix_get, zabbix_sender) in /usr/local/bin.

4.0 5.2 图像显示字体乱码的解决方法


1.替换支持中文的字体
#传输字体
#50fbe46d4c5c        zabbix/zabbix-web-nginx-pgsql:alpine-5.2-latest
docker cp simkai.ttf 50fbe46d4c5c:/usr/share/zabbix/assets/fonts

 cp  /root/STKAITI.TTF  /usr/share/zabbix/assets/fonts
  
2.修改字体配置 php文件
 #修改 指定的字体 或者直接把你的家体改成和默认同名,而默认的那个先删除 连重启都不用 反正在docker
  grep  -rn  BX_GRAPH_FONT_NAM   /usr/share/zabbix/include/defines.inc.php
67:define('ZBX_GRAPH_FONT_NAME',		'DejaVuSans'); // font file name

修改
sed  -i  's!DejaVuSans!simkai!' include/defines.inc.php
define('ZBX_GRAPH_FONT_NAME',           'simkai');  

zabbix-get

root@zabbix-server ~]#zabbix_get  -s 10.3.10.139 -k "system.hostname"
dev-hello-market


不过使用zabbix_get时必须开启客户端被动模式,要求暴露客户端监听端口。

自动化监控--zabbix-get安装使用详解

第二 agent


#4.0 #centos7 快速安装和自动配置 2019年 8月23日 星期五 11时45分01秒 CST

#国外
rpm -ivh http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm

#国内
https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm

手工直接添加  repo文件 ,如果有时 不小心 像上次删除了 reop文件 一样 ,搞半天 

cat <<EOF > /etc/yum.repos.d/zabbix.repo
[zabbix]
name=Zabbix Official Repository - \$basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/\$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
 
[zabbix-non-supported]
name=Zabbix Official Repository non-supported - \$basearch
baseurl=https://mirrors.aliyun.com/zabbix/non-supported/rhel/7/\$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1
EOF

curl https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX-A14FE591 \
-o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
 
curl https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX \
-o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX



yum install zabbix-agent -y

yum install ntp  -y
timedatectl set-ntp true

HOSTNAME=prod-java-02

#config
sed -i "s/^Server=127.0.0.1/Server=172.16.1.9/ " /etc/zabbix/zabbix_agentd.conf

sed -i "s/^ServerActive=127.0.0.1/ServerActive=172.16.1.9/"  /etc/zabbix/zabbix_agentd.conf
sed  -i "s/^Hostname=Zabbix server/Hostname=test-market/"  /etc/zabbix/zabbix_agentd.conf



#这个用了HOSTNAME 变量  而上面的要指定hostname
sed  -i 's/127.0.0.1/23.67.81.95/g'  /etc/zabbix/zabbix_agentd.conf
sed  -i "s/Hostname=Zabbix server/Hostname=${HOSTNAME}/g"  /etc/zabbix/zabbix_agentd.conf
grep "^\s*[^# \t].*$" /etc/zabbix/zabbix_agentd.conf

systemctl  enable  zabbix-agent.service
systemctl restart zabbix-agent


下面是老的信息 和解说

cat /etc/zabbix/zabbix_agentd.conf
Hostname=主机名
Server=zabbix server ip
LogFile= 可以不改

##最好这样3个
Server=10.6.1.181
ServerActive=10.6.1.181
Hostname=zabbix-client-1


#rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/6/x86_64/zabbix-release-3.0-1.el6.noarch.rpm
#rpm -ivh http://repo.zabbix.com/zabbix/2.2/rhel/6/x86_64/zabbix-release-2.2-1.el6.noarch.rpm
#http://repo.zabbix.com/zabbix/2.0/rhel/5/x86_64/zabbix-release-2.0-1.el5.noarch.rpm


rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm

 

agent on debian

#用系统的源 
 apt-get install zabbix-agent


#config 其实和yum的也一样 只是启动不一样而已
HOSTNAME=wiki
sed -i "s/^Server=127.0.0.1/Server=207.148.106.229/ " /etc/zabbix/zabbix_agentd.conf

sed -i "s/^ServerActive=127.0.0.1/ServerActive=207.148.106.229/"  /etc/zabbix/zabbix_agentd.conf
sed  -i "s/^Hostname=Zabbix server/Hostname=wiki/"  /etc/zabbix/zabbix_agentd.conf

grep "^\s*[^# \t].*$" /etc/zabbix/zabbix_agentd.conf

service zabbix-agent start


 zabbix_get -s 138.68.59.0 -k "system.hostname"


#用zbx的源
  https://repo.zabbix.com/zabbix/4.0/debian/pool/main/z/zabbix-release/zabbix-release_4.0-3+buster_all.deb        
dpkg -i zabbix-release_stretch_all.deb
# apt-get update

https://www.zabbix.com/documentation/3.2/manual/installation/install_from_packages/repository_installation

https://www.zabbix.com/documentation/4.0/zh/manual/installation/install_from_packages/rhel_centos#%E5%AE%89%E8%A3%85_agent


国内zabbix源总结

https://www.cnblogs.com/caidingyu/p/11423089.html

https://blog.cactifans.com/2019/01/21/Zabbix%E5%9B%BD%E5%86%85%E6%BA%90%E4%BD%BF%E7%94%A8/

docker zabbix 5.0

用 Zabbix 和 Docker 搭建监控平台


Docker Compose 快速搭建zabbix监控系统

我的没有 zabbix web ui 明天搞一下 暴露端口 8888 用于访问页面,10051 用于和 Zabbix-agent 通信;

Zabbix 5.0 LTS新功能

011.Docker Compose部署Zabbix实战

zabbix docker-compose 运行配置

debian10 zabbix5

Debian 10 Buster上安装和配置Zabbix 5.0


源码安装Zabbix5.0监控系统

Usage

5.0查看 Latest data -->右边 Graph


添加主机要添加 模板  不然 在监控--主机那 图形没东西 

https://www.zabbix.com/documentation/current/manual/quickstart/host


zabbix将多台机器的数据聚合到一个图中

查看hostid

http://z.cn/hosts.php?form=update&hostid=10084 一种简单的zabbix客户端 主机hostid查看方法

添加用户 和用户组

添加用户前 要添加用户组 然后在里面指定用户是哪个组 看到哪些项目

zabbix4.4新建用户组和用户权限设置

登陆和配置用户


Zabbix配置Telegram告警



https://www.zabbix.com/cn/integrations/telegram#tab:official1

配置zabbix+telegram告警

zabbix+telegram的API接口(告警)

Zabbix配置Telegram告警(无坑文档)

zabbix 用Telegram报警!!!

zabbix+telegram的API接口(告警)

故障及回顾

问题1.  zabbix server 没有打开 10051端口 前端图形没显示 

版本zabbix 2.2 

没有看到 10051 是因为  

DBPassword=‘123’ 改为 DBPassword=123


日志查看 
 tail  /tmp/zabbix_server.log

14659:20170525:171042.257 [Z3001] connection to database 'zabbix' failed: [1045] Access denied for user 'zabbix'@'localhost' (using password: YES)


正确如下 
[root@ zabbix]# netstat  -nlpt 
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:10051

经常报Zabbix agent on Zabbix server is unreachable for 5 minutes


我上次的处理是 重启 zbx server 就好了 

zabbix-compilation-dependencies


解决Zabbix使用一段时间后总报Zabbix Agent不可到达的问题

防火墙导致 zabbix监控大批量报警zabbix agent on **** unreachable for 5 minute

zabbix server is running | No.解决方法

zabbix 5 

根据日志报错排查
cat /var/log/zabbix/zabbix_server.log

zabbix进程查看
ps aux |grep zabbix

查看监听zabbix server---------zabbix agent    10050---10051端口
netstat -nplut |grep zabbix

登陆报错解决    zabbix server is running | No.

解决方法1

setsebool -P httpd_can_network_connect on   selinux 允许它通过httpd服务

关闭selinux

永久关闭vi /etc/selinux/config

#SELINUX=disabled

#SELINUXTYPE=targeted

临时关闭 setenforce 0 

关闭防火墙

永久关闭 chkconfig iptables off

临时生效 iptables -F

解决方法2

cd /etc/zabbix/web/

修改配置文件

vi zabbix.conf.php

修改lochlhost为 自己服务器的IP地址

修改$DB['SERVER']   = '192.168.30.6';

修改$ZBX_SERVER     = '192.168.30.6';

重启服务

service httpd restart

service zabbix-agent restart

service zabbix-server restart

参考

Install Zabbix Monitoring Server and Agent on Debian

zabbix--5.0.2部署使用手册

zabbix 3.0使用教程

Zabbix 3.0 详解:从添加主机到发送报警通知

Zabbix监控系统 (3) 之 添加自定义监控项目、配置邮件告警、测试告警

http://blog.linuxchina.net/?p=1711

Zabbix 3.0 with apache安装笔记

【zabbix】自定义监控项key值


zabbix添加自定义py脚本

用 Zabbix 和 Docker 搭建监控平台