基于LNMP平台使用源码方式安装Zabbix-4.0

2019/04/10 10:10
阅读数 31

上篇文章为大家梳理了Zabbix的基本知识,这篇文章我们来看一下Zabbix如何部署

常见的部署方式包括:源码方式部署,RPM方式部署,容器化部署,个人喜欢用源码方式部署,这是个人的喜好,哈哈,就像有的朋友喜欢用yum方式直接安装一样

提示:因为CentOS的官方yum源并不提供Zabbix的软件包,所以我们使用RPM方式部署Zabbix的时候,需要提前添加好第三方源,下面的链接均为基于4.0版本,以供参考

官方:http://repo.zabbix.com/zabbix/4.0/
阿里:https://mirrors.aliyun.com/zabbix/zabbix/4.0/

下面的记录为源码安装过程

一、安装LNMP平台

1)部署Nginx

1、安装依赖包

[root@zabbix ~]# yum -y install gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel

2、为Nginx创建运行用户

[root@zabbix ~]# useradd -M -s /sbin/nologin nginx

3、下载软件包

[root@zabbix ~]# wget -c http://www.nginx.org/download/nginx-1.16.1.tar.gz

4、编译安装Nginx

[root@zabbix ~]# tar xf nginx-1.16.1.tar.gz -C /usr/src/
[root@zabbix ~]# cd /usr/src/nginx-1.16.1/
[root@zabbix nginx-1.16.1]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module
[root@zabbix nginx-1.16.1]# make -j 8 && make install -j 8 && cd ~

5、添加Nginx至环境变量并启动Nginx

[root@zabbix ~]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' >> /etc/profile
[root@zabbix ~]# source /etc/profile && nginx
[root@zabbix ~]# netstat -anput | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      6575/nginx: master

6、将Nginx添加为系统服务

[root@zabbix ~]# cat > /usr/lib/systemd/system/nginx.service << EOF
[Unit]
Description=nginx
After=network.target
  
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=killall -s HUP $(cat /usr/local/nginx/logs/nginx.pid)
ExecStop=killall -s QUIT $(cat /usr/local/nginx/logs/nginx.pid)
PrivateTmp=Flase
  
[Install]
WantedBy=multi-user.target
EOF

7、检查并启动Nginx

[root@zabbix ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

[root@zabbix ~]# systemctl daemon-reload && pkill -9 nginx
[root@zabbix ~]# systemctl restart nginx && systemctl enable nginx

[root@zabbix ~]# netstat -anput | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      6626/nginx: master

2)部署MySQL

1、安装依赖包

[root@zabbix ~]# yum -y install ncurses ncurses-devel cmake libaio libaio-devel pcre pcre-devel \
zlib zlib-devel bison bison-devel libverto libverto-devel libstdc++ libstdc++-devel \
dbus dbus-devel libss libss-devel gcc gcc-c++ autoconf m4 libgcc e2fsprogs perl-Data-Dumper

2、下载软件包

[root@zabbix ~]# wget -c https://downloads.mysql.com/archives/get/file/mysql-5.7.27.tar.gz
[root@zabbix ~]# wget -c https://nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz

3、为MySQL创建运行用户与组

[root@zabbix ~]# groupadd mysql
[root@zabbix ~]# useradd -M -s /sbin/nologin mysql -g mysql

4、解压boost工具,并移动到指定位置即可,无需编译安装

[root@zabbix ~]# tar xf boost_1_59_0.tar.gz
[root@zabbix ~]# mv boost_1_59_0 /usr/local/boost

5、编译安装MySQL

注意:Zabbix只支持 utf8_bin 排序规则,所以这里需要为 utf8_bin,而不能设置为 utf8_general_ci

[root@zabbix ~]# tar xf mysql-5.7.27.tar.gz -C /usr/src/
[root@zabbix ~]# cd /usr/src/mysql-5.7.27/
[root@zabbix  mysql-5.7.27]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_bin \
-DWITH_EXTRA_CHARSETS=all \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_DEBUG=0 \
-DWITH_BOOST=/usr/local/boost \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/tmp/mysql.sock
make -j 8 && make install -j 8 && cd ~

6、创建对应的存储目录并调整相应的参数

