centos7安裝zabbix3.4,Nginx1.14+PHP7.2+MySQL5.7


更新yum源,並更新系統

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

yum update

安裝支持庫

yum -y install wget vim lsof lrzsz pcre-devel zlib-devel make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel libmcrypt libmcrypt-devel mcrypt mhash net-snmp-devel

yum -y install gcc bison bison-devel openssl-devel readline-devel libedit-devel sqlite-devel freetype freetype-devel libevent-devel mysql-devel

 

關閉防火牆和selinux

systemctl stop firewalld.service #停止firewall

systemctl disable firewalld.service #禁止firewall開機啟動

setenforce 0

注意:安裝包統一放在cd /opt/

wget http://nginx.org/download/nginx-1.4.0.tar.gz

wget http://mirrors.sohu.com/php/php-7.2.6.tar.gz

wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz

wget https://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.4.10/zabbix-3.4.10.tar.gz

 

安裝nginx

cd /opt/

tar -zxf nginx-1.4.0.tar.gz

cd nginx-1.4.0

./configure --prefix=/usr/local/nginx --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module  --with-pcre

make && make install 

chown -R nobody:nobody /usr/local/nginx/

 

配置啟動文件

vim /etc/init.d/nginx

#!/bin/bash

# chkconfig: - 30 21

# description: http service.

# Source Function Library

. /etc/init.d/functions

# Nginx Settings

NGINX_SBIN="/usr/local/nginx/sbin/nginx"

NGINX_CONF="/usr/local/nginx/conf/nginx.conf"

NGINX_PID="/usr/local/nginx/logs/nginx.pid"

RETVAL=0

prog="Nginx"

start() {

        echo -n $"Starting $prog: "

        mkdir -p /dev/shm/nginx_temp

        daemon $NGINX_SBIN -c $NGINX_CONF

        RETVAL=$?

        echo

        return $RETVAL

}

stop() {

        echo -n $"Stopping $prog: "

        killproc -p $NGINX_PID $NGINX_SBIN -TERM

        rm -rf /dev/shm/nginx_temp

        RETVAL=$?

        echo

        return $RETVAL

}

reload(){

        echo -n $"Reloading $prog: "

        killproc -p $NGINX_PID $NGINX_SBIN -HUP

        RETVAL=$?

        echo

        return $RETVAL

}

restart(){

        stop

        start

}

configtest(){

    $NGINX_SBIN -c $NGINX_CONF -t

    return 0

} 

case "$1" in

  start)

        start

        ;;

  stop)

        stop

        ;;

  reload)

        reload

        ;;

  restart)

        restart

        ;;

  configtest)

        configtest

        ;;

  *)

        echo $"Usage: $0 {start|stop|reload|restart|configtest}"

        RETVAL=1

esac 

exit $RETVAL
chmod +x /etc/init.d/nginx

添加開機自啟

chkconfig nginx on

 

編輯nginx配置文件:

vi /usr/local/nginx/conf/nginx.conf

user nobody nobody;

worker_processes 2;

error_log /usr/local/nginx/logs/nginx_error.log crit;

pid /usr/local/nginx/logs/nginx.pid;

worker_rlimit_nofile 51200;

events

{

    use epoll;

    worker_connections 6000;

}

http

{

    include mime.types;

    default_type application/octet-stream;

    server_names_hash_bucket_size 3526;

    server_names_hash_max_size 4096;

    log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'

    '$host "$request_uri" $status'

    '"$http_referer" "$http_user_agent"';

    sendfile on;

    tcp_nopush on;

    keepalive_timeout 30;

    client_header_timeout 3m;

    client_body_timeout 3m;

    send_timeout 3m;

    connection_pool_size 256;

    client_header_buffer_size 1k;

    large_client_header_buffers 8 4k;

    request_pool_size 4k;

    output_buffers 4 32k;

    postpone_output 1460;

    client_max_body_size 10m;

    client_body_buffer_size 256k;

    client_body_temp_path /usr/local/nginx/client_body_temp;

    proxy_temp_path /usr/local/nginx/proxy_temp;

    fastcgi_temp_path /usr/local/nginx/fastcgi_temp;

    fastcgi_intercept_errors on;

    tcp_nodelay on;

    gzip on;

    gzip_min_length 1k;

    gzip_buffers 4 8k;

    gzip_comp_level 5;

    gzip_http_version 1.1;

    gzip_types text/plain application/x-javascript text/css text/htm application/xml;

server

{

    listen 85;

    server_name localhost;

    index index.html index.htm index.php;

    root /usr/local/nginx/html;

    location ~ \.php$ {

        include fastcgi_params;

        fastcgi_pass unix:/tmp/php-fcgi.sock;

        fastcgi_index index.php;

        fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;

    }

} 

}

