01-centos7.2上源码编译部署LNMP+zabbix3.2(2017-03-07)

    • 环境准备
    • 配置基础服务
    • 安装mysql数据库
    • 安装nginx
    • 安装php
    • 配置php
    • 安装zbabix
    • Zabbix Server基本配置
    • Nginx和Zabbix Server Front Web配置
    • web配置页面

环境准备

centos7.2
nginx-1.9.15
mysql5.7
zabbix-3.2.3
php-5.5.35

配置基础服务

[root@zbserver ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@zbserver ~]#

[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eno16777728
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eno16777728
UUID=30f74f98-8f20-4e25-aff0-4a23cf7e911d
DEVICE=eno16777728
ONBOOT=yes
IPADDR=192.168.181.179
GATEWAY=192.168.181.2
NETMASK=255.255.255.0
DNS1=192.168.181.2

[root@localhost ~]#
[root@localhost ~]# yum install vim
[root@localhost ~]# vim /etc/hostname
添加zbserver.create80.com
[root@localhost ~]# hostname
zbserver.create80.com

修改/etc/hosts文件

[root@localhost ~]# vim /etc/hosts

添加:
192.168.181.179 zbserver.create80.com zabbix1

查看:

[root@localhost ~]# hostnamectl status
   Static hostname: zbserver.create80.com
         Icon name: computer-vm
           Chassis: vm
        Machine ID: b05666a8061b46f39567ae72d1cd8157
           Boot ID: 1e97e7bf0412441fa5b3015accee0263
    Virtualization: vmware
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-327.el7.x86_64
      Architecture: x86-64
[root@localhost ~]#

配置时钟同步:

[root@localhost ~]# timedatectl
      Local time: 四 2017-03-09 02:55:33 CST
  Universal time: 三 2017-03-08 18:55:33 UTC
        RTC time: 三 2017-03-08 18:55:33
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: n/a
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a
[root@localhost ~]#

安装ntp

[root@zbserver ~]# yum install ntp

[root@zbserver ~]# systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.
[root@zbserver ~]# systemctl start ntpd

设置开机自启动

[root@zbserver ~]# systemctl enable ntpd.service

参考笔记:
http://www.centoscn.com/CentOS/config/2015/1105/6385.html

关闭防火墙

[root@zbserver ~]# systemctl status firewalld
[root@zbserver ~]# systemctl stop firewalld

关闭selinux

[root@zbserver ~]# cat /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted
[root@zbserver ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
[root@zbserver ~]# grep -n ^[A-Z] /etc/selinux/config
7:SELINUX=disabled
12:SELINUXTYPE=targeted
[root@zbserver ~]#

安装mysql数据库

CentOS7默认安装了和MySQL有兼容性的MariaDB数据库,在我们安装MySQL5.7之前为了避免发生冲突首先删除MariaDB

[root@zbserver ~]# rpm -qa | grep maria
mariadb-libs-5.5.44-2.el7.centos.x86_64
[root@zbserver ~]# yum remove mariadb-libs -y

添加mysql的yum源
在CentOS7上yum安装MySQL需使用MySQL的yum源。执行以下命令首先添加MySQL的yum源。

[root@zbserver soft]# yum install wget
[root@zbserver soft]# wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm


[root@zbserver soft]# yum localinstall mysql57-community-release-el7-8.noarch.rpm

安装完后得到两个文件

[root@zbserver yum.repos.d]# ll   /etc/yum.repos.d/
总用量 36
-rw-r--r--. 1 root root 1664 12月  9 2015 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 12月  9 2015 CentOS-CR.repo
-rw-r--r--. 1 root root  649 12月  9 2015 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  290 12月  9 2015 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 12月  9 2015 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 12月  9 2015 CentOS-Sources.repo
-rw-r--r--. 1 root root 1952 12月  9 2015 CentOS-Vault.repo
-rw-r--r--  1 root root 1222 3月  23 2016 mysql-community.repo
-rw-r--r--  1 root root 1236 3月  23 2016 mysql-community-source.repo
[root@zbserver yum.repos.d]#

安装完成之后验证MySQL YUM repository

[root@zbserver yum.repos.d]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64        MySQL Connectors Community           30
mysql-tools-community/x86_64             MySQL Tools Community                43
mysql57-community/x86_64                 MySQL 5.7 Community Server          166
[root@zbserver yum.repos.d]#

这里写图片描述

开始安装

[root@zbserver yum.repos.d]# yum install mysql-community-server

01-centos7.2上源码编译部署LNMP+zabbix3.2(2017-03-07)_第1张图片

[root@zbserver yum.repos.d]# mysqld --version
mysqld  Ver 5.7.17 for Linux on x86_64 (MySQL Community Server (GPL))

配置mysql开机自启动

[root@zbserver yum.repos.d]# systemctl enable mysqld.service
[root@zbserver yum.repos.d]# systemctl start mysqld.service

安装MySQL 5.7之后,MySQL会生成一个随机密码在/var/log/mysqld.log文件中,使用如下命令查看密码:

[root@zbserver log]# grep 'temporary password' /var/log/mysqld.log
2017-03-08T05:39:40.970412Z 1 [Note] A temporary password is generated for root@localhost: +hyQTJ(K6wnf
[root@zbserver log]#

[root@zbserver log]# grep "password" /var/log/mysqld.log >> /tmp/mysql.password
[root@zbserver log]# cat /tmp/mysql.password
2017-03-08T05:39:40.970412Z 1 [Note] A temporary password is generated for root@localhost: +hyQTJ(K6wnf
[root@zbserver log]#

记录密码之后,运行 mysql_secure_installation初始化MySQL,初始化过程中会提示输入随机密码

[root@zbserver log]# mysql_secure_installation
更新密码为:xxxxxxx

登录:

[root@zbserver log]# mysql -u root -p

设置用户 root 可以在任意 IP 下被访问:

mysql>grant all privileges on *.* to root@"%" identified by 'Zabbix_Long01';

设置用户 root 可以在本地被访问:

mysql>grant all privileges on *.* to root@"localhost" identified by " Zabbix_Long01";

刷新权限使之生效:

mysql> flush privileges;

改变MySQL 的字符集:

mysql> show variables like '%character%';

查看指定的数据库中指定数据表的字符集,如查看 mysql 数据库中 servers 表的字符集:
show table status from mysql like ‘%servers%’;
查看指定数据库中指定表的全部列的字符集,如查看 mysql 数据库中 servers 表的全部的列的字符集:
show full columns from servers;

01-centos7.2上源码编译部署LNMP+zabbix3.2(2017-03-07)_第2张图片

设置 MySQL 的字符集为 UTF-8:

打开 /etc 目录下的 my.cnf 文件(此文件是 MySQL 的主配置文件):

vi /etc/my.cnf

在 [mysqld] 前添加如下代码:

[client]
default-character-set=utf8

在 [mysqld] 后添加如下代码:

character_set_server=utf8

01-centos7.2上源码编译部署LNMP+zabbix3.2(2017-03-07)_第3张图片

[root@zbserver ~]# systemctl restart mysqld
[root@zbserver ~]# mysql -u root -p

01-centos7.2上源码编译部署LNMP+zabbix3.2(2017-03-07)_第4张图片

[root@zbserver ~]# systemctl stop mysqld

mysql安装完成,做一个快照。

安装nginx

先安装依赖包

[root@zbserver ~]# yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre* make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel

01-centos7.2上源码编译部署LNMP+zabbix3.2(2017-03-07)_第5张图片

创建用户名:

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

下载nginx软件包并进入到目录中:

wget http://nginx.org/download/nginx-1.9.15.tar.gz && tar xvf nginx-1.9.15.tar.gz && cd nginx-1.9.15

编译:

[root@zbserver nginx-1.9.15]# ./configure --prefix=/usr/local/product/nginx1.9.15 --user=www --group=www --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module --with-pcre

01-centos7.2上源码编译部署LNMP+zabbix3.2(2017-03-07)_第6张图片

安装:

[root@zbserver nginx-1.9.15]# make && make install

01-centos7.2上源码编译部署LNMP+zabbix3.2(2017-03-07)_第7张图片

建立软链接并将Nginx服务加入操作系统启动组

[root@zbserver nginx-1.9.15]# ln -s /usr/local/product/nginx1.9.15 /usr/local/nginx
[root@zbserver nginx-1.9.15]# echo "/usr/local/nginx/sbin/nginx" >>/etc/rc.local
[root@zbserver nginx-1.9.15]#

安装php

下载php安装包:

[root@zbserver soft]# wget http://cn2.php.net/get/php-5.5.35.tar.gz/from/this/mirror
[root@zbserver soft]# mv mirror php-5.5.35.tar.gz
tar -xvf php-5.5.35.tar.gz
cd php-5.5.35
./configure --prefix=/usr/local/product/php-5.5.35 --with-config-file-path=/usr/local/product/php-5.5.35/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql --with-mysqli --with-mysql --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath

01-centos7.2上源码编译部署LNMP+zabbix3.2(2017-03-07)_第8张图片

安装:

make(时间比较长,耐心等待结果)

01-centos7.2上源码编译部署LNMP+zabbix3.2(2017-03-07)_第9张图片

make test(时间比较长,耐心等待结果)

01-centos7.2上源码编译部署LNMP+zabbix3.2(2017-03-07)_第10张图片

make install

01-centos7.2上源码编译部署LNMP+zabbix3.2(2017-03-07)_第11张图片

建立超链接:

[root@zbserver php-5.5.35]# ln -s /usr/local/product/php-5.5.35 /usr/local/php

配置php

[root@zbserver php-5.5.35]# cp php.ini-production /usr/local/php/etc/php.ini
[root@zbserver php-5.5.35]# cd /usr/local/php/etc/
[root@zbserver etc]# cp php-fpm.conf.default php-fpm.conf
[root@zbserver etc]#

修改php.ini配置参数
修改php.ini参数:(zabbix环境需要修改的参数)

max_execution_time = 300Default is 30)
memory_limit = 128M (no change, default is 128M)
post_max_size = 16M  (default is 8M)
upload_max_filesize = 2M (no change, default is 2M)
max_input_time = 300   (default is 60)
date.timezone = PRC    (default is empty)

将PHP服务加入操作系统启动组

[root@zbserver etc]# echo "/usr/local/php/sbin/php-fpm" >>/etc/rc.local

安装zbabix

[root@zbserver ~]# groupadd zabbix
[root@zbserver ~]# useradd -g zabbix zabbix

在mysql或PostgreSQL中创建Zabbix数据库(本文以mysql为例)

mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.03 sec)

mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'Zabbix_Long01';
Query OK, 0 rows affected, 1 warning (0.02 sec)

设置用户 zabbix可以在任意 IP 下被访问
mysql> grant all privileges on *.* to zabbix@"%" identified by 'Zabbix_Long01'
    -> ;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> grant all privileges on *.* to zabbix@"localhost" identified by 'Zabbix_Long01';
Query OK, 0 rows affected, 1 warning (0.00 sec)


[root@zbserver mysql]# mysql -u zabbix -pZabbix_Long01 zabbix
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@zbserver mysql]# mysql -u zabbix -pZabbix_Long01 zabbix
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@zbserver mysql]# mysql -u zabbix -pZabbix_Long01 zabbix
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@zbserver mysql]#

