2-27 使用zabbix监控服务器运行状态

Posted 喝茶等下班

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2-27 使用zabbix监控服务器运行状态相关的知识,希望对你有一定的参考价值。

在lnmp下,注意zabbix页面是运行在php下的,所以必须安装PHP

1.

创建zabbix数据库

mysql> create database zabbix;
Query OK, 1 row affected (0.00 sec)

mysql> grant all on zabbix.* to zabbix@localhost identified by zabbix;
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)

mysql> grant all on zabbix.* to zabbix@localhost identified by zabbix;
Query OK, 0 rows affected, 1 warning (0.00 sec)

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

mysql> \\q
Bye

2.

解压zabbix包

[root@xuegod13 opt]# tar xf zabbix-3.4.3.tar.gz -C /usr/local/src/
[root@xuegod13 opt]# cd /usr/local/src/
[root@xuegod13 src]# ls
boost_1_59_0 mysql-5.7.19 nginx-1.14.2 pcre-8.41 php-7.1.24 zabbix-3.4.3
[root@xuegod13 src]# cd zabbix-3.4.3/
[root@xuegod13 zabbix-3.4.3]# ls
aclocal.m4 compile configure.ac include Makefile.in README
AUTHORS conf COPYING INSTALL man sass
bin config.guess database install-sh misc src
build config.sub depcomp m4 missing upgrades
ChangeLog configure frontends Makefile.am NEWS

3.

导入zabbix数据库备份

[root@xuegod13 zabbix-3.4.3]# cd database/
[root@xuegod13 database]# ls
ibm_db2 Makefile.am Makefile.in mysql oracle postgresql sqlite3
[root@xuegod13 database]# cd mysql/
[root@xuegod13 mysql]# ls
data.sql images.sql schema.sql
[root@xuegod13 mysql]# mysql -uzabbix -pzabbix zabbix < schema.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@xuegod13 mysql]# mysql -uzabbix -pzabbix zabbix < images.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@xuegod13 mysql]# mysql -uzabbix -pzabbix zabbix < data.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@xuegod13 mysql]#

注意,这里导入有个顺序,先导入schema.sql 再导入images.sql 最后导入data.sql。顺序不能乱,否则会报错

4.

添加用户和组

[root@xuegod13 opt]# groupadd zabbix
[root@xuegod13 opt]# useradd -s /sbin/nologin -g zabbix zabbix

yum安装插件

#这个是网络管理协议
[root@xuegod13 opt]# yum install -y net-snmp-devel
#安装依赖包
[root@xuegod13 opt]# yum install libevent libevent-devel -y

源码安装

[root@xuegod13 zabbix-3.4.3]# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql=/var/lib/mysql/bin/mysql_config --with-net-snmp --with-libcurl
#zabbix没有make阶段,直接make install
[root@xuegod13 zabbix-3.4.3]# make install

5.

修改配置文件

[root@xuegod13 zabbix-3.4.3]# ll /usr/local/zabbix/
总用量 0
drwxr-xr-x 2 root root 45 223 18:40 bin
drwxr-xr-x 4 root root 114 223 18:40 etc
drwxr-xr-x 2 root root 6 223 18:40 lib
drwxr-xr-x 2 root root 48 223 18:40 sbin
drwxr-xr-x 4 root root 31 223 18:40 share
[root@xuegod13 zabbix-3.4.3]# cd /usr/local/zabbix/
[root@xuegod13 zabbix]# cd etc/
[root@xuegod13 etc]# ls
zabbix_agentd.conf zabbix_server.conf
zabbix_agentd.conf.d zabbix_server.conf.d
[root@xuegod13 etc]# vim zabbix_server.conf
#跳转到85行,修改如下
DBHost=xuegod13
#119行
DBPassword=zabbix
#修改客户端
[root@xuegod13 etc]# vim zabbix_agentd.conf
#280行
UnsafeUserParameters=1

6.

启动脚本

[root@xuegod13 zabbix]# pwd
/usr/local/zabbix
[root@xuegod13 zabbix]# cd sbin/
[root@xuegod13 sbin]# ls
zabbix_agentd zabbix_server
[root@xuegod13 sbin]# ./zabbix_server #执行报错
./zabbix_server: error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory
[root@xuegod13 sbin]# ldd zabbix_server
linux-vdso.so.1 => (0x00007fff76ffc000)
libmysqlclient.so.20 => not found #就是这个没找到
libnetsnmp.so.31 => /lib64/libnetsnmp.so.31 (0x00007f30a2544000)
libevent-2.0.so.5 => /lib64/libevent-2.0.so.5 (0x00007f30a22fc000)
libcurl.so.4 => /lib64/libcurl.so.4 (0x00007f30a2092000)
libm.so.6 => /lib64/libm.so.6 (0x00007f30a1d90000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f30a1b8c000)
libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f30a1973000)
libpcreposix.so.0 => /lib64/libpcreposix.so.0 (0x00007f30a1770000)
libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f30a150e000)
libc.so.6 => /lib64/libc.so.6 (0x00007f30a1141000)
libssl.so.10 => /lib64/libssl.so.10 (0x00007f30a0ecf000)
libcrypto.so.10 => /lib64/libcrypto.so.10 (0x00007f30a0a6c000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f30a0850000)
libidn.so.11 => /lib64/libidn.so.11 (0x00007f30a061d000)
libssh2.so.1 => /lib64/libssh2.so.1 (0x00007f30a03f0000)
libssl3.so => /lib64/libssl3.so (0x00007f30a019e000)
libsmime3.so => /lib64/libsmime3.so (0x00007f309ff77000)
libnss3.so => /lib64/libnss3.so (0x00007f309fc4a000)
libnssutil3.so => /lib64/libnssutil3.so (0x00007f309fa1b000)
libplds4.so => /lib64/libplds4.so (0x00007f309f817000)
libplc4.so => /lib64/libplc4.so (0x00007f309f612000)
libnspr4.so => /lib64/libnspr4.so (0x00007f309f3d4000)
libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007f309f187000)
libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007f309ee9e000)
libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007f309ec6b000)
libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007f309ea67000)
liblber-2.4.so.2 => /lib64/liblber-2.4.so.2 (0x00007f309e858000)
libldap-2.4.so.2 => /lib64/libldap-2.4.so.2 (0x00007f309e603000)
libz.so.1 => /lib64/libz.so.1 (0x00007f309e3ed000)
/lib64/ld-linux-x86-64.so.2 (0x00007f30a2847000)
librt.so.1 => /lib64/librt.so.1 (0x00007f309e1e5000)
libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007f309dfd5000)
libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007f309ddd1000)
libsasl2.so.3 => /lib64/libsasl2.so.3 (0x00007f309dbb4000)
libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f309d98d000)
libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007f309d756000)
libfreebl3.so => /lib64/libfreebl3.so (0x00007f309d553000)