檢查語法:

/usr/local/nginx/sbin/nginx  -t

service nginx start #啟動nginx

 檢查進程和端口

[root@data-node1 local]# ps -ef|grep nginx
root      14505      1  0 15:33 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody    14506  14505  0 15:33 ?        00:00:00 nginx: worker process

[root@data-node1 local]# netstat -tunpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name           
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      14505/nginx: master

 

安裝php

useradd -s /sbin/nologin php-fpm

cd /opt/

tar -zxvf php-7.2.6.tar.gz

cd php-7.2.6

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=mysqlnd  --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --disable-ipv6 --with-pear --with-curl --enable-bcmath --enable-mbstring --enable-sockets --with-gd --with-libxml-dir=/usr/local --with-gettext

報錯處理

解決
使用yum命令安裝

yum  install  php-mcrypt  libmcrypt  libmcrypt-devel 

報錯

今天安裝PHP的時候提示這個錯誤 configure: error: png.h not found.,這個是選擇安裝GD模塊才會出現的錯誤

解決

經查資料說是libpng,devel包沒安裝,

執行下面兩條命令即可解決

yum install libpng-devel libpng

然后重新編譯安裝就行了 

報錯

configure: error: libxml2 not found. Please check your libxml2 installation.

解決: 

yum -y install libxml2-devel

重新執行上面配置:

報錯:

 configure: error: Cannot find OpenSSL's <evp.h>

解決:

 yum install openssl-devel 

報錯:

 checking for cURL 7.10.5 or greater... configure: error: cURL version 7.10.5 or later is required to compile php with cURL support

解決:

  yum -y install curl-devel   

報錯: 

configure: error: jpeglib.h not found.

解決:

 yum install libjpeg-devel  

報錯:

 configure: error: freetype-config not found.

 解決:

yum -y install freetype-devel

 

解決過上面報錯信息,我們重新執行一下上面./configure 的所有命令: 

出現   Thank you for using PHP. 證明我們配置成功了

configure: creating ./config.status

creating main/internal_functions.c
creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE.  By continuing this installation |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+


Thank you for using PHP.


config.status: creating php7.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/fpm/php-fpm.conf
config.status: creating sapi/fpm/www.conf
config.status: creating sapi/fpm/init.d.php-fpm
config.status: creating sapi/fpm/php-fpm.service
config.status: creating sapi/fpm/php-fpm.8
config.status: creating sapi/fpm/status.html
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands

configure: WARNING: unrecognized options: --with-mcrypt, --with-mysql, --enable-gd-native-ttf, --enable-redis, --enable-fastcgi

//這里會出現上面的warning 是因為configure命令沒有識別出來,這個configure大家根據自己需求進行配置,我是參考其他人的使用的

在編譯安裝時,
提示unrecognized options: –with-mcrypt, –enable-gd-native-ttf
表示php7.2不支持這兩個選項,
把上面兩個編譯選項刪除就可以了。

在phh7.1時,
官方就開始建議用openssl_*系列函數代替Mcrypt_*系列的函數。

編譯和編譯安裝

make && make install 

最后結果如下:

Installing shared extensions:     /usr/local/php7/lib/php/extensions/no-debug-non-zts-20170718/
Installing PHP CLI binary:        /usr/local/php7/bin/
Installing PHP CLI man page:      /usr/local/php7/php/man/man1/
Installing PHP FPM binary:        /usr/local/php7/sbin/
Installing PHP FPM defconfig:     /usr/local/php7/etc/
Installing PHP FPM man page:      /usr/local/php7/php/man/man8/
Installing PHP FPM status page:   /usr/local/php7/php/php/fpm/
Installing phpdbg binary:         /usr/local/php7/bin/
Installing phpdbg man page:       /usr/local/php7/php/man/man1/
Installing PHP CGI binary:        /usr/local/php7/bin/
Installing PHP CGI man page:      /usr/local/php7/php/man/man1/
Installing build environment:     /usr/local/php7/lib/php/build/
Installing header files:          /usr/local/php7/include/php/
Installing helper programs:       /usr/local/php7/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/php7/php/man/man1/
  page: phpize.1
  page: php-config.1
/usr/local/src/php-7.2.4/build/shtool install -c ext/phar/phar.phar /usr/local/php7/bin
ln -s -f phar.phar /usr/local/php7/bin/phar
Installing PDO headers:           /usr/local/php7/include/php/ext/pdo/

 

[root@localhost php-7.2.4]# echo $?

0

證明我們安裝成功了

cp php.ini-production /usr/local/php/etc/php.ini

更改php.ini文件

 

sed-i's/post_max_size = 8M/post_max_size = 32M/g' /usr/local/php/etc/php.ini
sed-i's/upload_max_filesize = 2M/upload_max_filesize = 50M/g' /usr/local/php/etc/php.ini
sed-i's/;date.timezone =/date.timezone =PRC/' /usr/local/php/etc/php.ini
sed-i's/max_execution_time = 30/max_execution_time = 600/g' /usr/local/php/etc/php.ini
sed-i's/max_input_time = 60/max_input_time = 600/g' /usr/local/php/etc/php.ini
sed-i's/memory_limit = 128M/memory_limit = 256M/g'/usr/local/php/etc/php.ini

 

配置php-fpm.conf

vim /usr/local/php/etc/php-fpm.conf

[global]

pid = /usr/local/php/var/run/php-fpm.pid

error_log = /usr/local/php/var/log/php-fpm.log

[www]

listen = /tmp/php-fcgi.sock

user = php-fpm

group = php-fpm

listen.owner = nobody

listen.group = nobody

pm = dynamic

pm.max_children = 50

pm.start_servers = 20

pm.min_spare_servers = 5

pm.max_spare_servers = 35

pm.max_requests = 500

rlimit_files = 1024

檢查語法

/usr/local/php/sbin/php-fpm -t

啟動php

/usr/local/php/sbin/php-fpm

添加php-fpm啟動腳本

/etc/init.d/ 文件夾下的php-fpm腳步文件

vim /etc/init.d/php-fpm

php啟動腳本

#! /bin/sh

### BEGIN INIT INFO
# Provides:          php-fpm
# Required-Start:    $remote_fs $network
# Required-Stop:     $remote_fs $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts php-fpm
# Description:       starts the PHP FastCGI Process Manager daemon
### END INIT INFO

prefix=/usr/local/php
exec_prefix=${prefix}

php_fpm_BIN=${exec_prefix}/sbin/php-fpm
php_fpm_CONF=${prefix}/etc/php-fpm.conf
php_fpm_PID=${prefix}/var/run/php-fpm.pid


php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID"


wait_for_pid () {
    try=0

    while test $try -lt 35 ; do

        case "$1" in
            'created')
            if [ -f "$2" ] ; then
                try=''
                break
            fi
            ;;

            'removed')
            if [ ! -f "$2" ] ; then
                try=''
                break
            fi
            ;;
        esac

        echo -n .
        try=`expr $try + 1`
        sleep 1

    done

}