解压zabbix

tar -zxvf zabbix-3.2.1.tar.gz
[root@zbserver mysql]# mysql -u zabbix -pZabbix_Long01 zabbix
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@zbserver mysql]# mysql -u zabbix -pZabbix_Long01 zabbix
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@zbserver mysql]# mysql -u zabbix -pZabbix_Long01 zabbix
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@zbserver mysql]#
[root@zbserver soft]# rpm -ivh mysql-community-devel-5.7.16-1.el6.x86_64.rpm
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-devel-5.7.16-1.el################################# [100%]
[root@zbserver soft]#

yum install libcurl-devel

yum install net-snmp-devel
yum install libxml2-devel
yum install gcc

跳转到Zabbix解压目录:

./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2

[root@zbserver zabbix-3.2.3]# make install

01-centos7.2上源码编译部署LNMP+zabbix3.2(2017-03-07)_第12张图片

Zabbix Server基本配置

[root@zbserver zabbix-3.2.3]# cd /usr/local/etc/
[root@zbserver etc]# vim zabbix_server.conf

[root@zbserver conf]# grep ^[A-Z] /usr/local/etc/zabbix_server.conf
LogFile=/tmp/zabbix_server.log
DBName=zabbix
DBUser=zabbix
DBPassword=Zabbix_Long01
DBPort=3306
StartVMwareCollectors=5
VMwarePerfFrequency=60
VMwareCacheSize=8M
Timeout=4
LogSlowQueries=3000
[root@zbserver conf]#