提示类库没找到,如果让它自动加载进来呢,如下:

[root@xuegod13 sbin]# vim /etc/ld.so.conf
#追加如下行:
/var/lib/mysql/lib/
[root@xuegod13 sbin]# ldconfig
#检查下还有没有not found
[root@xuegod13 sbin]# ldd zabbix_server
linux-vdso.so.1 => (0x00007ffdfebfc000)
libmysqlclient.so.20 => /var/lib/mysql/lib/libmysqlclient.so.20 (0x00007fe5dda68000)
libnetsnmp.so.31 => /lib64/libnetsnmp.so.31 (0x00007fe5dd765000)
libevent-2.0.so.5 => /lib64/libevent-2.0.so.5 (0x00007fe5dd51d000)
libcurl.so.4 => /lib64/libcurl.so.4 (0x00007fe5dd2b3000)
libm.so.6 => /lib64/libm.so.6 (0x00007fe5dcfb1000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007fe5dcdad000)
libresolv.so.2 => /lib64/libresolv.so.2 (0x00007fe5dcb94000)
libpcreposix.so.0 => /lib64/libpcreposix.so.0 (0x00007fe5dc991000)
libpcre.so.1 => /lib64/libpcre.so.1 (0x00007fe5dc72f000)
libc.so.6 => /lib64/libc.so.6 (0x00007fe5dc362000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fe5dc146000)
librt.so.1 => /lib64/librt.so.1 (0x00007fe5dbf3e000)
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007fe5dbc36000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fe5dba20000)
libssl.so.10 => /lib64/libssl.so.10 (0x00007fe5db7ae000)
libcrypto.so.10 => /lib64/libcrypto.so.10 (0x00007fe5db34b000)
libidn.so.11 => /lib64/libidn.so.11 (0x00007fe5db118000)
libssh2.so.1 => /lib64/libssh2.so.1 (0x00007fe5daeeb000)
libssl3.so => /lib64/libssl3.so (0x00007fe5dac99000)
libsmime3.so => /lib64/libsmime3.so (0x00007fe5daa72000)
libnss3.so => /lib64/libnss3.so (0x00007fe5da745000)
libnssutil3.so => /lib64/libnssutil3.so (0x00007fe5da516000)
libplds4.so => /lib64/libplds4.so (0x00007fe5da312000)
libplc4.so => /lib64/libplc4.so (0x00007fe5da10d000)
libnspr4.so => /lib64/libnspr4.so (0x00007fe5d9ecf000)
libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007fe5d9c82000)
libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007fe5d9999000)
libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007fe5d9766000)
libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007fe5d9562000)
liblber-2.4.so.2 => /lib64/liblber-2.4.so.2 (0x00007fe5d9353000)
libldap-2.4.so.2 => /lib64/libldap-2.4.so.2 (0x00007fe5d90fe000)
libz.so.1 => /lib64/libz.so.1 (0x00007fe5d8ee8000)
/lib64/ld-linux-x86-64.so.2 (0x00007fe5de081000)
libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007fe5d8cd8000)
libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007fe5d8ad4000)
libsasl2.so.3 => /lib64/libsasl2.so.3 (0x00007fe5d88b7000)
libselinux.so.1 => /lib64/libselinux.so.1 (0x00007fe5d8690000)
libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007fe5d8459000)
libfreebl3.so => /lib64/libfreebl3.so (0x00007fe5d8256000)

再运行启动zabbix_server脚本,发现成功了

[root@xuegod13 sbin]# ./zabbix_server











以上是关于2-27 使用zabbix监控服务器运行状态的主要内容,如果未能解决你的问题,请参考以下文章

使用Zabbix监控ZooKeeper服务的健康状态

zabbix 3.4监控zookeeper3.4

Zabbix监控Zookeeper健康状况

zabbix系列zabbix3.4监控zookeeper3.4.10

使用zabbix监控服务器运行状态-

zabbix监控进程的CPU和内存占用量,进程数量