case "$1" in
    start)
        echo -n "Starting php-fpm "

        $php_fpm_BIN --daemonize $php_opts

        if [ "$?" != 0 ] ; then
            echo " failed"
            exit 1
        fi

        wait_for_pid created $php_fpm_PID

        if [ -n "$try" ] ; then
            echo " failed"
            exit 1
        else
            echo " done"
        fi
    ;;

    stop)
        echo -n "Gracefully shutting down php-fpm "

        if [ ! -r $php_fpm_PID ] ; then
            echo "warning, no pid file found - php-fpm is not running ?"
            exit 1
        fi

        kill -QUIT `cat $php_fpm_PID`

        wait_for_pid removed $php_fpm_PID

        if [ -n "$try" ] ; then
            echo " failed. Use force-quit"
            exit 1
        else
            echo " done"
        fi
    ;;

    status)
        if [ ! -r $php_fpm_PID ] ; then
            echo "php-fpm is stopped"
            exit 0
        fi

        PID=`cat $php_fpm_PID`
        if ps -p $PID | grep -q $PID; then
            echo "php-fpm (pid $PID) is running..."
        else
            echo "php-fpm dead but pid file exists"
        fi
    ;;

    force-quit)
        echo -n "Terminating php-fpm "

        if [ ! -r $php_fpm_PID ] ; then
            echo "warning, no pid file found - php-fpm is not running ?"
            exit 1
        fi

        kill -TERM `cat $php_fpm_PID`

        wait_for_pid removed $php_fpm_PID

        if [ -n "$try" ] ; then
            echo " failed"
            exit 1
        else
            echo " done"
        fi
    ;;

    restart)
        $0 stop
        $0 start
    ;;

    reload)

        echo -n "Reload service php-fpm "

        if [ ! -r $php_fpm_PID ] ; then
            echo "warning, no pid file found - php-fpm is not running ?"
            exit 1
        fi

        kill -USR2 `cat $php_fpm_PID`

        echo " done"
    ;;

    *)
        echo "Usage: $0 {start|stop|force-quit|restart|reload|status}"
        exit 1
    ;;

esac
chkconfig --add /etc/init.d/php-fpm

chkconfig --level 3 php-fpm on

添加到開機自啟動

加權限並啟動服務

chmod +x  /etc/init.d/php-fpm
[root@web1 init.d]# /etc/init.d/php-fpm stop
Gracefully shutting down php-fpm . done
[root@web1 init.d]# 
[root@web1 init.d]# 
[root@web1 init.d]# ps -ef|grep php-fpm     
root      41607  34132  0 14:30 pts/2    00:00:00 grep --color=auto php-fpm
[root@web1 init.d]# 
[root@web1 init.d]# 
[root@web1 init.d]# 
[root@web1 init.d]# /etc/init.d/php-fpm start
Starting php-fpm  done
[root@web1 init.d]# 
[root@web1 init.d]# 
[root@web1 init.d]# ps -ef|grep php-fpm      
root      41615      1  0 14:30 ?        00:00:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
php-fpm   41616  41615  0 14:30 ?        00:00:00 php-fpm: pool www
php-fpm   41617  41615  0 14:30 ?        00:00:00 php-fpm: pool www
php-fpm   41618  41615  0 14:30 ?        00:00:00 php-fpm: pool www
php-fpm   41619  41615  0 14:30 ?        00:00:00 php-fpm: pool www
php-fpm   41620  41615  0 14:30 ?        00:00:00 php-fpm: pool www
php-fpm   41621  41615  0 14:30 ?        00:00:00 php-fpm: pool www
php-fpm   41622  41615  0 14:30 ?        00:00:00 php-fpm: pool www
php-fpm   41623  41615  0 14:30 ?        00:00:00 php-fpm: pool www
php-fpm   41624  41615  0 14:30 ?        00:00:00 php-fpm: pool www
php-fpm   41625  41615  0 14:30 ?        00:00:00 php-fpm: pool www
php-fpm   41626  41615  0 14:30 ?        00:00:00 php-fpm: pool www
php-fpm   41627  41615  0 14:30 ?        00:00:00 php-fpm: pool www
php-fpm   41628  41615  0 14:30 ?        00:00:00 php-fpm: pool www
php-fpm   41629  41615  0 14:30 ?        00:00:00 php-fpm: pool www
php-fpm   41630  41615  0 14:30 ?        00:00:00 php-fpm: pool www
php-fpm   41631  41615  0 14:30 ?        00:00:00 php-fpm: pool www
php-fpm   41632  41615  0 14:30 ?        00:00:00 php-fpm: pool www
php-fpm   41633  41615  0 14:30 ?        00:00:00 php-fpm: pool www
php-fpm   41634  41615  0 14:30 ?        00:00:00 php-fpm: pool www
php-fpm   41635  41615  0 14:30 ?        00:00:00 php-fpm: pool www
root      41641  34132  0 14:30 pts/2    00:00:00 grep --color=auto php-fpm
vim /usr/local/nginx/html/a.php

