zoukankan      html  css  js  c++  java
  • nginx+php+mysql+zabbix服务器安装

    好久没有接触监控类的软件了,今天抽空搭建了下

    首先系统环境

      zabbix-server-1    centos7.2 

    本次所需的第三方软件包

    以下软件包通过官网下载

    zabbix-3.0.3.tar.gz   http://www.zabbix.com/download.php  官网下载页面
    http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/3.0.3/zabbix-3.0.3.tar.gz/download  下载链接

    nginx-1.10.1.tar.gz  http://nginx.org/en/download.html 官网下载页面
    http://nginx.org/download/nginx-1.10.1.tar.gz  下载链接

    php-5.6.22.tar.gz  http://php.net/downloads.php 官网下载页面
    http://cn2.php.net/get/php-5.6.22.tar.gz/from/this/mirror  选择中国站点下载

    配置yum仓库

    [root@zabbix-server-1 yum.repos.d]# cat zabbix.repo

    [base]

    name=CentOS-$releasever - Base

    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra

    baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/

    gpgcheck=1

    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

    enabled=1

    yum clean all  # 清除yum缓存

    yum makecache  # 生成yum缓存

    开始安装nginx

    #安装依赖包

    yum install pcre pcre-devel openssl openssl-devel gcc-c++

    useradd -s /sbin/nologin -M nginx

    tar xf nginx-1.10.1.tar.gz

    ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
    make
    make install

    /usr/local/nginx/sbin/nginx #start nginx service

    ps -ef|grep nginx

    ss -lntup|grep nginx

    [root@zabbix-server-1 conf]# pwd

    /usr/local/nginx/conf

    egrep -v "#|^$" nginx.conf.default > nginx.conf

    #修改部分配置

    [root@zabbix-server-1 conf]# cat nginx.conf

    worker_processes  1;

    events {

    worker_connections  1024;

    }

    http {

    include       mime.types;

    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    server {

    listen       80;

    server_name  localhost;

    location / {

    root   html;

    index  index.php index.html index.htm;

    }

    error_page   500 502 503 504  /50x.html;

    location = /50x.html {

    root   html;

    }

    location ~.(php|php5)?$ {

    root /application/nginx/html;

    fastcgi_pass 127.0.0.1:9000;

    fastcgi_index index.php;

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

    include    fastcgi_params;

    }

    }

    }

    #杀死进程,重启服务

    ps -ef|grep nginx

    /usr/local/nginx/sbin/nginx

    安装php依赖包

    yum –y install zlib-devel libxml2-devel libjpeg-devel libiconv-devel freetype-devel libpng-devel gd-devel curl-devel libxslt-devel mysql-devel

    wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz

    tar zxf libiconv-1.14.tar.gz

    cd libiconv-1.14

    ./configure --prefix=/usr/local/libiconv

    make

    make install

    编辑安装时报错

    make[2]: *** [progname.o] Error 1

    make[2]: Leaving directory `/root/libiconv-1.14/srclib'

    make[1]: *** [install] Error 2

    make[1]: Leaving directory `/root/libiconv-1.14/srclib'

    make: *** [install] Error 2

    解决方法:进入srclib目录 执行 sed -i -e '/gets is a security/d' ./stdio.in.h

    安装php

    tar xf php-5.6.22.tar.gz

    tar -zxvf mirror

    cd php-5.6.22

    ./configure

    --prefix=/usr/local/php

    --with-mysql

    --with-mysqli=mysqlnd

    --with-pdo-mysql=mysqlnd

    --with-iconv-dir=/usr/local/libiconv

    --with-freetype-dir

    --with-jpeg-dir

    --with-png-dir

    --with-zlib

    --with-libxml-dir=/usr

    --with-gettext

    --enable-xml

    --disable-rpath

    --enable-bcmath

    --enable-shmop

    --enable-sysvsem

    --enable-inline-optimization

    --with-curl

    --enable-mbregex

    --enable-fpm

    --enable-mbstring

    --with-mcrypt

    --with-gd

    --enable-gd-native-ttf

    --with-openssl

    --with-mhash

    --enable-pcntl

    --enable-sockets

    --with-xmlrpc

    --enable-soap

    --enable-short-tags

    --enable-static

    --with-xsl

    --with-fpm-user=nginx

    --with-fpm-group=nginx

    --enable-ftp

    --enable-opcache=no

    安装时报错

    configure: error: mcrypt.h not found. Please reinstall libmcrypt.

    解决方法

    yum install -y epel-release
    yum install -y libmcrypt-devel
    两个不能一起安装,因为CentOs6  7默认的yum源没有 libmcrypt-devel这个包,只能借助epel的yum源,所以先安装epel,再安装
    libmcrypt。

    make

    make install

     [root@zabbix-server-1 php-5.6.22]# pwd

    /root/php-5.6.22

    [root@zabbix-server-1 php-5.6.22]# cp php.ini-production /usr/local/php/lib/php.ini

    [root@zabbix-server-1 php-5.6.22]# cd /usr/local/php/etc/

    [root@zabbix-server-1 etc]# ls

    pear.conf  php-fpm.conf.default

    [root@zabbix-server-1 etc]# pwd

    /usr/local/php/etc

    [root@zabbix-server-1 etc]# cp php-fpm.conf.default php-fpm.conf

    [root@zabbix-server-1 etc]# /usr/local/php/sbin/php-fpm

    [root@zabbix-server-1 etc]# netstat -lntup|grep php-fpm

    tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      3689/php-fpm

    安装zabbix

    tar zxvf zabbix-3.0.3.tar.gz

    tar -zxvf download

    cd zabbix-3.0.3

    groupadd zabbix

    useradd -g zabbix zabbix

    #安装依赖包,如果一次安装错误,就多试几次

    yum -y install net-snmp net-snmp-devel libssh2-devel OpenIPMI-devel

    [root@zabbix-server-1 zabbix-3.0.3]# ./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi --with-ssh2

    make

    make install

    [root@zabbix-server-1 zabbix-3.0.3]# egrep -v "#|^$" /usr/local/etc/zabbix_server.conf

    LogFile=/tmp/zabbix_server.log

    DBHost=192.168.11.5

    DBName=zabbix

    DBUser=zabbix

    DBPassword=zabbix

    ListenIP=0.0.0.0

    Timeout=4

    AlertScriptsPath=${datadir}/zabbix/alertscripts

    LogSlowQueries=3000

    #拷贝启动脚本

    cp misc/init.d/fedora/core/zabbix_* /etc/rc.d/init.d/

    zabbix_server

    #修改配置文件

    vim /application/php/lib/php.ini

    max_execution_time = 300

    max_input_time = 300

    post_max_size = 16M

    always_populate_raw_post_data = -1

    date.timezone = Asia/Shanghai

    #重启php

    [root@zabbix-server-1 zabbix-3.0.3]# pkill -9 php-fpm

    [root@zabbix-server-1 zabbix-3.0.3]# /application/php/sbin/php-fpm

    #从zabbix源码包拷贝网站到nginx

    [root@zabbix-server-1 zabbix-3.0.3]# pwd

    /root/zabbix-3.0.3

    [root@zabbix-server-1 zabbix-3.0.3]# cp -rf frontends/php /application/nginx/html/zabbix/

    #如果有防火墙,要么开放80端口,要么临时停止

    Systemctl    stop firewalld

    #给目录设置权限

    chown -R nginx.nginx /application/nginx/html/

    基本上zabbix服务器算是安装差不多了

    这里准备配置mysql服务器了,需要在mysql服务器上授权,及初始化zabbix数据库

    #配置mysql服务器了。

    Mysql5.7安装yum

    介绍在CentOS7上yum安装数据库服务器MySQL Community Server 5.7的方法。

    准备

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

    # rpm -qa | grep maria

    mariadb-libs-5.5.50-1.el7_2.x86_64

    # yum remove mariadb-libs -y

    添加MySQLyum

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

    # yum localinstall http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm

    安装MySQL5.7

    以上yum info命令是2016年8月28日的执行结果,当前安装的MySQL版本是5.7.14。确认安装版本之后执行以下命令进行安装。

    # yum install mysql-community-server -y

    到此MySQL5.7安装就完成了,接下来确认安装的MySQL版本。

    # mysqld --version
    mysqld  Ver 5.7.14 for Linux on x86_64 (MySQL Community Server (GPL))

    启动及停止MySQL

    完成安装步骤之后,首先配置MySQL的开机自动启动,在这里使用systemctl命令

    # systemctl enable mysqld.service

    接着使用systemctl start mysqld.service命令启动MySQL。

    # systemctl start mysqld.service

    而停止MySQL时使用systemctl stop mysqld.service命令。

    # systemctl stop mysqld.service

    以上是在CentOS7.2安装MySQL Community Server 5.7的步骤,但仅限于安装后续还需要根据开发的系统进行配置。

    MySQL5.7开始MySQL管理用户root的密码,会默认生成并记录到/var/log/mysqld.log文件里,不要忘记修改默认密码。

    [Note] A temporary password is generated for root@localhost: lQidlh;BX4*x

    mysql -uroot -plQidlh;BX4*x

    mysql> create database zabbix character set utf8 collate utf8_bin;

    mysql> grant all privileges on zabbix.* to zabbix@’%’ identified by 'zabbix';

    mysql> flush privileges;

    mysql> quit;

    #按照SQL语句顺序导入SQL:

    mysql -uzabbix -pzabbix zabbix < zabbix-3.0.3/database/mysql/schema.sql

    数据导入时报错ERROR 1045 (28000): Access denied for user 'zabbix'@'localhost' (using password: YES)

    解决方法

    mysql -uroot -plQidlh;BX4*x

    mysql> use mysql

    mysql> select host,user,password from user;

    +-----------+--------+-------------------------------------------+

    | host      | user   | password                                  |

    +-----------+--------+-------------------------------------------+

    | localhost | root   | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |

    | zabbix    | root   |                                           |

    | 127.0.0.1 | root   |                                           |

    | ::1       | root   |                                           |

    | localhost |        |                                           |

    | zabbix    |        |                                           |

    | %         | wgldjc | *70E31422FB5C781D112D6C944FAB09312088255B |

    +-----------+--------+-------------------------------------------

    mysql> delete from user where user=' ';

    Query OK, 2 rows affected (0.00 sec)

    mysql> exit

    Bye

    mysql -uzabbix -pzabbix zabbix < zabbix-3.0.3/database/mysql/images.sql

    mysql -uzabbix -pzabbix zabbix < zabbix-3.0.3/database/mysql/data.sql

    打开浏览器,输入以下链接

    http://ip/zabbix/setup.php

     

     

  • 相关阅读:
    利用CSS3 中steps()制用动画
    移动WEB测试工具 Adobe Edge Inspect
    Grunt配置文件编写技巧及示范
    CSS3 box-shadow快速教程
    编写爬虫程序的神器
    node+express+jade搭建一个简单的"网站"
    node+express+ejs搭建一个简单的"页面"
    node的模块管理
    node的调试
    mongoDB的权限管理
  • 原文地址:https://www.cnblogs.com/zhehan/p/8204894.html
Copyright © 2011-2022 走看看