Zabbix部署篇-Zabbix3.4分布式Zabbix_Proxy搭建

释放双眼,带上耳机,听听看~!

系统环境

CentOS 7.4

Zabbix  proxy地址:192.168.56.6
Zabbix版本:zabbix-3.4.8.tar.gz
MySQL版本: mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz
JDK版本:jdk-8u161-linux-x64.tar.gz
依赖包:fping-4.0.tar.gz、cmake-3.11.1.tar.gz、perl-ExtUtils-Embed-1.30-292.el7.noarch.rpm、perl-Data-Dumper-2.145-3.el7.x86_64.rpm、libaio-devel-0.3.110-9.fc27.x86_64.rpm、net-snmp-5.7.3.tar.gz、pcre-devel-8.32-17.el7.x86_64.rpm

安装mysql

1.下载mysql

wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz
[root@linux-node2 src]# tar xf mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz  -C /usr/local/
[root@linux-node2 src]# mv /usr/local/mysql-5.6.40-linux-glibc2.12-x86_64 /usr/local/mysql

2.创建用户并修改文件属性

[root@linux-node2 local]# useradd -s /sbin/nologin mysql
[root@linux-node2 src]# chown -Rf mysql:mysql /usr/local/mysql

3.创建数据目录并初始化数据库

wget http://mirror.centos.org/centos/7/os/x86_64/Packages/perl-Data-Dumper-2.145-3.el7.x86_64.rpm       #再次依赖perl库,也可以使用yum install perl perl-devel
[root@linux-node2 src]# rpm -ivh perl-Data-Dumper-2.145-3.el7.x86_64.rpm
[root@linux-node2 scripts]# mkdir /opt/data
[root@linux-node2 init.d]# chown -Rf mysql:mysql /opt/data
[root@linux-node2 scripts]# cd /usr/local/mysql/scripts/
[root@linux-node2 scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/opt/data

4.初始化后调整

[root@linux-node2 scripts]# cd /usr/local/mysql/support-files/
[root@linux-node2 support-files]# cp my-default.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? y
[root@linux-node2 support-files]# cp mysql.server /etc/init.d/mysql
[root@linux-node2 support-files]# vim /etc/init.d/mysql         #在启动文件里指定应用路径以及数据目录
 46 basedir=/usr/local/mysql
 47 datadir=/opt/data

5.添加环境变量

[root@linux-node2 support-files]# vim /etc/profile
export MYSQL_HOME=/usr/local/mysql
export PATH=$MYSQL_HOME/bin:$PATH
[root@linux-node2 support-files]# source /etc/profile

6.启动mysql并加入开机自启

[root@linux-node2 support-files]# cd /etc/init.d/
[root@linux-node2 init.d]# chkconfig --add mysql
[root@linux-node2 init.d]# chkconfig mysql on
[root@linux-node2 init.d]# service mysql start

7.设置root登录密码

[root@linux-node2 init.d]# /usr/local/mysql/bin/mysqladmin -u root password "3edc#EDC"

8.登录数据库

[root@linux-node2 /]# mysql -u root -p
Enter password: 
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

9.数据库加固

[root@linux-node2 /]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):       #此处输入刚才使用mysqladmin修改过的mysql数据库root密码
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] y                      #要为root管理员设置数据库的密码,刚才已经使用mysqladmin命令设置过了,如果需要重置请按y,如果不需要请按n
New password:                               #输入要为root管理员设置的数据库密码
Re-enter new password:                          #再输入一次密码
Password updated successfully!
Reloading privilege tables..
 ... Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y                 #删除匿名账户
 ... Success!
Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y               #禁止root管理员从远程登录
 ... Success!
By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y      #删除test数据库并取消对其的访问权限
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y                #刷新授权表,让初始化后的设定立即生效
 ... Success!
All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
Cleaning up...

创建zabbix数据库并授权给zabbix数据库用户

[root@linux-node2 /]# mysql -uroot -p
Enter password: 
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |                              #经过安全加固后,test数据库已被删除
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
mysql> create database zabbix default charset utf8 collate utf8_general_ci;                 #创建zabbix数据库
Query OK, 1 row affected (0.00 sec)
mysql> grant all privileges on zabbix.* to 'zabbix'@'localhost' identified by 'zabbix';     #授权zabbix数据库给zabbix用户
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;                #刷新配置

