zabbix學習(一)——LNMP環境搭建及zabbix安裝

第一部分:LNMP環境搭建javascript

1、環境說明:php

OS:   centos7.6_x64
nginx:nginx-1.16.0
php:   php-7.1.11
mysql:mysql-5.6.44css

zabbix:zabbix-4.0.10html

2、安裝前準備:java

2.1 準備yum源node

# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
# yum -y install epel-release

2.2 安裝依賴關係mysql

# yum -y install gcc automake autoconf libtool make cmake gcc-c++ glibc pcre pcre-devel zlib zlib-devel openssl openssl-devel

3.3 建立目錄linux

# mkdir /data
# mkdir /data/package
# mkdir –p /data/server
# mkdir –p /data/webapps
# mkdir –p /data/logs

2、nginx安裝nginx

2.1 創建用戶c++

# groupadd -r nginx
# useradd -r -g nginx nginx

2.2 下載安裝包

# wget http://nginx.org/download/nginx-1.16.0.tar.gz

 

2.3 編譯安裝

# tar –zxvf nginx-1.16.0.tar.gz
# cd nginx-1.16.0/
./configure --prefix=/data/server/nginx-1.16.0 \
--sbin-path=/data/server/nginx-1.16.0/sbin/nginx \
--conf-path=/data/server/nginx-1.16.0/nginx.conf \
--pid-path=/data/server/nginx-1.16.0/nginx.pid \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--http-proxy-temp-path=/var/tmp/nginx/proxy/ \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
--http-scgi-temp-path=/var/tmp/nginx/scgi \
--with-select_module \
--with-poll_module \
--error-log-path=/data/logs/nginx/error.log \
--http-log-path=/data/logs/nginx/access.log \
--with-pcre

# make && make install

2.4 創建軟連接
方便之後升級,創建軟連接

# ln -sv /data/server/nginx-1.16.0 /data/server/nginx

2.5 爲nginx提供SysV init啓動腳本

新建文件/etc/rc.d/init.d/nginx,內容以下:

#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig:   - 85 15 
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /data/server/nginx/nginx.conf
# config:      /etc/sysconfig/nginx
# pidfile:     /data/server/nginx/nginx.pid
 
# Source function library.
. /etc/rc.d/init.d/functions
 
# Source networking configuration.
. /etc/sysconfig/network
 
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
 
nginx="/data/server/nginx/sbin/nginx"
prog=$(basename $nginx)
 
NGINX_CONF_FILE="/data/server/nginx/nginx.conf"
 
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
 
lockfile=/var/lock/subsys/nginx
 
make_dirs() {
   # make required directories
   user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
   options=`$nginx -V 2>&1 | grep 'configure arguments:'`
   for opt in $options; do
       if [ `echo $opt | grep '.*-temp-path'` ]; then
           value=`echo $opt | cut -d "=" -f 2`
           if [ ! -d "$value" ]; then
               # echo "creating" $value
               mkdir -p $value && chown -R $user $value
           fi
       fi
   done
}
 
start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    make_dirs
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}
 
stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}
 
restart() {
    configtest || return $?
    stop
    sleep 1
    start
}
 
reload() {
    configtest || return $?
    echo -n $"Reloading $prog: "
    killproc $nginx -HUP
    RETVAL=$?
    echo
}
 
force_reload() {
    restart
}
 
configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}
 
rh_status() {
    status $prog
}
 
rh_status_q() {
    rh_status >/dev/null 2>&1
}
 
case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac

 

2.6 爲此腳本賦予執行權限

# chmod +x /etc/rc.d/init.d/nginx

2.7 添加至服務管理列表,並讓其開機自動啓動:

# chkconfig --add nginx
# chkconfig nginx on

2.8 啓動nginx服務

# service nginx start

2.9 配置PATH環境變量

# echo 'export PATH=$PATH://data/server/nginx/sbin/' > /etc/profile.d/nginx.sh
# source /etc/profile.d/nginx.sh

2.10 配置nginx