修改zabbix_agentd.conf文件

[root@zbserver etc]# vim zabbix_agentd.conf
[root@zbserver etc]# grep ^[A-Z] zabbix_agentd.conf
LogFile=/tmp/zabbix_agentd.log
Server=192.168.181.179
ServerActive=zbserver.create80.com
Hostname=zbserver.create80.com
[root@zbserver etc]#

将zabbix服务加入操作系统启动服务:

echo "/usr/local/sbin/zabbix_server" >>/etc/rc.local

echo "/usr/local/sbin/zabbix_agentd" >>/etc/rc.local

创建Zabbix Server服务:

[root@zbserver etc]# cp /opt/soft/zabbix-3.2.3/misc/init.d/fedora/core/zabbix_server /usr/lib/systemd/system/
[root@zbserver etc]# cd  /usr/lib/systemd/system/
[root@zbserver init.d]# chmod +x zabbix_server
[root@zbserver init.d]#

创建Zabbix agentd服务:

[root@zbserver init.d]# cp /opt/soft/zabbix-3.2.3/misc/init.d/fedora/core/zabbix_agentd /usr/lib/systemd/system/
[root@zbserver init.d]# cd  /usr/lib/systemd/system/
[root@zbserver init.d]# chmod +x zabbix_agentd
[root@zbserver init.d]#

