更新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');

 打开页面就可以看到显示正常了