[root@zabbix ~]# mkdir /usr/local/mysql/pid
[root@zabbix ~]# mkdir /usr/local/mysql/logs
[root@zabbix ~]# mkdir /usr/local/mysql/socket
[root@zabbix ~]# mkdir /usr/local/mysql/tmp
[root@zabbix ~]# mkdir /usr/local/mysql/ibtmp
[root@zabbix ~]# mkdir /usr/local/mysql/binlog
[root@zabbix ~]# mkdir /usr/local/mysql/relaylog
[root@zabbix ~]# mkdir /usr/local/mysql/outcsv
[root@zabbix ~]# mkdir /usr/local/mysql/ibdata
[root@zabbix ~]# mkdir /usr/local/mysql/undolog
[root@zabbix ~]# mkdir /usr/local/mysql/redolog
[root@zabbix ~]# chown -R mysql:mysql /usr/local/mysql
[root@zabbix ~]# chmod -R 750 /usr/local/mysql/outcsv
[root@zabbix ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' >> /etc/profile
[root@zabbix ~]# source /etc/profile

7、定义MySQL配置文件

注意:配置文件当中的collation-server项,对应的值为 utf8_bin,而非 utf8_general_ci

[root@zabbix ~]# cat > /etc/my.cnf << EOF
[client]
port = 3635
socket = /usr/local/mysql/socket/mysql.sock
 
[mysqld]
user = mysql
port = 3635
federated
skip_ssl
bind_address = 0.0.0.0
max_connections = 3600
max_connect_errors = 200
autocommit = ON
skip-name-resolve
symbolic-links = 0
skip-external-locking
log_timestamps = system
explicit_defaults_for_timestamp = ON
transaction_isolation = read-committed
binlog_gtid_simple_recovery = ON
show_compatibility_56 = ON
transaction_write_set_extraction = OFF
socket = /usr/local/mysql/socket/mysql.sock
pid-file = /usr/local/mysql/pid/mysql.pid
log-error = /usr/local/mysql/logs/mysql_error.log
secure-file-priv = /usr/local/mysql/outcsv
innodb_tmpdir = /usr/local/mysql/ibtmp
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
tmpdir = /usr/local/mysql/tmp
 
character-set-server = utf8
init_connect = SET NAMES utf8
collation-server = utf8_bin
 
slow_query_log = ON
long_query_time = 1
min_examined_row_limit = 960
log_slow_admin_statements = ON
log_slow_slave_statements = ON
log_queries_not_using_indexes = OFF
slow_query_log_file = /usr/local/mysql/logs/mysql_slow.log
 
back_log = 360
tmp_table_size = 64M
max_allowed_packet = 64M
max_heap_table_size = 64M
sort_buffer_size = 1M
join_buffer_size = 1M
read_buffer_size = 2M
read_rnd_buffer_size = 2M
thread_cache_size = 64
thread_stack = 256K
query_cache_size = 32M
query_cache_limit = 2M
query_cache_min_res_unit = 2K
table_open_cache = 4096
open_files_limit = 65535
connect_timeout = 9
interactive_timeout = 21600
wait_timeout = 21600
 
innodb_data_file_path = ibdata1:12M;ibdata:12M:autoextend
innodb_autoextend_increment = 12
innodb_data_home_dir = /usr/local/mysql/ibdata
 
innodb_undo_tablespaces = 4
innodb_undo_logs = 128
innodb_max_undo_log_size = 1G
innodb_undo_log_truncate = ON
innodb_purge_rseg_truncate_frequency = 10
innodb_undo_directory = /usr/local/mysql/undolog
 
innodb_log_file_size = 128M
innodb_log_buffer_size = 16M
innodb_log_files_in_group = 3
innodb_flush_log_at_trx_commit = 2
innodb_flush_log_at_timeout = 1
innodb_flush_method = O_DIRECT
innodb_log_group_home_dir = /usr/local/mysql/redolog
 
innodb_temp_data_file_path = ibtmp1:12M:autoextend:max:5G
innodb_fast_shutdown = 0
 
default-storage-engine = InnoDB
innodb_buffer_pool_size = 2G
table_open_cache_instances = 8
innodb_buffer_pool_chunk_size = 256MB
innodb_page_size = 16k
innodb_sort_buffer_size = 1MB
innodb_file_per_table = ON
innodb_large_prefix = ON
innodb_purge_threads = 8
innodb_page_cleaners = 8
innodb_read_io_threads = 8
innodb_write_io_threads = 8
innodb_thread_concurrency = 16
innodb_flush_neighbors = 0
innodb_lru_scan_depth = 1024
innodb_lock_wait_timeout = 60
innodb_print_all_deadlocks = ON
innodb_deadlock_detect = ON
innodb_strict_mode = ON
innodb_buffer_pool_load_at_startup = ON
innodb_buffer_pool_dump_at_shutdown = ON
EOF

8、初始化数据库

[root@zabbix ~]# /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
[root@zabbix ~]## echo $?
0

9、将MySQL添加为系统服务

[root@zabbix ~]# cp /usr/local/mysql/support-files/mysql.server /usr/local/mysql/bin/mysql.sh
[root@zabbix ~]# chmod +x /usr/local/mysql/bin/mysql.sh
[root@zabbix ~]# cat > /usr/lib/systemd/system/mysql.service << EOF
[Unit]
Description=MySQL
After=network.target
 
[Service]
User=mysql
Group=mysql
Type=forking
PrivateTmp=false
LimitNOFILE=65535
ExecStart=/usr/local/mysql/bin/mysql.sh start
ExecStop=/usr/local/mysql/bin/mysql.sh stop
 
[Install]
WantedBy=multi-user.target
EOF

10、启动MySQL并为root用户设置密码

[root@zabbix ~]# systemctl start mysql
[root@zabbix ~]# systemctl enable mysql
[root@zabbix ~]# netstat -anput | grep mysql
tcp        0      0 0.0.0.0:3635            0.0.0.0:*               LISTEN      33916/mysqld
[root@zabbix ~]# mysql -e"update mysql.user set authentication_string=password('abc-123') where user='root';flush privileges;"

3)部署PHP