Nginx和Zabbix Server Front Web配置

[root@zbserver html]# mkdir -p zabbix
[root@zbserver html]# cd zabbix/
[root@zbserver zabbix]# mkdir -p logs
[root@zbserver zabbix]# cp -rp /opt/soft/zabbix-3.2.3/frontends/php/* /usr/local/product/nginx1.9.15/html/zabbix/
[root@zbserver zabbix]#

修改NGINX配置文件

cd /usr/local/product/nginx1.9.15/conf
mkdir extra
cd extra

[root@zbserver extra]# vim zabbix.conf
server {
listen 80;
server_name zbserver.create80.com;
access_log /usr/local/product/nginx1.9.15/html/zabbix/logs/zbserver.create80.com.access.log main;
index index.html index.php index.html;
root /usr/local/product/nginx1.9.15/html/zabbix;

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

location ~ ^(.+.php)(.*)$ {
               fastcgi_split_path_info ^(.+.php)(.*)$;
               include fastcgi.conf;
               fastcgi_pass 127.0.0.1:9000;
               fastcgi_index index.php;
               fastcgi_param PATH_INFO $fastcgi_path_info;
}

}

修改nginx.conf

[root@zbserver extra]# cd /usr/local/product/nginx1.9.15/conf/
vim nginx.conf
[root@zbserver extra]# cat nginx.conf

user  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"';

    access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
    include extra/*.conf;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #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;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

web配置页面

把命令放在/etc/rc.locaL文件里头似乎不行,需要手动启动

[root@zbserver ~]# systemctl start zabbix_server
[root@zbserver ~]# /usr/local/php/sbin/php-fpm
[root@zbserver ~]# /usr/local/nginx/sbin/nginx

输入zbserver.create80.com

01-centos7.2上源码编译部署LNMP+zabbix3.2(2017-03-07)_第13张图片

01-centos7.2上源码编译部署LNMP+zabbix3.2(2017-03-07)_第14张图片

01-centos7.2上源码编译部署LNMP+zabbix3.2(2017-03-07)_第15张图片

01-centos7.2上源码编译部署LNMP+zabbix3.2(2017-03-07)_第16张图片

01-centos7.2上源码编译部署LNMP+zabbix3.2(2017-03-07)_第17张图片

01-centos7.2上源码编译部署LNMP+zabbix3.2(2017-03-07)_第18张图片

01-centos7.2上源码编译部署LNMP+zabbix3.2(2017-03-07)_第19张图片

账号密码都是:admin

01-centos7.2上源码编译部署LNMP+zabbix3.2(2017-03-07)_第20张图片

至此zabbix_server安装完成。

你可能感兴趣的:(01-centos7.2上源码编译部署LNMP+zabbix3.2(2017-03-07))