編輯nginx主配置文件,以下,
# vim /data/server/nginx/nginx.conf user nginx nginx; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; sendfile on; tcp_nopush on; keepalive_timeout 65; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 2; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; tcp_nodelay on; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; include /data/server/nginx/conf.d/*.conf; } # 創建目錄 # mkdir /data/server/nginx/conf.d/ # mkdir -pv data/logs/nginx/{access,error}
# 創建一個虛擬主機 # vim /data/server/nginx/conf.d/default.conf server { listen 80; server_name localhost; index index.html; root /data/webapps; location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 1h; } access_log /data/logs/nginx/access/default.log main; error_log /data/logs/nginx/error/default.log; #僞靜態規則 include /data/server/nginx/conf.d/rewrite/default.conf; } # 僞靜態規則 # vim /data/server/nginx/conf.d/rewrite/default.conf rewrite ^(.*)-htm-(.*)$ $1.php?$2 last; rewrite ^(.*)/simple/([a-z0-9\_]+\.html)$ $1/simple/index.php?$2 last; rewrite ^(.*)/data/(.*)\.(htm|php)$ 404.html last; rewrite ^(.*)/attachment/(.*)\.(htm|php)$ 404.html last; rewrite ^(.*)/html/(.*)\.(htm|php)$ 404.html last; # 測試頁面 # echo 'test nginx' > /data/webapps/index.html # nginx -t # service nginx restart

 

3、安裝mysql

3.1 先檢查是否安裝了其它版本的mysql或mariadb

# rpm -qa|grep mariadb
  mariadb-libs-5.5.52-1.el7.x86_64
# rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64

3.2 創建mysql用戶及組

# groupadd mysql
# useradd -r -g mysql mysql

3.3 下載並安裝mysql

# wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.44-linux-glibc2.12-x86_64.tar.gz

# tar xf mysql-5.6.44-linux-glibc2.12-x86_64.tar.gz

# mv mysql-5.6.44-linux-glibc2.12-x86_64 /data/server/mysql-5.6.44

# ln -sv /data/server/mysql-5.6.44 /data/server/mysql

# chown -R mysql.mysql /data/server/mysql*

3.4 配置環境變量

# echo "export PATH=$PATH:/data/server/mysql/bin" > /etc/profile.d/mysql.sh
# source /etc/profile.d/mysql.sh

3.5 編輯mysql配置文件,以下:

# vim /etc/my.cnf
[mysqld]
basedir=/data/server/mysql
datadir=/data/mysql
socket=/data/server/mysql/mysql.sock
log-error=/data/logs/mysql/error.log
pid-file=/data/logs/mysql/mysql.pid
symbolic-links=0
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 
default-storage-engine = innodb
innodb_file_per_table
collation-server = utf8_general_ci
init-connect = 'SET NAMES utf8'
character-set-server = utf8
max_connections=1000
max_connect_errors=10000
thread_cache_size=100
thread_stack=192K
ssl=false
max_allowed_packet=60M
max_heap_table_size=64M
max_length_for_sort_data=8M
net_buffer_length=65536
skip-name-resolve ##ip/localhost
skip-external-locking ##system lock

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[client]
socket=/data/server/mysql/mysql.sock

[mysql]
socket=/data/server/mysql/mysql.sock


3.6 準備啓動腳本

# cp /data/server/mysql/support-files/mysql.server /etc/init.d/mysqld
# vim /etc/init.d/mysqld    # 修改basedir和datadir 和/etc/my.cnf保持一致
 …………

  basedir=/data/server/mysql
  datadir=/data/mysql

 …………

# 添加服務
# chkconfig --add mysqld

3.7 初始化mysql

# mysql_install_db --user=mysql --basedir=/data/server/mysql/ --datadir=/data/mysql

3.8 啓動mysql並設置開機自啓動

# service enable mysqld && service sttart mysqld

mysql> delete from mysql.user where user = '' or host = '::1';

3.8 爲了使用mysql的安裝符合系統使用規範,並將其開發組件導出給系統使用,這裏還須要進行以下步驟:

輸出mysql的man手冊至man命令的查找路徑:

編輯/etc/man.config,添加以下行便可:
# echo "/data/server/mysql/man" >> /etc/man_db.conf

輸出mysql的頭文件至系統頭文件路徑/usr/include:

這能夠經過簡單的建立連接實現:
# ln -sv /data/server/mysql/include /usr/include/mysql

輸出mysql的庫文件給系統庫查找路徑:

# echo '/data/server/mysql/lib' > /etc/ld.so.conf.d/mysql.conf

然後讓系統從新載入系統庫:
# ldconfig

4、安裝php

4.1 下載php

# wget http://cn2.php.net/distributions/php-7.1.11.tar.gz

4.2 安裝依賴擴展包

# yum -y install libmcrypt libmcrypt-devel mhash mhash-devel mcrypt libxml2-devel bzip2-devel libcurl-devel libjpeg-devel libpng libpng-devel freetype freetype-devel libmcrypt libmcrypt-devel

4.3 編譯安裝php

