[原创]Zabbix各种模式姿势大全

Posted 运维部落

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[原创]Zabbix各种模式姿势大全相关的知识,希望对你有一定的参考价值。

Zabbbix安装及配置


目录:


一、获取zabbix安装包

软件下载

zabbix版本使用3.0LTS版本

二、安装环境准备

1、安装依赖环境

yum groupinstall "Development tools" "Compatibility libraries" -y

2、配置时钟同步

echo "00 */1 * * * root /usr/sbin/ntpdate 1.cn.pool.ntp.org;hwclock -w" >> /etc/crontab

三、安装Zabbix Server端

1、软件存入到服务器端

  • 将下载好的zabbix-3.0.5.tar.gz放到相应的服务器端

  • 解压软件包

tar xf zabbix-3.0.5.tar.gz

2、安装php依赖组件

  • 添加yum源

[webtatic]
name=Webtatic Repository EL6 - $basearch
mirrorlist=http://mirror.webtatic.com/yum/el7/x86_64/mirrorlist
failovermethod=priority
enabled=1
gpgcheck=0
  • 缓存repo数据

yum makecache
  • 安装php

yum install php56w   php56w-bcmath php56w-pecl-memcache php56w-pecl-redis php56w-mcrypt php56w-cli php56w-mysql  php56w-fpm  php56w-pdo  php56w-mbstring  php56w-soap php56w-process php56w-xml php56w-pear php56w-pecl-igbinary php56w-gd php56w-devel php56w-pecl-redis php56w-ldap php56w-common php56w-xmlrpc php56w-opcache -y
  • 配置php

[root@zabbix3-server ~]# cat /etc/php.ini  | grep "^[^;]"
[PHP]
engine = On
short_open_tag = Off
asp_tags = Off
precision = 14
output_buffering = 4096
zlib.output_compression = Off
implicit_flush = Off
unserialize_callback_func =
serialize_precision = 17
disable_functions =
disable_classes =
zend.enable_gc = On
expose_php = On
max_execution_time = 300
max_input_time = 300
memory_limit = 128M
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
display_errors = Off
display_startup_errors = Off
log_errors = On
log_errors_max_len = 1024
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
track_errors = Off
html_errors = On
variables_order = "GPCS"
request_order = "GP"
register_argc_argv = Off
auto_globals_jit = On
post_max_size = 16M
auto_prepend_file =
auto_append_file =
default_mimetype = "text/html"
default_charset = "UTF-8"
always_populate_raw_post_data = -1
doc_root =
user_dir =
enable_dl = Off
file_uploads = On
upload_max_filesize = 2M
max_file_uploads = 20
allow_url_fopen = On
allow_url_include = Off
default_socket_timeout = 60
[CLI Server]
cli_server.color = On
[Date]
#date.timezone = RPC
date.timezone = Asia/Shanghai
[filter]
[iconv]
[intl]
[sqlite]
[sqlite3]
[Pcre]
[Pdo]
[Pdo_mysql]
pdo_mysql.cache_size = 2000
pdo_mysql.default_socket=
[Phar]
[mail function]
sendmail_path = /usr/sbin/sendmail -t -i
mail.add_x_header = On
[SQL]
sql.safe_mode = Off
[ODBC]
odbc.allow_persistent = On
odbc.check_persistent = On
odbc.max_persistent = -1
odbc.max_links = -1
odbc.defaultlrl = 4096
odbc.defaultbinmode = 1
[Interbase]
ibase.allow_persistent = 1
ibase.max_persistent = -1
ibase.max_links = -1
ibase.timestampformat = "%Y-%m-%d %H:%M:%S"
ibase.dateformat = "%Y-%m-%d"
ibase.timeformat = "%H:%M:%S"
[MySQL]
mysql.allow_local_infile = On
mysql.allow_persistent = On
mysql.cache_size = 2000
mysql.max_persistent = -1
mysql.max_links = -1
mysql.default_port =
mysql.default_socket =
mysql.default_host =
mysql.default_user =
mysql.default_password =
mysql.connect_timeout = 60
mysql.trace_mode = Off
[MySQLi]
mysqli.max_persistent = -1
mysqli.allow_persistent = On
mysqli.max_links = -1
mysqli.cache_size = 2000
mysqli.default_port = 3306
mysqli.default_socket =
mysqli.default_host =
mysqli.default_user =
mysqli.default_pw =
mysqli.reconnect = Off
[mysqlnd]
mysqlnd.collect_statistics = On
mysqlnd.collect_memory_statistics = Off
[OCI8]
[PostgreSQL]
pgsql.allow_persistent = On
pgsql.auto_reset_persistent = Off
pgsql.max_persistent = -1
pgsql.max_links = -1
pgsql.ignore_notice = 0
pgsql.log_notice = 0
[Sybase-CT]
sybct.allow_persistent = On
sybct.max_persistent = -1
sybct.max_links = -1
sybct.min_server_severity = 10
sybct.min_client_severity = 10
[bcmath]
bcmath.scale = 0
[browscap]
[Session]
session.save_handler = files
session.use_strict_mode = 0
session.use_cookies = 1
session.use_only_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.cookie_httponly =
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor = 1000
session.gc_maxlifetime = 1440
session.referer_check =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.hash_function = 0
session.hash_bits_per_character = 5
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"
[MSSQL]
mssql.allow_persistent = On
mssql.max_persistent = -1
mssql.max_links = -1
mssql.min_error_severity = 10
mssql.min_message_severity = 10
mssql.compatibility_mode = Off
mssql.secure_connection = Off
[Assertion]
[mbstring]
[gd]
[exif]
[Tidy]
tidy.clean_output = Off
[soap]
soap.wsdl_cache_enabled=1
soap.wsdl_cache_dir="/tmp"
soap.wsdl_cache_ttl=86400
soap.wsdl_cache_limit = 5
[sysvshm]
[ldap]
ldap.max_links = -1
[mcrypt]
[dba]
[curl]