內容如下:

<?php echo phpinfo();?>

下載zabbix編譯包:

cd /opt/

groupadd zabbix

useradd -g zabbix zabbix

tar -zxf zabbix-3.4.10.tar.gz

cd zabbix-3.4.10

./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2

make && make install 

mkdir -p /usr/local/nginx/html/zabbix

cp -ra frontends/php/* /usr/local/nginx/html/zabbix

安裝數據庫

安裝文檔博客里面有!!!

創建zabbix數據庫,用戶及授權!

 

mysql -uroot -p
mysql> create database if not exists zabbix default character set utf8 collate utf8_general_ci;


進入zabbix庫里面

mysql> use zabbix;

查看當前庫

select database();

find / -name schema.sql(找出要導入數據文件相關路徑)

mysql> source /opt/zabbix-3.4.10/database/mysql/schema.sql;

mysql> source /opt/zabbix-3.4.10/database/mysql/images.sql;
mysql> source /opt/zabbix-3.4.10/database/mysql/data.sql;
grant all privileges on zabbix.* to zabbix@'localhost' identified by 'zabbix';

#允許賬戶zabbix能從本機連接到數據庫zabbix

///zabbix 是你的zabbix表名。

///zabbix 是你的MySql用戶名

///127.0.0.1 是你限制之能這個IP登錄這個賬號,寫成localhost也和127.0.0.1同樣,表示只能本機訪問,如果寫成 % 的意思是任何IP都可以連接。

delete from mysql.user where user=""; 

flush privileges;

 

備份配置文件

cd /usr/local/zabbix/etc/
cp zabbix_agentd.conf zabbix_agentd.conf.bak 

cp zabbix_server.conf zabbix_server.conf.bak

[root@xuegod64 ~]# vim /usr/local/zabbix/etc/zabbix_server.conf

LogFile=/usr/local/zabbix/logs/zabbix_server.log 

PidFile=/tmp/zabbix_server.pid
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix    #(zabbix用戶的密碼)

DBSocket=/tmp/mysql.sock

AlertScriptsPath=/usr/local/zabbix/alertscripts


創建自定義腳本目錄,設置權限,目錄下的腳步,可以被zabbix調用

mkdir /usr/local/zabbix/alertscripts
chown zabbix.zabbix -R /usr/local/zabbix

監控Zabbix Server本身

監控本身,意思是本身作為服務器之外,自己也做自己的客戶端,也要使用agentd這個代理者

配置文件中,有agentd和agent兩個配置文件,前者是守護進程,后者依賴xinetd

[root@xuegod64 ~]# vi /usr/local/zabbix/etc/zabbix_agentd.conf

Server=127.0.0.1 #默認監控服務器自己,這三行不用改

ServerActive=127.0.0.1

Hostname=Zabbix server

PidFile=/tmp/zabbix_agentd.pid
LogFile=/usr/local/zabbix/logs/zabbix_agentd.log

UnsafeUserParameters=1 #允許所有的字符是在用戶定義的參數,參數傳遞,也就是支持自定義腳本

其中Server和ServerActive都指定zabbixserver的IP地址,不同的是,前者是被動后者是主動。也就是說前者允許127.0.0.1這個ip來我這取數據。而serverActive的127.0.0.1的意思是,客戶端主動提交數據給他。

啟動服務

 

zabbix相關配置
創建日志目錄

mkdir /usr/local/zabbix/logs

cd /usr/local/zabbix/etc/


編輯zabbix_server配置文件

 

LogFile=/usr/local/zabbix/logs/zabbix_agentd.log


編輯zabbix_agentd配置文件

LogFile=/usr/local/zabbix/logs/zabbix_server.log創建自定義腳本目錄,設置權限,目錄下的腳步,可以被zabbix調用mkdir /usr/local/zabbix/alertscripts
chown zabbix.zabbix -R /usr/local/zabbix

vim /etc/ld.so.conf 

在后面加一行:/usr/local/mysql/lib/

重新加載:

ldconfig

 

添加啟動腳本

 

vi /etc/init.d/zabbix_server

#!/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_server.pid
 
# Modified for Zabbix 2.0.0
# May 2012, Zabbix SIA
 
# Source function library.
 
. /etc/init.d/functions
 
RETVAL=0
prog="Zabbix Server"
ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_server"
 
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_server
        echo
}
 
stop() {
        echo -n $"Stopping $prog: "
        killproc $ZABBIX_BIN
        RETVAL=$?
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/zabbix_server
        echo
}
 
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  reload|restart)
        stop
        sleep 10
        start
        RETVAL=$?
        ;;
  condrestart)
        if [ -f /var/lock/subsys/zabbix_server ]; then
            stop
            start
        fi
        ;;
  status)
        status $ZABBIX_BIN
        RETVAL=$?
        ;;
  *)
        echo $"Usage: $0 {condrestart|start|stop|restart|reload|status}"
        exit 1
esac
 
exit $RETVAL

 

vi /etc/init.d/zabbix_agentd

#!/bin/bash
#
#       /etc/rc.d/init.d/zabbix_agentd
#
# Starts the zabbix_agentd daemon
#
# chkconfig: - 95 5
# description: Zabbix Monitoring Agent
# processname: zabbix_agentd
# pidfile: /tmp/zabbix_agentd.pid
 
# Modified for Zabbix 2.0.0
# May 2012, Zabbix SIA
 
# Source function library.
 
. /etc/init.d/functions
 
RETVAL=0
prog="Zabbix Agent"
ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_agentd"
 
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_agentd
        echo
}
 
stop() {
        echo -n $"Stopping $prog: "
        killproc $ZABBIX_BIN
        RETVAL=$?
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/zabbix_agentd
        echo
}
 
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  reload|restart)
        stop
        sleep 10
        start
        RETVAL=$?
        ;;
  condrestart)
        if [ -f /var/lock/subsys/zabbix_agentd ]; then
            stop
            start
        fi
        ;;
  status)
        status $ZABBIX_BIN
        RETVAL=$?
        ;;
  *)
        echo $"Usage: $0 {condrestart|start|stop|restart|reload|status}"
        exit 1
esac
 
exit $RETVAL

 

添加執行權限

chmod +x /etc/init.d/zabbix_server 

chmod +x /etc/init.d/zabbix_agentd 

 

/etc/init.d/zabbix_server start
/etc/init.d/zabbix_agentd start
netstat -ntpl|grep zabbix
tcp        0      0 0.0.0.0:10050               0.0.0.0:*                   LISTEN      21188/zabbix_agentd
tcp        0      0 0.0.0.0:10051               0.0.0.0:*                   LISTEN      21140/zabbix_server

 

[root@xuegod64 ~]# useradd -u 8005 -M -s /sbin/nologin zabbix

//如果zabbix用戶不存在,將以root運行,新建之后,如果zabbix存在,那么久直接可以用zabbix運行

[root@xuegod64 ~]# /usr/local/zabbix/sbin/zabbix_server  //直接運行

報錯 Starting zabbix_server:  /usr/local/zabbix//sbin/zabbix_server: error while loading shared libraries: libmysqlclient.so.20: ca...or directory

解決 ln -s /usr/local/mysql/lib/libmysqlclient.so.20 /usr/lib64/

 

[root@xuegod64 ~]# echo /usr/local/zabbix/sbin/zabbix_server >> /etc/rc.local   //開機啟動

啟動腳本

cp -a /usr/local/zabbix/sbin/zabbix_agentd /etc/init.d/

cp -a /usr/local/zabbix/sbin/zabbix_server /etc/init.d/

 

[root@web1 init.d]# /etc/init.d/zabbix_server start
Reloading systemd:                                         [  確定  ]
Starting zabbix_server (via systemctl):                    [  確定  ]
[root@web1 init.d]# /etc/init.d/zabbix_agentd start
Starting zabbix_agentd (via systemctl):                    [  確定  ]

 

出現錯誤的解決

zabbix_server: error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory

yum install mysql-devel mysql-libs

 

[root@web1 init.d]# ps -ef|grep zabbix

zabbix    39538      1  0 13:51 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_server
zabbix    39570      1  0 13:51 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_agentd
zabbix    39572  39570  0 13:51 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_agentd: collector [idle 1 sec]
zabbix    39573  39570  0 13:51 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_agentd: listener #1 [waiting for connection]
zabbix    39574  39570  0 13:51 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_agentd: listener #2 [waiting for connection]
zabbix    39575  39570  0 13:51 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_agentd: listener #3 [waiting for connection]
zabbix    39576  39570  0 13:51 ?        00:00:00 /usr/local/zabbix/sbin/zabbix_agentd: active checks #1 [idle 1 sec]
root      39587  34132  0 13:51 pts/2    00:00:00 grep --color=auto zabbix


[root@xuegod64 ~]# netstat -antup | grep zabbix 

tcp        0      0 0.0.0.0:10051               0.0.0.0:*                   LISTEN      94837/zabbix_server

bix_server

 

WEB訪問:

http://IP/zabbix

進入初始配置向導:

下一步

設置數據庫連接信息,下一步

 

這里就有問題了,報了一個小錯。解決辦法:

Database error
Error connecting to database: No such file or directory

2中解決辦法:

1、ln -s /var/lib/mysql/mysql.sock /tmp/

2、vim /usr/local/php/etc/php.ini

mysqli.default_socket = /var/lib/mysql/mysql.sock

/etc/init.d/php-fpm restart

/etc/init.d/php-fpm restart

 

Mysql

Localhost

0是使用默認端口

Zabbix

Zabbix

123456

設置zabbix服務信息,下一步

主機ip:localhost

端口號:可以按照自己的需要設置

服務名稱:yunjiankong

 

有可能會提示Unable to create the configuration file.

Please install it manually, or fix permissions on the conf directory.

Press the "Download configuration file" button, download the configuration file and save it as

"/usr/local/nginx/html/zabbix/conf"(這里提示保存位置)

直接下載zabbix.conf.php放到cd /usr/local/nginx/html/zabbix/conf下就好了,

或者修改cd /usr/local/nginx/html/zabbix/conf的權限

chown -R zabbix:zabbix zabbix.conf.php

chmod 644 zabbix.conf.php

Zabbix前端是准備好了!默認的用戶名是Admin,密碼zabbix

Ok,到此已安裝成功。

 

解決zabbix頁面中文亂碼

2.1在windows的C:\Windows\Fonts找到字體文件simkai.ttf
2.2在zabbix服務器上找到zabbix默認字體文件DejaVuSans.ttf的目錄,並將simkai.ttf文件上傳至該目錄

[root@localhost fonts]# find / -name 'DejaVuSans.ttf'
/usr/local/nginx/html/zabbix/fonts/DejaVuSans.ttf

[root@localhost ~]# cd /usr/local/nginx/html/zabbix/fonts

上傳到目錄里面

[root@localhost fonts]# ll

-rw-r--r-- 1 zabbix zabbix   756072 6月   4 19:40 DejaVuSans.ttf

-rw-r--r-- 1 zabbix zabbix 11787328 12月  4 2017 simkai.ttf

2.3將配置文件vi /usr/local/nginx/html/zabbix/include/defines.inc.php中的以下兩行更換為新的字體simkai

define('ZBX_GRAPH_FONT_NAME',           'simkai'); // font file name

define('ZBX_FONT_NAME', 'simkai');

 打開頁面就可以看到顯示正常了


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM