美文网首页linux
zabbix-3.2源码编译安装和lnmp安装

zabbix-3.2源码编译安装和lnmp安装

作者: uvscjh | 来源:发表于2016-10-20 17:19 被阅读1298次
    名称/IP 软件 版本包 说明
    master nginx nginx-1.10.2.tar.gz http://nginx.org/download/nginx-1.10.2.tar.gz
    172.16.0.1 mysql mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz
    php php-5.6.27.tar.bz2 http://cn2.php.net/get/php-5.6.27.tar.bz2/from/this/mirror
    libevent libevent-2.0.22-stable.tar.gz https://github.com/libevent/libevent/releases/download/release-2.0.22-stable/libevent-2.0.22-stable.tar.gz
    memcached memcached-1.4.32.tar.gz http://memcached.org/files/memcached-1.4.32.tar.gz
    zabbix-server zabbix-3.2.1.tar.gz https://sourceforge.net/projects/zabbix/files/
    zabbix-agent zabbix-3.2.1.tar.gz
    172.16.0.2 zabbix-agent zabbix-3.2.1.tar.gz

    一、准备工作

    提前准备好编译环境,防火墙和selinux都关闭

    1. 准备好编译环境

    // 偷个懒,把开发包都安装了,如果后面有需要别的包再手动安装
    # yum groupinstall "Development Tools"
    

    2. 关闭防火墙

    # service iptables stop
    # chkconfig iptables off
    

    3. 关闭selinux

    // 设置开机selinux即是关闭的状态
    # sed -i "/^SELINUX=/c SELINUX=permissive" /etc/sysconfig/selinux
    // 设置当前系统selinux的状态为关闭
    # setenforce 0
    

    二、安装nginx

    1. 解决依赖关系

    编译安装nginx需要事先需要安装开发包组"Development Tools"和 "Development Libraries"。同时,还需要专门安装pcre-devel包:
    # yum -y install pcre-devel

    2. 安装

    2.1.首先添加用户nginx,实现以之运行nginx服务进程:
    # groupadd -r -g 80 nginx
    # useradd -r -g 80 -u 80 nginx
    
    2.2. 接着开始编译和安装:
    ./configure \
      --prefix=/opt/nginx \
      --sbin-path=/usr/sbin/nginx \
      --conf-path=/etc/nginx/nginx.conf \
      --error-log-path=/var/log/nginx/error.log \
      --http-log-path=/var/log/nginx/access.log \
      --pid-path=/var/run/nginx/nginx.pid  \
      --lock-path=/var/lock/nginx.lock \
      --user=nginx \
      --group=nginx \
      --with-http_ssl_module \
      --with-http_flv_module \
      --with-http_realip_module \
      --with-http_sub_module \
      --with-http_stub_status_module \
      --with-http_gzip_static_module \
      --with-http_perl_module \
      --http-client-body-temp-path=/var/tmp/nginx/client/ \
      --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-pcre
    
    # make && make install
    

    说明:如果想使用nginx的perl模块,可以通过为configure脚本添加--with-http_perl_module选项来实现,但目前此模块仍处于实验性使用阶段,可能会在运行中出现意外,因此,其实现方式这里不再介绍。如果想使用基于nginx的cgi功能,也可以基于FCGI来实现,具体实现方法请参照网上的文档。

    3. 为nginx提供SysV init脚本:

    3.1. 新建文件/etc/rc.d/init.d/nginx,内容如下:
    # vim /etc/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:      /etc/nginx/nginx.conf
    # config:      /etc/sysconfig/nginx
    # pidfile:     /var/run/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="/usr/sbin/nginx"
    prog=$(basename $nginx)
     
    NGINX_CONF_FILE="/etc/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
    
    3.2. 而后为此脚本赋予执行权限:
    # chmod +x /etc/rc.d/init.d/nginx
    
    3.3. 添加至服务管理列表,并让其开机自动启动:
    # chkconfig --add nginx
    # chkconfig nginx on
    
    3.4. 而后就可以启动服务并测试了:
    # service nginx start
    

    三、安装mysql

    1. 准备数据存放的文件系统

    新建一个逻辑卷,并将其挂载至特定目录即可。这里不再给出过程。
    这里假设其逻辑卷的挂载目录为/data,而后需要创建/data/mysql目录做为mysql数据的存放目录。

    2. 新建用户以安全方式运行进程:

    // id号可选
    # groupadd -r -g 306 mysql
    # useradd -g mysql -u 306 -r -s /sbin/nologin -M -d /mydata/data mysql
    

    3. 解压MySQL

    首先下载平台对应的mysql版本,这里是64位平台,因此选择的为mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz
    # tar xf mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz -C /opt
    # cd /opt
    // 为主目录创建链接
    # ln -sv mysql-5.6.34-linux-glibc2.5-x86_64 mysql
    # cd mysql
    // 修改主目录所属主及所属组为mysql
    # chown -R mysql:mysql .

    4. 配置MySQL

    4.1. 新建数据文件夹, 修改权限
    # mkdir -p /data/mysql
    
    4.2. 为mysql提供主配置文件并修改
    // 复制my-default.cnf, 好像这里面也没有什么内容,还是自己写吧
    # cp support-files/my-default.cnf /data/mysql/my.cnf
    

    创建my.cnf文件

    cat > /data/mysql/my.cnf <<EOF
    [client]
    # 用mysqlbinlog查看binlog文件失败时,把这项注释掉
    default_character_set = utf8
    port = 3306
    socket = /data/mysql/mysql.sock
    [mysqld]
    # innodb_buffer_pool_size = 128M
    # join_buffer_size = 128M
    # sort_buffer_size = 2M
    # read_rnd_buffer_size = 2M                                                                                                                                             
    init_connect = 'SET collation_connection = utf8_general_ci'
    init_connect = 'SET NAMES utf8'
    character_set_server = utf8
    collation_server = utf8_general_ci
    basedir = /opt/mysql
    datadir = /data/mysql/data
    port = 3306
    server_id = 1 
    socket = /data/mysql/mysql.sock
    binlog_format = MIXED
    log_bin = mysql-bin
    innodb_file_per_table = 1
    # 值为你的CPU个数乘以2 
    thread_concurrency = 2 
    slow_query_log = 1
    EOF  
    
    4.3. 修改数据目录所属主及所属组为mysql
    # chown -R mysql.mysql /data/mysql/
    
    4.4. 链接文件
    // 有必要的话先备份系统上已经存在的/etc/my.cnf文件
    # ln -sv /data/mysql/my.cnf  /etc/my.cnf
    

    5. 初始化数据库

    # ./mysql_install_db --user=mysql --defaults-file=/etc/my.cnf --basedir=/opt/mysql --datadir=/data/mysql/data (mysql-5.7: ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data) 
    

    6. 为mysql提供sysv服务脚本并修改

    # cp support-files/mysql.server /etc/init.d/mysqld
    # sed -i "/^basedir=/c basedir=/opt/mysql" /etc/init.d/mysqld
    # sed -i "/^datadir=/c datadir=/data/mysql/data" /etc/init.d/mysqld
    # sed -i "/^mysqld_pid_file_path=/c mysqld_pid_file_path=/data/mysql/mysqld.pid" /etc/init.d/mysqld
    # chkconfig --add mysqld
    # chkconfig mysqld on
    

    7. 修改主目录所属主权限为root

    # chown -R root .
    

    8. 为了使用mysql的安装符合系统使用规范,并将其开发组件导出给系统使用,这里还需要进行如下步骤:

    8.1. 输出mysql的man手册至man命令的查找路径:
    //编辑/etc/man.config,添加如下行即可
    # vim /etc/man.config
    

    MANPATH /usr/local/mysql/man

    8.2. 输出mysql的库文件及创建mysql的头文件链接
    # vim /etc/ld.so.conf.d/mysql.conf
    

    /usr/local/mysql/lib

    // 让系统重新读取库文件,系统启动时会将所有库文件找出来,然后缓存至/etc/ld.so.cache
    # ldconfig -v
    // 输出头文件
    # ln -s /opt/mysql/include/mysql /usr/include/mysql
    

    9. 启动mysqld

    // 建议使用安全启动
    # service mysql start
    // 此行不执行,只是建议,因为上面已经启动mysql了
    # /opt/mysql/bin/mysqld_safe --datadir=/data/mysql/data & 
    

    10. 设置mysql环境变量

    # vim /etc/profile.d/mysql.sh
    

    export MYSQL_HOME=/opt/mysql export PATH=$PATH:$MYSQL_HOME/bin export CLASSPATH=$MYSQL_HOME/lib:$CLASSPAHT:./

    // 读取环境变量
    # source /etc/profile.d/mysql.sh
    

    11. 设置字符集

    # mysql -uroot -p 
        (mysql-5.7: mysql -uroot -p'初始化时会自动生成一个密码',登录后修改之: 
        step 1: SET PASSWORD = PASSWORD(‘your new password‘);
        step 2: ALTER USER ‘root‘@‘localhost‘ PASSWORD EXPIRE NEVER;
        step 3: flush privileges;)
    

    > SHOW VARIABLES LIKE 'character%';
    +--------------------------+----------------------------------+ | Variable_name | Value | +--------------------------+----------------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | /usr/local/mysql/share/charsets/ | +--------------------------+----------------------------------+
    如果不是utf8, 则修改主配置文件my.cnf

    # vim /etc/my.cnf
    
    [mysqld]
    init_connect = 'SET collation_connection = utf8_general_ci'
    init_connect = 'SET NAMES utf8'
    character_set_server = utf8
    collation_server = utf8_general_ci
    innodb_file_per_table = 1
    [mysqld_safe]
    init_connect = 'SET collation_connection = utf8_general_ci'
    init_connect = 'SET NAMES utf8'
    character_set_server = utf8
    collation_server = utf8_general_ci
    log_bin = mysql-bin
    
    // 重启mysqld
    # /etc/init.d/mysqld restart
    

    12. 配置mysql用户

    MySQL启动成功后,root默认没有密码,我们需要设置root密码。

    12.1. 修改mysql管理员密码

    给所有的root用户设定密码:
    // 第一种方式(推荐此方法)
    # mysql -uroot -p
    如下操作
    > SELECT USER,PASSWORD,HOST FROM mysql.user;
    +------+----------+------------------+ | USER | PASSWORD | HOST | +-------+----------+------------------+ | root | | localhost | | root | | node1.magedu.com | | root | | 127.0.0.1 | | root | | ::1 | | | | localhost | | | | node1.magedu.com | +-------+----------+------------------+
    > UPDATE mysql.user SET PASSWORD=PASSWORD('admin1') WHERE USER='root' LIMIT 100; FLUSH PRIVILEGES;
    Query OK, 4 rows affected (0.00 sec)
    Rows matched: 4 Changed: 4 Warnings: 0

    12.2. 删除所有匿名用户(不要删除root@localhost)
    > DROP USER ''@'localhost'; DELETE FROM mysql.user WHERE USER='' limit 10; COMMIT; FLUSH PRIVILEGES;
    

    Query OK, 0 rows affected (0.00 sec)
    Query OK, 1 row affected (0.00 sec)
    Query OK, 0 rows affected (0.00 sec)
    Query OK, 0 rows affected (0.00 sec);

    12.3. 设置mysql用户安全
    > DELETE FROM mysql.user WHERE USER NOT IN('root'); FLUSH PRIVILEGES;
    

    Query OK, 0 rows affected (0.00 sec)
    Query OK, 0 rows affected (0.00 sec)

    12.4. 设置root用户可以远程访问

    --方法1:授权法(推荐)
    > GRANT ALL PRIVILEGES ON . TO 'root'@'%' IDENTIFIED BY 'admin1' WITH GRANT OPTION; FLUSH PRIVILEGES;
    Query OK, 0 rows affected (0.00 sec)
    Query OK, 0 rows affected (0.00 sec)
    > SELECT USER,PASSWORD,HOST FROM mysql.user;
    +------+-------------------------------------------+------------------+ | USER | PASSWORD | HOST | +------+-------------------------------------------+------------------+ | root | *6D45FD76D5E9C6A404E39C25106A7F032659ACB8 | localhost | | root | *6D45FD76D5E9C6A404E39C25106A7F032659ACB8 | node1.magedu.com | | root | *6D45FD76D5E9C6A404E39C25106A7F032659ACB8 | 127.0.0.1 | | root | *6D45FD76D5E9C6A404E39C25106A7F032659ACB8 | ::1 | | root | *6D45FD76D5E9C6A404E39C25106A7F032659ACB8 | % | +------+-------------------------------------------+------------------+

    12.5 登录mysql
    #mysql -hlocalhost -uroot -padmin1
    
    12.6 设置linux脚本
    # vim + ~/.bash_profile
    
    #ocpyang set(绑定mysql到内网IP只能写内网IP)
    alias date='date "+%Y-%m-%d %H:%M:%S" '
    alias  mysql="mysql -hlocalhost -uroot -padmin1 --auto-rehash --prompt=\"\u@\h [\d]> \" "
    alias  errorlog="cat  /data/mysql/mysql_logs/error_log/error.log"
    alias  mycnf="cd /data/mysql"
    export PATH=/data/mysql/scripts:$PATH
    
    # source ~/.bash_profile
    
    12.7. 常见启动错误或警告
    # cat /data/mysql/data/node1.magedu.com.err 
    

    150619 14:16:30 [Warning] 'user' entry 'root@master.uvsc.com' ignored in --skip-name-resolve mode. 150619 14:16:30 [Warning] 'user' entry '@master.uvsc' ignored in --skip-name-resolve mode. 150619 14:16:30 [Warning] 'proxies_priv' entry '@% root@master.uvsc.com' ignored in --skip-name-resolve mode.
    解决办法:
    > DELETE FROM mysql.proxies_priv WHERE HOST='mariadb.jinri.com'; COMMIT; FLUSH PRIVILEGES;

    四、编译安装php

    1. 解决依赖关系

    1.1. 如果想让编译的php支持mcrypt、mhash扩展和libevent,此处还需要下载如下几个rpm包并安装之:

    可以添加epel源安装 或 在http://rpmfind.net/搜索下载

    • libmcrypt-2.5.8-9.el6.x86_64.rpm
    • libmcrypt-devel-2.5.8-9.el6.x86_64.rpm
    • mhash-0.9.9.9-3.el6.x86_64.rpm
    • mhash-devel-0.9.9.9-3.el6.x86_64.rpm
    • mcrypt-2.6.8-10.el6.x86_64.rpm

    最好使用升级的方式安装上面的rpm包,命令格式如下:
    # rpm -Uvh *.rpm

    1.2. 另外,也可以根据需要安装libevent,系统一般会自带libevent,但版本有些低。因此可以升级安装之,它包含如下两个rpm包,或者编译安装它。
    • libevent-2.0.17-2.i386.rpm
    • libevent-devel-2.0.17-2.i386.rpm

    说明:libevent是一个异步事件通知库文件,其API提供了在某文件描述上发生某事件时或其超时时执行回调函数的机制,它主要用来替换事件驱动的网络服务器上的event loop机制。目前来说, libevent支持/dev/poll、kqueue、select、poll、epoll及Solaris的event ports。

    项目主页:http://libevent.org/,读者可自行选择需要的版本下载。本文采用的是目前最新版本的源码包libevent-2.0.12-stable.tar.gz。安装过程:
    # tar xf libevent-2.0.22-stable.tar.gz
    # cd libevent-2.0.22
    # ./configure --prefix=/opt/libevent
    # make && make install

    # echo "/opt/libevent/lib" > /etc/ld.so.conf.d/libevent.conf
    # ldconfig
    

    2. 编译安装php

    说明:如果前面第1步解决依赖关系时安装mcrypt相关的两个rpm包,此./configure命令还可以带上--with-mcrypt选项以让php支持mycrpt扩展。--with-snmp选项则用于实现php的SNMP扩展,但此功能要求提前安装net-snmp相关软件包。

    • net-snmp-5.5-57.el6.x86_64.rpm
    • net-snmp-devel-5.5-57.el6.x86_64.rpm
    • net-snmp-libs-5.5-57.el6.x86_64.rpm
    2.1. 安装net-snmp相关软件包
    # rpm -Uvh net-snmp-5.5-57.el6.x86_64.rpm net-snmp-devel-5.5-57.el6.x86_64.rpm net-snmp-libs-5.5-57.el6.x86_64.rpm
    
    2.2. 编译安装php
    # tar xf php-5.6.26.tar.bz2
    # cd php-5.6.26
    # ./configure \
    --prefix=/opt/php \
    --with-mysql=/opt/mysql \
    --with-openssl \
    --enable-fpm \
    --enable-sockets \
    --enable-sysvshm  \
    --with-mysqli=/opt/mysql/bin/mysql_config \
    --enable-mbstring \
    --enable-bcmath \
    --with-freetype-dir \
    --with-jpeg-dir \
    --with-png-dir \
    --with-zlib-dir \
    --with-libxml-dir=/usr \
    --enable-xml  \
    --with-mhash \
    --with-mcrypt  \
    --with-config-file-path=/etc \
    --with-config-file-scan-dir=/etc/php.d \
    --with-bz2 \
    --with-curl \
    --with-gd \
    --with-gettext \
    --with-snmp
    

    make并安装
    # make
    # make test
    # make intall

    2.3. 为php提供配置文件:
    # cp php.ini-production /etc/php.ini
    
    2.4. 为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
    
    2.5. 为php-fpm提供配置文件:
    # cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf 
    
    2.6. 编辑php-fpm的配置文件:

    配置fpm的相关选项为你所需要的值,并启用pid文件(如下最后一行):
    # vim /opt/php/etc/php-fpm.conf
    pm.max_children = 150 pm.start_servers = 8 pm.min_spare_servers = 5 pm.max_spare_servers = 10 pid = /usr/local/php/var/run/php-fpm.pid

    2.7. 接下来就可以启动php-fpm了:
    # service php-fpm start
    

    使用如下命令来验正(如果此命令输出有中几个php-fpm进程就说明启动成功了):
    # ps aux | grep php-fpm

    五、整合nginx和php5

    1. 编辑/etc/nginx/nginx.conf,启用如下选项:
    # vim /etc/nginx/nginx.conf
    

    location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi_params; }

    2. 编辑/etc/nginx/fastcgi_params,将其内容更改为如下内容:
    # vim /etc/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格式的主页,类似如下:
    # vim /etc/nginx/nginx.conf
    location / { root html; index index.php index.html index.htm; }
    而后重新载入nginx的配置文件:
    # service nginx reload

    3、在/usr/html新建index.php的测试页面,测试php是否能正常工作:
    # cat > /usr/html/index.php << EOF
    <?php
    phpinfo();
    ?>
    EOF

    接着就可以通过浏览器访问此测试页面了。

    六、安装xcache,为php加速:

    1. 编译安装

    # tar xf xcache-3.2.0.tar.gz
    # cd xcache-3.2.0
    // 动态安装php扩展模块
    // 使用phpize脚本安装php扩展模块的好处:在安装php时没有安装的扩展,可以在以后随时安装上,且不需要重新安装PHP。
    # /opt/php/bin/phpize
    # ./configure --enable-xcache --with-php-config=/opt/php/bin/php-config
    # make && make install
    

    安装结束时,会出现类似如下行:

    Installing shared extensions: /opt/php/lib/php/extensions/no-debug-zts-20100525/

    2. 编辑php.ini,整合php和xcache:

    首先将xcache提供的样例配置导入php.ini
    # mkdir /etc/php.d
    # cp xcache.ini /etc/php.d

    说明:xcache.ini文件在xcache的源码目录中。

    接下来编辑/etc/php.d/xcache.ini,找到zend_extension开头的行,修改为如下行,不改也行php能找到这个目录下的xcache.so:
    # vim /etc/php.d/xcache.ini
    zend_extension = /opt/php/lib/php/extensions/no-debug-zts-20100525/xcache.so

    注意:如果php.ini文件中有多条zend_extension指令行,要确保此新增的行排在第一位。

    3. 重新启动php-fpm

    # service php-fpm restart
    

    七、创建zabbix数据库和授权用户

    1. 创建zabbix数据库和授权用户

    # mysql -uroot -p
    

    在数据库中操作
    > CREATE DATABASE zabbix;
    > GRANT ALL ON zabbix.* TO 'zabbix'@'192.168.19.%' IDENTIFIED BY '123456';
    > GRANT ALL ON zabbix.* TO 'zabbix'@'localhost' IDENTIFIED BY '123456';
    > GRANT ALL ON zabbix.* TO 'zabbix'@'master.node1.com' IDENTIFIED BY '123456';
    > FLUSH PRIVILEGES;

    2. 导入数据库文件:

    # tar xf zabbix-3.2.1.tar.gz
    # cd zabbix-3.2.1/database/mysql/
    //导入顺序不能错
    # /opt/mysql/bin/mysql -uzabbix -p123456 zabbix < schema.sql
    # /opt/mysql/bin/mysql -uzabbix -p123456 zabbix < images.sql
    # /opt/mysql/bin/mysql -uzabbix -p123456 zabbix < data.sql
    

    八、安装Zabbix-Server服务器

    1. 安装JAVA

    # rpm -ivh jdk-8u20-linux64-x.rpm
    // 或者解压安装
    # tar xvf jdk-8u20-linux64-tar.gz -C /opt
    # ln -sv /opt/jdk-1.8.20 /opt/java
    

    2. 配置JAVA环境变量

    # vi /etc/profile.d/java.sh
    

    export JAVA_HOME=/usr/local/java export PATH=$PATH:$JAVA_HOME/bin export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
    # source /etc/profile.d/java.sh
    # java -version

    3. 编译安装zabbix并提供sysv脚本和zabbix_web文件:

    3.1. 编译安装
    // 如果不能上网则将以下rpm下载到本地用 rpm -Uvh 安装
    # yum -y install mysql-devel libxml2-devel net-snmp-devel libcurl-devel OpenIPMI OpenIPMI-devel rpm-build
    # tar xf zabbix-3.2.1.tar.gz
    # cd zabbix-3.2.1
    # groupadd -g 201 -r zabbix
    # useradd -g 201 -u 201 -r zabbix
    # ./configure --prefix=/opt/zabbix --sysconfdir=/etc/zabbix --enable-server --enable-agent --with-net-snmp --with-libcurl --enable-proxy --with-mysql=/opt/mysql/bin/mysql_config --with-libxml2 --with-ssh2 --with-openssl --with-ldap --enable-java --with-openipmi
    # make
    # make install
    
    3.2. 提供sysv脚本
    # cp misc/init.d/tru64/zabbix_server /etc/init.d/
    // 复制zabbix_agentd是因为要监控zabbix_server服务所在的主机,即本机
    # cp misc/init.d/tru64/zabbix_agentd /etc/init.d/
    # chmod +x /etc/init.d/zabbix*
    
    3.3. 复制zabbix_web文件
    // nginx的默认根目录是`/opt/nginx/html`
    # cp -r frontends/php/ /opt/nginx/html/zabbix
    

    4. 编辑配置文件并启动:

    4.1. 修改sysv脚本文件
    // 设置zabbix_server运行级别
    # sed -i "/^# Zabbix/a# chkconfig: 2345 65 35\n# description: zabbix server" /etc/init.d/zabbix_server
    // 修改zabbix_server执行程序路径
    # sed -i '/^DAEMON=/c DAEMON=/opt/zabbix/sbin/zabbix_server' /etc/init.d/zabbix_server
    // 设置zabbix_agentd运行级别
    # sed -i "/^# Zabbix/i# chkconfig: 2345 66 34\n# description: zabbix agent" /etc/init.d/zabbix_agentd
    // 修改zabbix_agentd执行程序路径
    # sed -i '/^DAEMON=/c DAEMON=/opt/zabbix/sbin/zabbix_agentd' /etc/init.d/zabbix_agentd
    # chkconfig --add zabbix_server
    # chkconfig --add zabbix_agentd
    
    4.2. 创建日志目录
    # mkdir /var/log/zabbix
    # chown -R zabbix:zabbix /var/log/zabbix
    
    4.3. 修改zabbix_server的配置文件
    # vim /etc/zabbix/zabbix_server.conf
    
    LogFile=/var/log/zabbix/zabbix_server.log
    DBHost=127.0.0.1
    DBName=zabbix
    DBUser=zabbix
    DBPassword=admin1
    #StartPollers=30
    #StartTrappers=20
    #StartPingers=10
    #StartDiscoverers=5
    #JavaGateway=0.0.0.0
    #JavaGatewayPort=10052
    #StartJavaPollers=5
    ListenIP=0.0.0.0
    #MaxHousekeeperDelete=5000
    #CacheSize=12M
    #StartDBSyncers=8
    #HistoryCacheSize=22M
    #TrendCacheSize=8M
    #Timeout=30
    Include=/etc/zabbix_server.conf.d/
    AlertScriptsPath=/etc/zabbix/alertscripts
    #LogSlowQueries=3000
    
    4.4. 启动服务
    //opt/zabbix-server/sbin/zabbix_server -c /usr/local/zabbix-server/etc/zabbix_server.conf也可以
    # service zabbix_server start
    

    查看端口,已经开始监听了:

    5. 配置php并启动nginx:

    // 这里的参数可能不全,可根据后面zabbix页面的提示再回来修改
    # vim /etc/php.ini
    

    date.timezone = Asia/Shanghai post_max_size = 16M max_execution_time = 300 max_input_time = 300
    # service php-fpm restart
    # service nginx restart

    6. 用浏览器访问http://172.16.0.1/zabbix,并按照提示安装:

    图片上的IP改成172.16.0.1

    Paste_Image.png Paste_Image.png Paste_Image.png Paste_Image.png

    这里出现权限报错,将配置文件下载下来保存到
    /opt/nginx/html/zabbix/conf/zabbix.conf.php文件中。如果手动写入配置文件之后如果还报错,可以忽略,将浏览器关闭并重新打开连接即可。登录账号admin,登录密码zabbix:

    //手动写入配置172.16.0.1可改成127.0.0.1或localhost
    # vim /opt/nginx/html/zabbix/conf/zabbix.conf.php    
    

    <?php // Zabbix GUI configuration file. global $DB; $DB['TYPE'] = 'MYSQL'; $DB['SERVER'] = '172.16.0.1'; $DB['PORT'] = '0'; $DB['DATABASE'] = 'zabbix'; $DB['USER'] = 'zabbix'; $DB['PASSWORD'] = '123456'; // Schema name. Used for IBM DB2 and PostgreSQL. $DB['SCHEMA'] = ''; $ZBX_SERVER = '172.16.0.1'; $ZBX_SERVER_PORT = '10051'; $ZBX_SERVER_NAME = ''; $IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG; ?>
    登录成功后显示如下

    Paste_Image.png
    7. 开启172.16.0.1上的zabbix_agentd以监控zabbix_server本身(即172.16.0.1)
    # service zabbix_agend start
    

    打开http://172.16.0.1/zabbix

    Paste_Image.png
    如不成功则查看日志报什么错

    十、安装Zabbix-Agent端(172.16.0.2)

    1. 在172.16.0.2主机上编译安装:

    # tar xf zabbix-3.2.1.tar.gz 
    # cd zabbix-3.2.1
    # groupadd -g 201 -r zabbix
    # useradd -g 201 -u 201 -r zabbix zabbix
    # ./configure --prefix=/opt/zabbix-agent --sysconfdir=/etc/zabbix --enable-agent
    # make install
    
    // 复制zabbix_agentd到/etc/init.d
    # cp misc/init.d/tru64/zabbix_agentd /etc/init.d/
    // 设置zabbix_agentd运行级别
    # sed -i "/^# Zabbix/i# chkconfig: 2345 66 34\n# description: zabbix agent" /etc/init.d/zabbix_agentd
    // 修改zabbix_agentd执行程序路径
    # sed -i '/^DAEMON=/c DAEMON=/opt/zabbix/sbin/zabbix_agentd' /etc/init.d/zabbix_agentd
    # chmod +x /etc/init.d/zabbix_agentd
    

    2. 编辑配置文件:

    # mkdir /var/log/zabbix
    # chown -R zabbix:zabbix /var/log/zabbix/
    # vim /etc/zabbix/zabbix_agentd.conf
    
    LogFile=/var/log/zabbix/zabbix_agentd.log
    Server=172.16.0.1
    ServerActive=172.16.0.1
    # 这里要和zabbix_server页面上添加的主机名一样,这里为本地的hostname
    Hostname=node1.uvsc.com
    

    3. 启动

    # service zabbix_agend start
    

    十一、添加主机(在172.16.0.1上操作)

    这里就大体截图一下来演示了,过程可能并不详细:

    Paste_Image.png Paste_Image.png Paste_Image.png Paste_Image.png

    至此,演示过程全部结束,感谢大家的收看!

    相关文章

      网友评论

        本文标题:zabbix-3.2源码编译安装和lnmp安装

        本文链接:https://www.haomeiwen.com/subject/arsfuttx.html