1、安装依赖包

[root@zabbix ~]# yum -y install libxml2 libxml2-devel gd gd-devel libpng libpng-devel bzip2 bzip2-devel \
curl curl-devel gmp gmp-devel openldap openldap-devel libevent libevent-devel libxslt libxslt-devel

2、下载软件包

[root@zabbix ~]# wget -c https://www.php.net/distributions/php-7.3.15.tar.gz
[root@zabbix ~]# wget -c https://nih.at/libzip/libzip-1.2.0.tar.gz

3、安装libzip

注意:如果部署的PHP版本为7.X,则需要安装libzip,否则就会提示:Please reinstall the libzip distribution

[root@zabbix ~]# tar xf libzip-1.2.0.tar.gz -C /usr/src/
[root@zabbix ~]# cd /usr/src/libzip-1.2.0/
[root@zabbix libzip-1.2.0]# ./configure && make -j 8 && make install -j 8 && cd ~
[root@zabbix ~]# cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
[root@zabbix ~]# cat > /etc/ld.so.conf.d/local.conf << EOF
/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64
EOF
[root@zabbix ~]# ldconfig -v

4、编译安装PHP

[root@zabbix ~]# tar xf php-7.3.15.tar.gz -C /usr/src/
[root@zabbix ~]# cd /usr/src/php-7.3.15/
[root@zabbix  php-7.3.15]# ./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7 --enable-fpm --enable-mbstring  \
--with-gd --with-zlib --enable-inline-optimization --with-jpeg-dir=/usr/lib --disable-debug --disable-rpath \
--enable-shared --with-libxml-dir --with-xmlrpc --enable-soap  --with-openssl --enable-exif --enable-fileinfo \
--enable-filter --with-pcre-dir --enable-ftp --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir \
--with-freetype-dir --with-gettext --with-gmp --enable-json --enable-mbregex --enable-mbregex-backtrack \
--with-onig --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib-dir  --with-pdo-sqlite  --enable-session --enable-shmop \
--enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-zip \
--enable-mysqlnd-compression-support --with-pear --enable-opcache --with-mhash --with-pcre-regex --with-sqlite3 --enable-bcmath --with-iconv --with-bz2 \
--enable-calendar --with-curl --with-cdb --enable-dom --without-pear --disable-phar && make -j 8 && make install -j 8

5、复制参考文件与执行文件至对应的目录

[root@zabbix php-7.3.15]# cp php.ini-production /usr/local/php7/php.ini
[root@zabbix php-7.3.15]# cp /usr/local/php7/bin/* /usr/local/bin/
[root@zabbix php-7.3.15]# cp /usr/local/php7/sbin/* /usr/local/sbin/ && cd ~

6、安装opcache模块,用于提升性能

[root@zabbix ~]# cd /usr/src/php-7.3.15/ext/opcache/
[root@zabbix opcache]# /usr/local/php7/bin/phpize
Configuring for:
PHP Api Version:         20180731
Zend Module Api No:      20180731
Zend Extension Api No:   320180731
[root@zabbix opcache]# ./configure --with-php-config=/usr/local/php7/bin/php-config && make -j 8 && make install -j 8 && cd ~
[root@zabbix ~]# cp /usr/local/php7/lib/php/extensions/no-debug-non-zts-20180731/opcache.so /usr/local/php7/include/php/ext/

7、安装openldap模块,Zabbix有时候需要

[root@zabbix ~]# cp /usr/lib64/libldap* /usr/lib
[root@zabbix ~]# cp /usr/local/mysql/lib/libmysqlclient.so.20 /usr/lib64/
[root@zabbix ~]# cd /usr/src/php-7.3.15/ext/ldap/
[root@zabbix ldap]# /usr/local/php7/bin/phpize
Configuring for:
PHP Api Version:         20180731
Zend Module Api No:      20180731
Zend Extension Api No:   320180731
[root@zabbix ldap]# ./configure --with-php-config=/usr/local/php7/bin/php-config && make -j 8 && make install -j 8 && cd ~
[root@zabbix ~]# cp /usr/local/php7/lib/php/extensions/no-debug-non-zts-20180731/ldap.so /usr/local/php7/include/php/ext/

8、定义PHP配置文件,因为PHP的默认配置并不适合Zabbix

[root@zabbix ~]# cp /usr/local/php7/php.ini /usr/local/php7/php.ini.bak
[root@zabbix ~]# sed -i 's#;extension=ldap#extension=ldap#' /usr/local/php7/php.ini
[root@zabbix ~]# vim /usr/local/php7/php.ini
memory_limit = 1024M
max_execution_time = 0
post_max_size = 10800M
upload_max_filesize = 10240M
max_input_time = 360
 
[opcache]
opcache.enable=1
opcache.enable_cli=1
opcache.fast_shutdown = 1
opcache.save_comments = 1
opcache.revalidate_freq = 5
opcache.validate_timestamps = 0
opcache.memory_consumption = 512
opcache.interned_strings_buffer = 8
opcache.max_accelerated_files = 10000
zend_extension = /usr/local/php7/include/php/ext/opcache.so
 
[Date]
date.timezone = Asia/Shanghai
 
[Pdo_mysql]
pdo_mysql.default_socket=/usr/local/mysql/socket/mysql.sock

[MySQLi]
mysqli.default_socket = /usr/local/mysql/socket/mysql.sock

9、复制模板文件,并将PID的路径改为绝对路径

[root@zabbix ~]# cp /usr/local/php7/etc/php-fpm.conf.default  /usr/local/php7/etc/php-fpm.conf
[root@zabbix ~]# sed -i 's#;pid = run/php-fpm.pid#pid = /usr/local/php7/var/run/php-fpm.pid#' /usr/local/php7/etc/php-fpm.conf
[root@zabbix ~]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default  /usr/local/php7/etc/php-fpm.d/www.conf

10、更改属主与属组,并开启动态模式,调整动态参数

[root@zabbix ~]# cp /usr/local/php7/etc/php-fpm.d/www.conf /usr/local/php7/etc/php-fpm.d/www.conf.bak
[root@zabbix ~]# vim /usr/local/php7/etc/php-fpm.d/www.conf
user = nginx
group = nginx
pm = dynamic
pm.max_children = 130
pm.start_servers = 15
pm.min_spare_servers = 6
pm.max_spare_servers = 35

11、启动PHP-FPM并设置为开机自启

[root@zabbix ~]# /usr/local/sbin/php-fpm -t
[17-Mar-2020 15:20:02] NOTICE: configuration file /usr/local/php7/etc/php-fpm.conf test is successful

[root@zabbix ~]# /usr/local/sbin/php-fpm

[root@zabbix ~]# netstat -anput | grep 9000
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      47172/php-fpm: mast 

[root@zabbix ~]# chmod +x /etc/rc.d/rc.local 
[root@zabbix ~]# echo "/usr/local/sbin/php-fpm" >> /etc/rc.d/rc.local

二、Zabbix部署  

1)准备工作

1、安装依赖包

[root@zabbix ~]# yum -y install gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel libevent libevent-devel libssh2 libssh2-devel \
OpenIPMI OpenIPMI-devel OpenIPMI-libs OpenIPMI-perl OpenIPMI-python curl curl-devel libcurl libcurl-devel net-snmp net-snmp-devel openldap openldap-devel

2、为Zabbix创建运行用户与组

[root@zabbix ~]# groupadd zabbix
[root@zabbix ~]# useradd -M -s /sbin/nologin zabbix -g zabbix

3、下载软件包

[root@zabbix ~]# wget -c https://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.0.18/zabbix-4.0.18.tar.gz

2)安装并配置Zabbix

1、源码编译安装Zabbix

[root@zabbix ~]# tar xf zabbix-4.0.18.tar.gz -C /usr/src/
[root@zabbix ~]# cd /usr/src/zabbix-4.0.18
[root@zabbix zabbix-4.0.18]# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent \
--with-mysql --with-ldap --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml --with-ssh2 --with-openssl
[root@zabbix zabbix-4.0.18]# make -j 8 && make install && cd ~

2、复制执行文件至对应的目录

[root@zabbix ~]# cp /usr/local/zabbix/bin/* /usr/local/bin/
[root@zabbix ~]# cp /usr/local/zabbix/sbin/* /usr/local/sbin/

3、创建对应的存储目录

[root@zabbix ~]# mkdir /usr/local/zabbix/{pid,logs,socket}
[root@zabbix ~]# chown -R zabbix:zabbix /usr/local/zabbix

4、创建Zabbix使用的数据库并授权

[root@zabbix ~]# mysql -uroot -pabc-123 -e"create database zabbix;" 2> /dev/null
[root@zabbix ~]# mysql -uroot -pabc-123 -e"grant all privileges on zabbix.* to 'zabbix'@'10.2.3.%' identified by 'abc-123';" 2> /dev/null

5、导入初始化数据

[root@zabbix ~]# mysql -uzabbix -pabc-123 -h10.2.3.11 -P3635 zabbix < /usr/src/zabbix-4.0.18/database/mysql/schema.sql 2> /dev/null
[root@zabbix ~]# mysql -uzabbix -pabc-123 -h10.2.3.11 -P3635 zabbix < /usr/src/zabbix-4.0.18/database/mysql/images.sql 2> /dev/null
[root@zabbix ~]# mysql -uzabbix -pabc-123 -h10.2.3.11 -P3635 zabbix < /usr/src/zabbix-4.0.18/database/mysql/data.sql 2> /dev/null

6、复制Zabbix的前段代码文件到Nginx的发布目录

[root@zabbix ~]# cp -rp /usr/src/zabbix-4.0.18/frontends/php /usr/local/nginx/html/zabbix
[root@zabbix ~]# chown -R nginx:nginx /usr/local/nginx/html/zabbix

7、替换字体文件

Windows字体文件目录:C:\Windows\Fonts

注意:字体文件我已经上传到了服务器的根目录,所以这里只需将其原有的字体文件备份并将上传的字体文件重命名即可

#修改之前查看
[root@zabbix ~]# ll /usr/local/nginx/html/zabbix/assets/fonts/
总用量 740
-rw-r--r-- 1 nginx nginx 756072 2月  21 23:12 DejaVuSans.ttf

#备份现有字体文件
[root@zabbix ~]# mv /usr/local/nginx/html/zabbix/assets/fonts/DejaVuSans.ttf /usr/local/nginx/html/zabbix/assets/fonts/DejaVuSans.ttf.bak
[root@zabbix ~]# ll /usr/local/nginx/html/zabbix/assets/fonts/
总用量 740
-rw-r--r-- 1 nginx nginx 756072 2月  21 23:12 DejaVuSans.ttf.bak

#重命名新的字体文件
[root@zabbix ~]# mv /root/simkai.ttf /usr/local/nginx/html/zabbix/assets/fonts/DejaVuSans.ttf
[root@zabbix ~]# chown -R nginx:nginx /usr/local/nginx/html/zabbix/assets/fonts/

#修改之后查看
[root@zabbix ~]# ll /usr/local/nginx/html/zabbix/assets/fonts/
总用量 12252
-rw-r--r-- 1 root  root  11785184 4月  27 2016 DejaVuSans.ttf
-rw-r--r-- 1 nginx nginx   756072 2月  21 23:12 DejaVuSans.ttf.bak

8、定义zabbix_server配置文件

[root@zabbix ~]# cp /usr/local/zabbix/etc/zabbix_server.conf /usr/local/zabbix/etc/zabbix_server.conf.bak
[root@zabbix ~]# vim /usr/local/zabbix/etc/zabbix_server.conf
ListenIP=10.2.3.11
ListenPort=10051
LogFile=/usr/local/zabbix/logs/zabbix_server.log
LogFileSize=1
DebugLevel=3
PidFile=/usr/local/zabbix/pid/zabbix_server.pid
SocketDir=/usr/local/zabbix/socket

DBUser=zabbix
DBPassword=abc-123
DBHost=10.2.3.11
DBPort=3635
DBName=zabbix
DBSocket=/usr/local/mysql/socket/mysql.sock

Timeout=4
User=zabbix
StartPollers=6
StartIPMIPollers=0
StartPreprocessors=3
StartPollersUnreachable=1
StartTrappers=3
StartPingers=3
StartDiscoverers=3
StartHTTPPollers=1
StartTimers=1
StartEscalators=1
StartAlerters=3
CacheSize=9M
CacheUpdateFrequency=60
StartDBSyncers=4
HistoryCacheSize=16M
HistoryIndexCacheSize=5M
ValueCacheSize=8M
LogSlowQueries=2000

9、定义zabbix_agent配置文件

[root@zabbix ~]# cp /usr/local/zabbix/etc/zabbix_agentd.conf /usr/local/zabbix/etc/zabbix_agentd.conf.bak
[root@zabbix ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf
PidFile=/usr/local/zabbix/pid/zabbix_agentd.pid
LogType=file
LogFile=/usr/local/zabbix/logs//zabbix_agentd.log
LogFileSize=1
DebugLevel=3
ListenPort=10050
ListenIP=10.2.3.11
Timeout=3
UnsafeUserParameters=1
StartAgents=3

Server=10.2.3.11
Hostname=node1

10、定义Nginx配置文件

[root@zabbix ~]# vim /usr/local/nginx/conf/nginx.conf
user	nginx;	
worker_processes	auto;
worker_cpu_affinity	auto;
worker_rlimit_nofile	65535;

pid		/usr/local/nginx/logs/nginx.pid;
error_log	/usr/local/nginx/logs/error.log  info;

events	{
	use epoll;
	worker_connections  65535;
}

http	{
	include       mime.types;
	default_type  application/octet-stream;

	log_format mds  '$remote_addr - $remote_user [$time_local] "$request"'
                    	'$status $body_bytes_sent "$http_referer"'
                     	'"$http_user_agent" "$http_x_forwarded_for"';

    	access_log  logs/access.log  mds;

    	sendfile		on;
    	tcp_nopush		on;
    	tcp_nodelay		on;
    	send_timeout		10;
    	keepalive_timeout	60;
    	server_tokens 		off;
    	client_max_body_size  	512m;
    	fastcgi_buffers 	64 4K;
    	client_header_buffer_size  	15k;
    	large_client_header_buffers  4 128k;
    	open_file_cache_valid  		30s;
    	open_file_cache_min_uses 	2;
    	open_file_cache max=65535 inactive=20s;

    	gzip  on;
    	gzip_min_length		3k;
    	gzip_buffers     	4 16k;
    	gzip_http_version	1.1;
    	gzip_comp_level		1;
    	gzip_vary		on;
    	gzip_types		text/plain application/x-javascript text/css application/xml;

	server	{
		listen       	80;
        	server_name  	zabbix.mds.com;
        	charset 	utf-8;

    		root /usr/local/nginx/html/zabbix;

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

		location ~ \.php$ {
			fastcgi_index	index.php;
			fastcgi_pass 	127.0.0.1:9000;
			include 	fastcgi_params;
			fastcgi_param	SCRIPT_FILENAME $document_root$fastcgi_script_name;
                }
	}
}
[root@zabbix ~]# systemctl restart nginx

11、启动zabbix_server并设置为开机自启

#方法一:
[root@zabbix ~]# vim /etc/init.d/zabbix_server
#!/bin/bash
#chkconfig: 2345 90 25

# define zabbix name
ZB_NAME="zabbix_server"

# define zabbix install dir
BASEDIR="/usr/local/zabbix"

# define zabbix pidfile dir
PIDFILE="/usr/local/zabbix/pid"

# define zabbix confile dir
ZB_CONF="/usr/local/zabbix/etc"

case "$1" in
	start )
		# Start Zabbix
		echo -e "\033[32mStart ${ZB_NAME}...\033[0m"
		${BASEDIR}/sbin/${ZB_NAME} -c ${ZB_CONF}/${ZB_NAME}.conf 
;;
	stop )
		# Stop Zabbix
		echo -e "\033[34mStop ${ZB_NAME}....\033[0m"
		pkill -9 ${ZB_NAME} && rm -rf ${PIDFILE}/${ZB_NAME}.pid
		
;;
	restart )
		# Stop Zabbix
		echo -e "\033[34mStop ${ZB_NAME}....\033[0m"
		pkill -9 ${ZB_NAME} && rm -rf ${PIDFILE}/${ZB_NAME}.pid
		
		# Start Zabbix
		echo -e "\033[32mStart ${ZB_NAME}...\033[0m"
		${BASEDIR}/sbin/${ZB_NAME} -c ${ZB_CONF}/${ZB_NAME}.conf	

;;
	status )
		# examine Running status
		netstat -anput | grep ${ZB_NAME} | head -1
;;
	* )
		# explain zabbix usage
		echo -e "\033[31mUsage:"/etc/init.d/$0" {start | stop | restart | status}\033[0m"
;;
esac

[root@zabbix ~]# chmod +x /etc/init.d/zabbix_server 
[root@zabbix ~]# chkconfig --add /etc/init.d/zabbix_server


#方法二:
[root@zabbix ~]# zabbix_server -c /usr/local/zabbix/etc/zabbix_server.conf
[root@zabbix ~]# echo "zabbix_server -c /usr/local/zabbix/etc/zabbix_server.conf" >> /etc/rc.d/rc.local

12、启动zabbix_agent并设置为开机自启

#方法一:
[root@zabbix ~]# vim /etc/init.d/zabbix_agent
#!/bin/bash
#chkconfig: 2345 90 25

# define zabbix name
ZB_NAME="zabbix_agentd"

# define zabbix install dir
BASEDIR="/usr/local/zabbix"

# define zabbix pidfile dir
PIDFILE="/usr/local/zabbix/pid"

# define zabbix confile dir
ZB_CONF="/usr/local/zabbix/etc"

case "$1" in
	start )
		# Start Zabbix
		echo -e "\033[32mStart ${ZB_NAME}...\033[0m"
		${BASEDIR}/sbin/${ZB_NAME} -c ${ZB_CONF}/${ZB_NAME}.conf 
;;
	stop )
		# Stop Zabbix
		echo -e "\033[34mStop ${ZB_NAME}....\033[0m"
		pkill -9 ${ZB_NAME} && rm -rf ${PIDFILE}/${ZB_NAME}.pid
		
;;
	restart )
		# Stop Zabbix
		echo -e "\033[34mStop ${ZB_NAME}....\033[0m"
		pkill -9 ${ZB_NAME} && rm -rf ${PIDFILE}/${ZB_NAME}.pid
		
		# Start Zabbix
		echo -e "\033[32mStart ${ZB_NAME}...\033[0m"
		${BASEDIR}/sbin/${ZB_NAME} -c ${ZB_CONF}/${ZB_NAME}.conf	

;;
	status )
		# examine Running status
		netstat -anput | grep ${ZB_NAME} | head -1
;;
	* )
		# explain zabbix usage
		echo -e "\033[31mUsage:"/etc/init.d/$0" {start | stop | restart | status}\033[0m"
;;
esac

[root@zabbix ~]# chmod +x /etc/init.d/zabbix_agent
[root@zabbix ~]# chkconfig --add /etc/init.d/zabbix_agent


#方法二:
[root@zabbix ~]# zabbix_agentd -c /usr/local/zabbix/etc/zabbix_agentd.conf
[root@zabbix ~]# echo "zabbix_agentd -c /usr/local/zabbix/etc/zabbix_agentd.conf" >> /etc/rc.d/rc.local

三、Zabbix使用

默认用户:Admin

默认密码:zabbix

访问路径:http://10.2.3.11,回车之后,出现的界面如下所示

1)初始化Zabbix

 

 

 

 

 

 

 

 2)Zabbix基本配置

1、设置中文

 2、添加本身监控

 

 3、查看CPU负载状态

  

【一个人,一个地方,一首歌,一段回忆】

原文出处:https://www.cnblogs.com/lvthinks/p/12363954.html

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部