安装zabbix proxy

1.下载zabbix

[root@linux-node2 src]# wget https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/3.4.8/zabbix-3.4.8.tar.gz

2.解压并安装

[root@linux-node2 src]# tar xf zabbix-3.4.8.tar.gz 
[root@linux-node2 src]# useradd -s /sbin/nologin zabbix

3.安装java环境

下载jdk wget http://download.oracle.com/otn-pub/java/jdk/8u171-b11/512cd62ec5174c3487ac17c61aaa89e8/jdk-8u171-linux-x64.tar.gz
[root@linux-node2 src]# tar xf jdk-8u161-linux-x64.tar.gz -C /usr/local/        
[root@linux-node2 src]# mv /usr/local/jdk1.8.0_161 /usr/local/java
[root@linux-node2 src]# vim /etc/profile
export JAVA_HOME=/usr/local/java
export JRE_HOME=/usr/local/java/jre
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
[root@linux-node2 src]# source /etc/profile
[root@linux-node2 src]# java -version

4.导入Zabbix数据表

[root@linux-node2 mysql]# mysql -u zabbix -p
Enter password:
mysql> use zabbix;
mysql> source /usr/local/src/zabbix-3.4.8/database/mysql/schema.sql

5.安装依赖包

[root@linux-node2 src]# yum install net-snmp*       #net-snmp我再也不用源码或者rpm装了,mb依赖太多了,解决不了,要疯的感觉
[root@linux-node2 src]# yum install curl curl-devel

6.编译安装zabbix

[root@linux-node2 zabbix-3.4.8]# ./configure --prefix=/usr/local/zabbix --enable-proxy --enable-agent --with-mysql --with-net-snmp --with-libcurl --enable-java --enable-ipv6
[root@linux-node2 zabbix-3.4.8]# make install

7.拷贝启动脚本文件

[root@linux-node2 zabbix-3.4.8]# cp misc/init.d/fedora/core5/zabbix_server /etc/init.d/zabbix_proxy
[root@linux-node2 zabbix-3.4.8]# cp misc/init.d/fedora/core5/zabbix_agentd /etc/init.d/zabbix_agentd
[root@linux-node2 zabbix-3.4.8]# chmod +x /etc/init.d/zabbix_*

8.修改zabbix_proxy配置文件