# tar xf php-7.1.11.tar.gz
# cd /root/php-7.1.11
# ./configure --prefix=/data/server/php-7.1.11 \
--with-config-file-path=/data/server/php-7.1.11/etc \
--enable-fpm \
--with-mcrypt \
--enable-mbstring \
--enable-pdo \
--with-curl \
--disable-debug \
--disable-rpath \
--enable-inline-optimization \
--with-bz2 \
--with-zlib \
--enable-sockets \
--enable-sysvsem \
--enable-sysvshm \
--enable-pcntl \
--enable-mbregex \
--with-mhash \
--enable-zip \
--with-pcre-regex \
--with-mysqli=/data/server/mysql/bin/mysql_config \
--with-gd \
--with-jpeg-dir \
--with-freetype-dir \
--with-png-dir \
--enable-calendar \
--with-openssl \
--with-bcmath \
--with-gettext

# make && make install
# ln -sv /data/server/php-7.1.11 /data/server/php

4.4 準備php配置文件

# cp php.ini-production /data/server/php/etc/php.ini

4.5 爲php-fpm提供配置文件:

# cp /data/server/php/etc/php-fpm.conf.default /data/server/php/etc/php-fpm.conf

4.6 編輯php-fpm的配置文件:

# vim /data/server/php/etc/php-fpm.conf
取消pid的註釋
……
[global]

pid = run/php-fpm.pid
……
# cp /data/server/php/etc/php-fpm.d/www.conf.default /data/server/php/etc/php-fpm.d/www.conf

4.7 設置環境變量

# echo 'export PATH=$PATH:/data/server/php/sbin' > /etc/profile.d/php-fpm.sh
# echo 'export PATH=/data/server/php/bin:$PATH' >> /etc/profile.d/php-fpm.sh
# source /etc/profile.d/php-fpm.sh

4.8 爲php-fpm提供Sysv init腳本,並將其添加至服務列表:

# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
# chmod +x /etc/rc.d/init.d/php-fpm
# chkconfig --add php-fpm
# chkconfig php-fpm on

接下來就能夠啓動php-fpm了:
# systemctl start php-fpm

5、整合nginx和php5

5.1 編輯nginx.conf,啓用以下選項:

# vi /data/server/nginx/nginx.conf
location ~ \.(php|php5)$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}

5.2 編輯/data/server/nginx/fastcgi_params,將其內容更改成以下內容:

# cp fastcgi_params{,.bak}
# vim /data/server/nginx/fastcgi_params
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

並在所支持的主頁面格式中添加php格式的主頁,相似以下:
location / {
root html;
index index.php index.html index.htm;
}

5.3 完整的配置文件以下:

# cat /data/server/nginx/conf.d/default.conf 
server {
listen 80;
server_name localhost;
index index.php index.html index.htm;
root /data/webapps;
location ~ \.(php|php5)$ {
root /data/webapps;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
access_log /data/logs/nginx/access/default.log main;
error_log /data/logs/nginx/error/default.log; 
}

然後從新載入nginx的配置文件:
# service nginx reload

5.4 在/data/webapps新建index.php的測試頁面,測試php是否能正常工做及可否鏈接數據庫:

mysql> create user 'test'@'localhost' identified by 'test123';
mysql> flush privileges;

接着就能夠經過瀏覽器訪問此測試頁面了。
# vim /data/webapps/index.php 
<?php
$servername = "localhost";
$username = "test";
$password = "test123";

// 建立鏈接
$conn = new mysqli($servername, $username, $password);

// 檢測鏈接
if ($conn->connect_error) {
die("鏈接失敗: " . $conn->connect_error);
} 
echo "鏈接成功";
?>

<?php
phpinfo();
?>

6、安裝php擴展,爲php

xcache不支持php7.1了,使用php原生的opcache代替

# vim /data/server/php/etc/php.ini

zend_extension=opcache.so
[opcache]
;開啓opcache
opcache.enable=1  

;CLI環境下,PHP啓用OPcache
opcache.enable_cli=1

;OPcache共享內存存儲大小,單位MB
opcache.memory_consumption=128  

;PHP使用了一種叫作字符串駐留(string interning)的技術來改善性能。例如,若是你在代碼中使用了1000次字符串「foobar」,在PHP內部只會在第一使用這個字符串的時候分配一個不可變的內存區域來存儲這個字符串,其餘的999次使用都會直接指向這個內存區域。這個選項則會把這個特性提高一個層次——默認狀況下這個不可變的內存區域只會存在於單個php-fpm的進程中,若是設置了這個選項,那麼它將會在全部的php-fpm進程中共享。在比較大的應用中,這能夠很是有效地節約內存,提升應用的性能。
這個選項的值是以兆字節(megabytes)做爲單位,若是把它設置爲16,則表示16MB,默認是4MB
opcache.interned_strings_buffer=8

;這個選項用於控制內存中最多能夠緩存多少個PHP文件。這個選項必須得設置得足夠大,大於你的項目中的全部PHP文件的總和。
設置值取值範圍最小值是 200,最大值在 PHP 5.5.6 以前是 100000,PHP 5.5.6 及以後是 1000000。也就是說在200到1000000之間。
opcache.max_accelerated_files=4000

;設置緩存的過時時間(單位是秒),爲0的話每次都要檢查
opcache.revalidate_freq=60

;從字面上理解就是「容許更快速關閉」。它的做用是在單個請求結束時提供一種更快速的機制來調用代碼中的析構器,從而加快PHP的響應速度和PHP進程資源的回收速度,這樣應用程序能夠更快速地響應下一個請求。把它設置爲1就可使用這個機制了。
opcache.fast_shutdown=1

;若是啓用(設置爲1),OPcache會在opcache.revalidate_freq設置的秒數去檢測文件的時間戳(timestamp)檢查腳本是否更新。
若是這個選項被禁用(設置爲0),opcache.revalidate_freq會被忽略,PHP文件永遠不會被檢查。這意味着若是你修改了你的代碼,而後你把它更新到服務器上,再在瀏覽器上請求更新的代碼對應的功能,你會看不到更新的效果
強烈建議你在生產環境中設置爲0,更新代碼後,再平滑重啓PHP和web服務器。
opcache.validate_timestamps=0 

;開啓Opcache File Cache(實驗性), 經過開啓這個, 咱們可讓Opcache把opcode緩存緩存到外部文件中, 對於一些腳本, 會有很明顯的性能提高.
這樣PHP就會在/tmp目錄下Cache一些Opcode的二進制導出文件, 能夠跨PHP生命週期存在.
opcache.file_cache=/tmp

6.2 從新啓動php-fpm

# service php-fpm restart

7、如何安裝第三方php擴展模塊

7.1 安裝在源碼包中帶的擴展模塊bcmatch

# cd /tmp/lnmp/php-7.1.11/ext/bcmath/

# /data/server/php/bin/phpize

# ./configure --with-php-config=/data/server/php/bin/php-config

# make && make install

安裝完成的模塊在下面的目錄下
Installing shared extensions: /data/server/php-7.1.11/lib/php/extensions/no-debug-non-zts-20160303/

 # ls -lhrt /data/server/php-7.1.11/lib/php/extensions/no-debug-non-zts-20160303/
  total 5.2M
 -rwxr-xr-x 1 root root 3.3M Jul 16 14:11 opcache.a
 -rwxr-xr-x 1 root root 1.6M Jul 16 14:11 opcache.so
 -rwxr-xr-x 1 root root 357K Jul 16 16:56 bcmath.so
 -rwxr-xr-x 1 root root 52K Jul 16 20:07 gettext.so

 

7.2 編輯配置文件,啓用

# vim /data/server/php-7.1.11/etc/php.ini 
[bcmath]

extension=bcmath.so

 

第二部分:zabbix安裝

一、安裝Zabbix Server

1.1 先安裝依賴包

# yum -y install net-snmp gcc mysql-devel libxml2-devel net-snmp-devel libevent-devel curl-devel

1.2 下載軟件包

# wget https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/4.0.10/zabbix-4.0.10.tar.gz/download

1.3 建立用戶

# groupadd --system zabbix
# useradd --system -g zabbix -M -s /sbin/nologin -c "Zabbix Monitoring System" zabbix

1.4 建立數據庫

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

1.5 導入數據庫

# cd database/mysql
# mysql -uzabbix -pzabbix zabbix < schema.sql
# stop here if you are creating database for Zabbix proxy
# mysql -uzabbix -pzabbix zabbix < images.sql
# mysql -uzabbix -pzabbix zabbix < data.sql

1.6 編譯安裝

# tar -zxvf zabbix-4.0.10.tar.gz
# ./configure --help
./configure --prefix=/data/server/zabbix-4.0.10 \
--enable-server \
--enable-agent \
--with-mysql \
--enable-ipv6 \
--with-net-snmp \
--with-libcurl \
--with-libxml2

# make install

# ln -sv /data/server/zabbix-4.0.10 /data/server/zabbix

1.7 配置環境變量

# echo 'export PATH=$PATH:/data/server/zabbix/sbin' > /etc/profile.d/zabbix.sh
# source /etc/profile.d/zabbix.sh

1.8 編輯zabbix_server.conf

# vim /data/server/zabbix/etc/zabbix_server.conf
DBPassword=zabbix

1.9 安裝zabbix
拷貝網頁文件至web服務器目錄下

# mkdir /data/webapps/zabbix
# cp -ap frontends/php/* /data/webapps/zabbix/

1.10 編輯php配置,以知足zabbix要求

# vim /data/server/php/etc/php.ini 
post_max_size = 16M
max_execution_time = 300
max_input_time = 300

1.11 準備zabbix server的啓動腳本

# vim /etc/rc.d/init.d/zabbix_server 

#!/bin/sh
#
# zabbix server - this script starts and stops the zabbix server daemon
#
# chkconfig:   - 85 15 
# description:  Zabbix Server is an Monitor server
# processname: zabbix
# config:     /data/server/zabbix/etc/zabbix_server.conf
# pidfile:    /tmp/zabbix_server.pid
 
# Source function library.
. /etc/rc.d/init.d/functions
 
# Source networking configuration.
. /etc/sysconfig/network
 
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
 
zabbix_server="/data/server/zabbix/sbin/zabbix_server"
prog=$(basename $zabbix_server)
ZABBIX_SERVER_CONF_FILE="/data/server/zabbix/etc/zabbix_server.conf"
lockfile=/var/lock/subsys/zabbix_server

start() {
    [ -x $zabbix_server ] || exit 5
    [ -f $ZABBIX_SERVER_CONF_FILE ] || exit 6
    echo -n $"Starting $prog: "
    daemon $zabbix_server -c $ZABBIX_SERVER_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}
 
stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}
 