[root@zabbix3-server ~]# cat /etc/php-fpm.d/www.conf
[www]
listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1
user = apache
group = apache
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
slowlog = /var/log/php-fpm/www-slow.log
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_admin_flag[log_errors] = on
php_value[session.save_handler] = files
php_value[session.save_path]    = /var/lib/php/session
php_value[soap.wsdl_cache_dir]  = /var/lib/php/wsdlcache
  • 启动php-fpm

service php-fpm start | systemctl start php-fpm.service
  • 服务加入启动项

chkconfig php-fpm on | systemctl enable php-fpm.service

3、安装Mysql组件

  • 添加yum源

[percona]
name = CentOS $releasever - Percona
baseurl=http://repo.percona.com/centos/$releasever/os/$basearch/
enabled = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-percona
gpgcheck = 0
  • 安装mysql

yum install Percona-Server-client-56 Percona-Server-devel-56 Percona-Server-server-56 Percona-Server-shared-56 Percona-Server-shared-compat
  • 初始化mysql

[root@zabbix3-server ~]# mysql_install_db
  • 启动mysql

service mysql start | systemctl start mysql.service
  • 导入zabbix数据库脚本

[root@zabbix3-server ~]# cd /root/zabbix-3.0.5/database/mysql/
[root@zabbix3-server ~]# mysql -uroot -ptest@2016
mysql> create database zabbix default charset utf8;
mysql> grant all privileges on zabbix.* to 'test'@'localhost' identified by 'test@2016';
mysql> quit;
[root@zabbix3-server ~]# mysql -uroot -ptest@2016 zabbix < schema.sql
[root@zabbix3-server ~]# mysql -uroot -ptest@2016 zabbix < images.sql
[root@zabbix3-server ~]# mysql -uroot -ptest@2016 zabbix < data.sql
  • 服务加入启动项

chkconfig mysql on | systemctl enable mysql.service

4、安装nginx组件

  • 添加阿里云epel源

[aliyun-epel]
name=aliyun epel
baseurl=http://mirrors.aliyun.com/epel/7Server/x86_64/
enabled=1
gpgcheck=0
  • 安装nginx

yum install nginx -y
  • 配置nginx 虚拟主机

[root@zabbix-server conf.d]# cat zabbix.conf 
 server {
        listen       80;
        server_name zabbix-idc.test.cn;
        access_log  /web/logs/zabbix.test.cn.log  main;

        index index.html index.php index.html;
        root /web/site/zabbix.test.cn;

        location /
        {
                try_files $uri $uri/ /index.php?$args;
        }

        location ~ ^(.+.php)(.*)$ {
                fastcgi_split_path_info ^(.+.php)(.*)$;
                include fastcgi.conf;
                fastcgi_pass  127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param  PATH_INFO          $fastcgi_path_info;
        }
}
  • 创建虚拟主机根目录