[root@linux-node2 zabbix-3.4.8]# cd /usr/local/zabbix/etc/
[root@linux-node2 etc]# vim zabbix_proxy.conf
[root@linux-node2 etc]# grep -Ev "#|^$" zabbix_proxy.conf
Server=172.16.14.236,172.16.70.30                           #指定Zabbix_Server地址,可以有多个,以逗号隔开
Hostname=zbx_proxy_migu                                 #指定proxy主机名,此名称需和页面上添加agentd代理程序名称一致
LogFile=/tmp/zabbix_proxy.log                               #指定日志文件存放位置
LogFileSize=10                                          #日志文件大小,默认单位为MB
DBName=zabbix                                           #指定数据库名称
DBUser=zabbix                                           #指定数据库用户
DBPassword=zabbix                                       #指定数据库密码
DBSocket=/tmp/mysql.sock                                    #指定mysql的sock文件存放位置,大多数位置都为/var/lib/mysql/mysql.sock
ConfigFrequency=3600                                        #代理在几秒钟内从ZabBiX服务器检索配置数据的频率,对于被动模式中的代理,此参数将被忽略
StartPollers=50                                         #zabbix进程数,poller可以简单的理解为一个zabbix的工作worker
StartPollersUnreachable=10                                  #检查unreachable host(包括IPMI)的进程数
StartTrappers=10                                            #Trappers进程数,Trappers用于接收其它host用zabbix_sender、active_agents发送的数据,至少需要一个Trapper进程用来在前端显示Zabbix Server可用性
StartPingers=20                                         #用于ICMP ping的进程数
StartDiscoverers=5                                          #用于自动发现(Discovery)的discovery的进程数
StartHTTPPollers=10                                     #用于HTTP检查的进程数
CacheSize=1G                                            #存储Host、Item和Trgger数据的内存空间
HistoryCacheSize=256M                                   #存储History数据的内存大小
HistoryIndexCacheSize=256M                              #存储历史索引缓存共享内存的大小
Timeout=4                                               #Zabbix等待Agent、SNMP设备或者自定义脚本的执行超时时间
FpingLocation=/usr/local/fping                              #指定fping的路径
LogSlowQueries=3000                                     #记录查询Zabbix数据库的慢查询,单位是毫秒,只有当DebugLevel设置为3或者4才会生效,如果设置设置为0,则不记录慢查询,这个对Zabbix性能差是非常好的debug方式
Include=/usr/local/zabbix/etc/zabbix_proxy.conf.d/*.conf            #指定存放设置自定义监控的文件位置

9.修改zabbix_agentd配置文件

[root@linux-node2 etc]# vim zabbix_agentd.conf
[root@linux-node2 etc]# grep -Ev "#|^$" zabbix_agentd.conf
LogFile=/tmp/zabbix_agentd.log                              #指定日志存放位置
Server=127.0.0.1,192.168.56.6                               #Zabiix Server IP地址或者Zabbix Proxy IP地址或主机名,再次因本机就是Proxy,所以Server地址指向本机IP地址,即为经过Proxy和Server传递数据
ServerActive=192.168.56.6                                   #用于主动检查的IP或者Hostname和端口,如果不指定端口,会使用默认端口,即为Zabbix Server 地址或者Zabbix Proxy地址
Hostname=192.168.56.6                                   #运行Zabbix Agentd的hostname,必须与server中配置的host相同
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf           #指定存放自定义监控文件位置

10.修改启动配置文件

[root@linux-node2 etc]# vim /etc/init.d/zabbix_agentd
ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_agentd"           #修改启动文件路径,之前为/usr/local/sbin/zabbix_agentd,或者创软连接也可以解决此问题
[root@linux-node2 /]# vim /etc/init.d/zabbix_proxy
#!/bin/bash
#
#       /etc/rc.d/init.d/zabbix_server
#
# Starts the zabbix_server daemon
#
# chkconfig: - 95 5
# description: Zabbix Monitoring Server
# processname: zabbix_server
# pidfile: /tmp/zabbix_proxy.pid

# Modified for Zabbix 2.0.0
# May 2012, Zabbix SIA

# Source function library.

. /etc/init.d/functions

RETVAL=0
prog="Zabbix Proxy"
ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_proxy"

if [ ! -x ${ZABBIX_BIN} ] ; then
        echo -n "${ZABBIX_BIN} not installed! "
        # Tell the user this has skipped
        exit 5
fi

start() {
        echo -n $"Starting $prog: "
        daemon $ZABBIX_BIN
        RETVAL=$?
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/zabbix_proxy
        echo
}

stop() {
        echo -n $"Stopping $prog: "
        killproc $ZABBIX_BIN
        RETVAL=$?
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/zabbix_proxy
        echo
}

case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  reload|restart)
        stop
        sleep 10
        start
        RETVAL=$?
        ;;
  condrestart)
        if [ -f /var/lock/subsys/zabbix_proxy ]; then
            stop
            start
        fi
        ;;
  status)
        status $ZABBIX_BIN
        RETVAL=$?
        ;;
  *)
        echo $"Usage: $0 {condrestart|start|stop|restart|reload|status}"
        exit 1
esac

exit $RETVAL
[root@linux-node2 /]# cd /etc/init.d/
[root@linux-node2 init.d]# chkconfig --add zabbix_agentd 
c[root@linux-node2 init.d]# chkconfig --add zabbix_proxy 
[root@linux-node2 init.d]# chkconfig zabbix_agentd on
[root@linux-node2 init.d]# chkconfig zabbix_proxy on
[root@linux-node2 init.d]# service zabbix_agentd restart
Restarting zabbix_agentd (via systemctl):                  [  OK  ]
[root@linux-node2 init.d]# service zabbix_proxy restart
Restarting zabbix_proxy (via systemctl):                   [  OK  ]

Web界面添加Zabbix_Proxy

登录Zabbix_Server的Web页面
管理——>创建代理——>写入代理名称选择代理模式,然后添加即可

人已赞赏
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