restart() {
    stop
    sleep 1
    start
}
 
rh_status() {
    status $prog
}


case "$1" in
    start)
        rh_status && exit 0
        $1
        ;;
    stop)
        rh_status || exit 0
        $1
        ;;
    restart)
        $1
        ;;
    status)
        rh_status
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart}"
        exit 2
esac

1.12 啓動zabbix_server

加入系統自啓動
# chkconfig --add zabbix_server # chkconfig zabbix_server on
# service zabbix_server start

二、安裝zabbix agent

2.1 編譯安裝agent

# ./configure --prefix=/data/server/zabbix-4.0.10 \
--enable-agent \
--with-mysql \
--enable-ipv6 \
--with-net-snmp \
--with-libcurl \
--with-libxml2

# make install

2.2 編輯配置文件

# vim /data/server/zabbix/etc/zabbix_agentd.conf
Server=127.0.0.1
ServerActive=127.0.0.1
Hostname=Zabbix server

2.3 準備zabbix_agentd啓動腳本

# vim /etc/rc.d/init.d/zabbix_agentd 

#!/bin/sh
#
# zabbix agent - this script starts and stops the zabbix agent daemon
#
# chkconfig:   - 85 15 
# description:  Zabbix agentd is an Monitor agent
# processname: zabbix_agentd
# config:     /data/server/zabbix/etc/zabbix_agentd.conf
# pidfile:    /tmp/zabbix_agentd.pid
 
# Source function library.
. /etc/rc.d/init.d/functions
 
# Source networking configuration.
. /etc/sysconfig/network
 
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
 
zabbix_agentd="/data/server/zabbix/sbin/zabbix_agentd"
prog=$(basename $zabbix_agentd)
ZABBIX_AGENTD_CONF_FILE="/data/server/zabbix/etc/zabbix_agentd.conf"
lockfile=/var/lock/subsys/zabbix_agentd

start() {
    [ -x $zabbix_agentd ] || exit 5
    [ -f $ZABBIX_AGENTD_CONF_FILE ] || exit 6
    echo -n $"Starting $prog: "
    daemon $zabbix_agentd -c $ZABBIX_AGENTD_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}
 
stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}
 
restart() {
    stop
    sleep 1
    start
}
 
rh_status() {
    status $prog
}

case "$1" in
    start)
        rh_status && exit 0
        $1
        ;;
    stop)
        rh_status || exit 0
        $1
        ;;
    restart)
        $1
        ;;
    status)
        rh_status
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart}"
        exit 2
esac

 

2.4 啓動zabbix_agent

加入系統自啓動
# chkconfig --add zabbix_agentd
# chkconfig zabbix_agentd on
# service zabbix_agentd start

 

參考連接:https://www.zabbix.com/documentation/4.0/manual/installation/install

相關文章
相關標籤/搜索