mkdir /web/site/zabbix.test.cn -p
mkdir /web/logs/
  • 复制zabbix 资源文件到虚拟主机根目录

[root@zabbix3-server zabbix-3.0.5]# pwd
/root/zabbix-3.0.5
[root@zabbix3-server zabbix-3.0.5]# cd frontends/php/
[root@zabbix3-server php]# cp -r * /web/site/zabbix.test.cn/
  • 配置zabbix的数据库设置

[root@zabbix3-server zabbix.test.cn]# pwd
/web/site/zabbix.test.cn
[root@zabbix3-server zabbix.test.cn]# cat conf/zabbix.conf.php
<?php
// Zabbix GUI configuration file.
global $DB;

$DB['TYPE']     = 'MYSQL';
$DB['SERVER']   = '10.8.5.88';
$DB['PORT']     = '0';
$DB['DATABASE'] = 'zabbix';
$DB['USER']     = 'test';
$DB['PASSWORD'] = 'test@2016';

// Schema name. Used for IBM DB2 and PostgreSQL.
$DB['SCHEMA'] = '';

$ZBX_SERVER      = '10.8.5.88';
$ZBX_SERVER_PORT = '10051';
$ZBX_SERVER_NAME = '';

$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;
  • 启动Nginx

service nginx start | systemctl start nginx.service
  • 将Nginx加入启动列表

chkconfig nginx on | systemctl enable nginx.service

5、编译安装zabbix-server

  • 进入zabbix源码目录

cd /root/zabbix-3.0.5
useradd zabbix
  • 编译

[root@zabbix3-server zabbix-3.0.5]# ./configure --prefix=/usr/local/zabbix-3.0.5 --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2
[root@zabbix3-server zabbix-3.0.5]# make 
[root@zabbix3-server zabbix-3.0.5]# make install
  • 配置zabbix-server

[root@zabbix3-server etc]# grep -v "^#" zabbix_server.conf | grep -v "^$"
LogFile=/tmp/zabbix_server.log
DebugLevel=3
PidFile=/tmp/zabbix_server.pid
DBHost=10.8.5.88
DBName=zabbix
DBUser=test
DBPassword=test@2016
StartPollers=40
CacheSize=128M
Timeout=4
AlertScriptsPath=/usr/local/zabbix-3.0/bin
LogSlowQueries=3000
  • 配置zabbix-server服务管理脚本

[root@zabbix3-server etc]# cat /etc/init.d/zabbix-server 
#!/bin/sh
#
# chkconfig: - 85 15
# description: Zabbix server daemon
# config: /usr/local/zabbix-3.0/etc/zabbix_server.conf
#

### BEGIN INIT INFO
# Provides: zabbix
# Required-Start: $local_fs $network
# Required-Stop: $local_fs $network
# Default-Start:
# Default-Stop: 0 1 2 3 4 5 6
# Short-Description: Start and stop Zabbix server
# Description: Zabbix server
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions
export PATH=/usr/local/zabbix-3.0/sbin/:$PATH

if [ -x /usr/local/zabbix-3.0/sbin/zabbix_server ]; then
    exec=zabbix_server
else
    exit 5
fi

prog=${exec##*/}
conf=/usr/local/zabbix-3.0/etc/zabbix_server.conf
pidfile=$(grep -e "^PidFile=.*$" $conf | cut -d= -f2  | tr -d '\r')
timeout=10

if [ -f /etc/sysconfig/zabbix-server ]; then
    . /etc/sysconfig/zabbix-server
fi

lockfile=/var/lock/subsys/zabbix-server

start()
{
    echo -n $"Starting Zabbix server: "
    daemon $exec -c $conf
    rv=$?
    echo
    [ $rv -eq 0 ] && touch $lockfile
    return $rv
}

stop()
{
    echo -n $"Shutting down Zabbix server: "
    killproc -p $pidfile -d $timeout $prog
    rv=$?
    echo
    [ $rv -eq 0 ] && rm -f $lockfile
    return $rv
}

restart()
{
    stop
    start
}

case "$1" in
    start|stop|restart)
        $1
        ;;
    force-reload)
        restart
        ;;
    status)
        status -p $pidfile $prog
        ;;
    try-restart|condrestart)
        if status $prog >/dev/null ; then
            restart
        fi
        ;;
    reload)
        action $"Service ${0##*/} does not support the reload action: " /bin/false
        exit 3
        ;;
    *)
    echo $"Usage: $0 {start|stop|status|restart|try-restart|force-reload}"
    exit 2
    ;;
esac
  • 启动zabbix-server服务

[root@zabbix3-server etc]# chmod +x /etc/init.d/zabbix-server 
[root@zabbix3-server etc]# service zabbix-server start
[root@zabbix3-server etc]# chkconfig zabbix-server on

四、初始化zabbix-server

1、访问zabbix-server地址

2、zabbix环境检查

[原创]Zabbix各种模式姿势大全

3、zabbix数据库配置

[原创]Zabbix各种模式姿势大全

五、编译安装zabbix-agent端

Server端在编译的时候,已经开启了zabbix-agent功能,不需要单独编译

  • 进入源码目录

[root@www zabbix-3.0.5]# cd /root/zabbix-3.0.5
[root@www zabbix-3.0.5]# useradd zabbix
[root@www zabbix-3.0.5]# mkdir /var/log/zabbix
[root@www zabbix-3.0.5]# chown zabbix.zabbix /var/log/zabbix
  • 编译

[root@zabbix3-server zabbix-3.0.5]# ./configure --prefix=/usr/local/zabbix-3.0/ --enable-agent
  • 配置zabbix-agent服务管理脚本

[root@DB2 home]# cat /etc/init.d/zabbix-agent 
#!/bin/sh
#
# chkconfig: - 86 14
# description: Zabbix agent daemon
# processname: zabbix_agentd
# config: /usr/local/zabbix-3.0/etc/zabbix_agentd.conf
#

### BEGIN INIT INFO
# Provides: zabbix-agent
# Required-Start: $local_fs $network
# Required-Stop: $local_fs $network
# Should-Start: zabbix zabbix-proxy
# Should-Stop: zabbix zabbix-proxy
# Default-Start:
# Default-Stop: 0 1 2 3 4 5 6
# Short-Description: Start and stop Zabbix agent
# Description: Zabbix agent
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions

export PATH=/usr/local/zabbix-3.0/sbin/:$PATH

if [ -x /usr/local/zabbix-3.0/sbin/zabbix_agentd ]; then
    exec=zabbix_agentd
else
    exit 5
fi

prog=${exec##*/}
conf=/usr/local/zabbix-3.0/etc/zabbix_agentd.conf
pidfile=$(grep -e "^PidFile=.*$" $conf | cut -d= -f2 | tr -d '\r')
timeout=10

if [ -f /etc/sysconfig/zabbix-agent ]; then
    . /etc/sysconfig/zabbix-agent
fi

lockfile=/var/lock/subsys/zabbix-agent

start()
{
    echo -n $"Starting Zabbix agent: "
    daemon $exec -c $conf
    rv=$?
    echo
    [ $rv -eq 0 ] && touch $lockfile
    return $rv
}

stop()
{
    echo -n $"Shutting down Zabbix agent: "
    killproc -p $pidfile -d $timeout $prog
    rv=$?
    echo
    [ $rv -eq 0 ] && rm -f $lockfile
    return $rv
}

restart()
{
    stop
    start
}

case "$1" in
    start|stop|restart)
        $1
        ;;
    force-reload)
        restart
        ;;
    status)
        status -p $pidfile $prog 
        ;;
    try-restart|condrestart)
        if status $prog >/dev/null ; then
            restart
        fi
        ;;
    reload)
        action $"Service ${0##*/} does not support the reload action: " /bin/false
        exit 3
        ;;
    *)
    echo $"Usage: $0 {start|stop|status|restart|try-restart|force-reload}"
    exit 2
    ;;
esac
  • 服务添加到启动项

[root@zabbix3-server ~]# chkconfig zabbix-agent on
  • 启动服务

[root@zabbix3-server ~]# service zabbix-agent start

六、安装zabbix-proxy端

zabbix版本使用3.0LTS版本,需要将zabbix-proxy的主机添加到zabbix-server中,目录环境中是将IP:58.96.188.84,zabbix-agent名称为:www.test.com

1、安装依赖环境

yum groupinstall "Development tools" "Compatibility libraries" -y

2、配置时钟同步

echo "00 */1 * * * root /usr/sbin/ntpdate 1.cn.pool.ntp.org;hwclock -w" >> /etc/crontab

3、上传安装文件

[root@www ~]# ls
zabbix-3.0.5.tar.gz

4、编译安装

[root@www zabbix-3.0.5]# ./configure --prefix=/usr/local/zabbix-3.0 --with-mysql --with-net-snmp --with-libcurl  --enable-agent --enable-proxy  #此处开启了zabbix-agent端
[root@www zabbix-3.0.5]# make  && make install

5、配置zabbix-proxy

[root@www zabbix-3.0.5]# cd /usr/local/zabbix-3.0/etc/
[root@www etc]# cat zabbix_proxy.conf
Server=103.243.254.186
#ServerPort=10053
ServerPort=10051
Hostname=www.test.com
LogFile=/var/log/zabbix/zabbix3_proxy.log
LogFileSize=0
DebugLevel=3
PidFile=/var/run/zabbix/zabbix3_proxy.pid
DBName=zabbix3
DBUser=zabbix3
DBPassword=test@2016     #此处的数据库用户和密码,需要手动建立
DBSocket=/var/lib/mysql/mysql.sock
ProxyLocalBuffer=0
ProxyOfflineBuffer=1
ConfigFrequency=600
DataSenderFrequency=10
ExternalScripts=/usr/local/zabbix-3.0/scripts/

[root@www zabbix-3.0.5]# useradd zabbix
[root@www zabbix-3.0.5]# mkdir /var/log/zabbix
[root@www zabbix-3.0.5]# chown zabbix.zabbix /var/log/zabbix

6、添加管理脚本

由于字数限制,本处略过....

7、安装Mysql组件

  • 添加yum源

[percona]
name = CentOS $releasever - Percona
baseurl=http://repo.percona.com/centos/$releasever/os/$basearch/
enabled = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-percona
gpgcheck = 0
  • 安装mysql

yum install Percona-Server-client-56 Percona-Server-devel-56 Percona-Server-server-56 Percona-Server-shared-56 Percona-Server-shared-compat
  • 初始化mysql

[root@zabbix3-server ~]# mysql_install_db
  • 启动mysql

service mysql start | systemctl start mysql.service
  • 导入zabbix数据库脚本

[root@zabbix3-server ~]# cd /root/zabbix-3.0.5/database/mysql/
[root@zabbix3-server ~]# mysql -uroot -ptest@2016
mysql> create database zabbix3 default charset utf8;
mysql> grant all privileges on zabbix3.* to 'zabbix3'@'localhost' identified by 'test@2016';
mysql> quit;
[root@zabbix3-server ~]# mysql -uroot -ptest@2016 zabbix < schema.sql
  • 服务加入启动项

chkconfig mysql on | systemctl enable mysql.service

8、启动zabbix-proxy

[root@www etc]# chmod +x /etc/init.d/zabbix-proxy 
[root@www etc]# chkconfig zabbix-proxy on
[root@www etc]# service zabbix-proxy start

9、添加zabbix proxy节点

需要将www.test.com这个代理节点添加到zabbix中。(在proxy端开户agent,并添加主机)

  • 登陆zabbix server端

  • 添加proxy代理节点

[原创]Zabbix各种模式姿势大全

10、确认proxy工作状态

  • zabbix server端日志

[root@zabbix3-server ~]# tailf /tmp/zabbix_server.log
  7541:20161201:215205.923 sending configuration data to proxy "www.test.com" at "58.96.188.84", datalen 38961
  7539:20161201:220206.514 sending configuration data to proxy "www.test.com" at "58.96.188.84", datalen 38961
  7542:20161201:221206.753 sending configuration data to proxy "www.test.com" at "58.96.188.84", datalen 38961
  • zabbix proxy端日志

tailf /var/log/zabbix/zabbix3_proxy.log
 10518:20161202:105206.429 received configuration data from server at "103.243.254.186", datalen 38961
 10518:20161202:110206.673 received configuration data from server at "103.243.254.186", datalen 38961
 10518:20161202:111206.918 received configuration data from server at "103.243.254.186", datalen 38961

以上是关于[原创]Zabbix各种模式姿势大全的主要内容,如果未能解决你的问题,请参考以下文章

(原创)看我用各种姿势在手机和PC查看到连接到的wifi密码

有用 .htaccess 使用方法大全

VSCode自定义代码片段3——url大全

VSCode自定义代码片段3——url大全

VSCode自定义代码片段3——url大全

VSCode自定义代码片段——cli的终端命令大全