jjfjjj 发表于 2019-1-19 07:58:53

LNMP+Zabbix


  第1章 环境规划
  1.1 环境要求
  # cat /etc/redhat-release
  CentOS release 6.7 (Final)
  # uname -m
  x86_64
  # uname -r
  2.6.32-573.el6.x86_64
  # uname -n
  web01
  # uname -a
  Linux web01 2.6.32-573.el6.x86_64 #1 SMP Thu Jul 23 15:44:03 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
  #
  1.2 软件版本
  软件版本
  nginx-1.10.1.tar.gz1.10.1
  php-5.5.32.tar.gz5.5.32
  mysql-5.5.49-linux2.6-x86_64.tar.gz5.5.49
  
  1.3 系统规划
  1.3.1 IP规划
  IP地址软件
  10.0.0.8安装zabbix
  第2章 安装Nginx
  2.1 上传软件包
  2.1.1 创建软件包存放目录
  # mkdir /home/oldboy/tools
  # ls -l /home/oldboy/
  total 4
  drwxr-xr-x 2 root root 4096 Jul 24 23:30 tools
  #
  2.1.2 上传软件包
  # cd /home/oldboy/tools/
  # rz -E
  rz waiting to receive.
  # ls
  nginx-1.10.1.tar.gz
  #
  2.2 安装Nginx依赖包
  # yum -y install openssl openssl-devel pcre pcre-devel
  2.3 解压编译安装Nginx
  2.3.1 创建nginx服务管理用户
  # useradd -s /sbin/nologin -M nginx
  # id nginx
  uid=501(nginx) gid=501(nginx) groups=501(nginx)
  #
  2.3.2 解压编译安装nginx
  # ls
  nginx-1.10.1.tar.gz
  # tar xf nginx-1.10.1.tar.gz
  # cd nginx-1.10.1
  # ls
  autoCHANGESCHANGES.ruconfconfigurecontribhtmlLICENSEmanREADMEsrc
  # ./configure --prefix=/application/nginx-1.10.1 --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module
  编译正确结果:
   nginx path prefix: "/application/nginx-1.10.1"
   nginx binary file: "/application/nginx-1.10.1/sbin/nginx"
   nginx modules path: "/application/nginx-1.10.1/modules"
   nginx configuration prefix: "/application/nginx-1.10.1/conf"
   nginx configuration file: "/application/nginx-1.10.1/conf/nginx.conf"
   nginx pid file: "/application/nginx-1.10.1/logs/nginx.pid"
   nginx error log file: "/application/nginx-1.10.1/logs/error.log"
   nginx http access log file: "/application/nginx-1.10.1/logs/access.log"
   nginx http client request body temporary files: "client_body_temp"
   nginx http proxy temporary files: "proxy_temp"
   nginx http fastcgi temporary files: "fastcgi_temp"
   nginx http uwsgi temporary files: "uwsgi_temp"
   nginx http scgi temporary files: "scgi_temp"
  # make
  编译正确结果:
  sed -e "s|%%PREFIX%%|/application/nginx-1.10.1|" \
  -e "s|%%PID_PATH%%|/application/nginx-1.10.1/logs/nginx.pid|" \
  -e "s|%%CONF_PATH%%|/application/nginx-1.10.1/conf/nginx.conf|" \
  -e "s|%%ERROR_LOG_PATH%%|/application/nginx-1.10.1/logs/error.log|" \
  < man/nginx.8 > objs/nginx.8
  make: Leaving directory `/home/oldboy/tools/nginx-1.10.1'
  # make install
  make未报错结果:
  || mkdir -p '/application/nginx-1.10.1/logs'
  test -d '/application/nginx-1.10.1/html' \
  || cp -R html '/application/nginx-1.10.1'
  test -d '/application/nginx-1.10.1/logs' \
  || mkdir -p '/application/nginx-1.10.1/logs'
  make: Leaving directory `/home/oldboy/tools/nginx-1.10.1'
  #
  2.3.3 创建软链接文件
  # ln -s /application/nginx-1.10.1/ /application/nginx
  # ls -l /application/
  total 4
  lrwxrwxrwx 1 root root   26 Jul 24 23:45 nginx -> /application/nginx-1.10.1/
  drwxr-xr-x 6 root root 4096 Jul 24 23:44 nginx-1.10.1
  #
  2.3.4 启动nginx,测试安装是否正常
  # /application/nginx/sbin/nginx
  # lsof -i :80
  COMMANDPIDUSER   FD   TYPE DEVICE SIZE/OFF NODE NAME
  nginx   3873root    6uIPv415870      0t0TCP *:http (LISTEN)
  nginx   3874 nginx    6uIPv415870      0t0TCP *:http (LISTEN)
  # netstat -tunlp|grep nginx
  tcp      0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      3873/nginx         
  #
  2.3.5 前段web页面测试
  
  第3章 安装Mysql数据库
  3.1 上传mysql二进制安装包
  # rz -E
  rz waiting to receive.
  # ls
  mysql-5.5.49-linux2.6-x86_64.tar.gznginx-1.10.1nginx-1.10.1.tar.gz
  #
  3.2 创建mysql用户
  # useradd -s /sbin/nologin -M mysql
  # id mysql
  uid=502(mysql) gid=502(mysql) groups=502(mysql)
  #
  3.3 安装mysql
  3.3.1 解压二进制文件并移动到application目录下
  # tar xf mysql-5.5.49-linux2.6-x86_64.tar.gz
  # ls
  mysql-5.5.49-linux2.6-x86_64         nginx-1.10.1
  mysql-5.5.49-linux2.6-x86_64.tar.gznginx-1.10.1.tar.gz
  # mv mysql-5.5.49-linux2.6-x86_64 /application/mysql-5.5.49
  3.3.2 创建软链接
  # ln -s /application/mysql-5.5.49/ /application/mysql
  # ls -l /application/
  total 8
  lrwxrwxrwx1 root root   26 Jul 24 23:59 mysql -> /application/mysql-5.5.49/
  drwxr-xr-x 13 root root 4096 Jul 24 23:58 mysql-5.5.49
  lrwxrwxrwx1 root root   26 Jul 24 23:45 nginx -> /application/nginx-1.10.1/
  drwxr-xr-x 11 root root 4096 Jul 24 23:46 nginx-1.10.1
  #
  3.3.3 创建mysql配置文件和启动文件
  # \cp /application/mysql/support-files/my-small.cnf /etc/my.cnf
  # cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld
  # ls -l /etc/init.d/mysqld
  -rwxr-xr-x 1 root root 10880 Jul 25 00:02 /etc/init.d/mysqld
  #
  # sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe /etc/init.d/mysqld
  3.3.4 初始化mysql数据库
  # /application/mysql/scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data/ --user=mysql
  Installing MySQL system tables...
  1607250:08:23 /application/mysql//bin/mysqld (mysqld 5.5.49) starting as process 3981 ...
  OK
  Filling help tables...
  1607250:08:23 /application/mysql//bin/mysqld (mysqld 5.5.49) starting as process 3988 ...
  OK
  To start mysqld at boot time you have to copy
  support-files/mysql.server to the right place for your system
  PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
  To do so, start the server, then issue the following commands:
  /application/mysql//bin/mysqladmin -u root password 'new-password'
  /application/mysql//bin/mysqladmin -u root -h web01 password 'new-password'
  Alternatively you can run:
  /application/mysql//bin/mysql_secure_installation
  which will also give you the option of removing the test
  databases and anonymous user created by default.This is
  strongly recommended for production servers.
  See the manual for more instructions.
  You can start the MySQL daemon with:
  cd /application/mysql/ ; /application/mysql//bin/mysqld_safe &
  You can test the MySQL daemon with mysql-test-run.pl
  cd /application/mysql//mysql-test ; perl mysql-test-run.pl
  Please report any problems at http://bugs.mysql.com/
  #
  3.4 递归修改/application/mysql目录
  # chown -R mysql.mysql /application/mysql/
  # ls -lr /application/mysql/
  total 220
  drwxr-xr-x2 mysql mysql   4096 Jul 24 23:58 support-files
  drwxr-xr-x4 mysql mysql   4096 Jul 24 23:58 sql-bench
  drwxr-xr-x 27 mysql mysql   4096 Jul 24 23:58 share
  drwxr-xr-x2 mysql mysql   4096 Jul 24 23:58 scripts
  -rw-r--r--1 mysql mysql   2496 Mar1 13:45 README
  drwxr-xr-x 10 mysql mysql   4096 Jul 24 23:58 mysql-test
  drwxr-xr-x4 mysql mysql   4096 Jul 24 23:58 man
  drwxr-xr-x3 mysql mysql   4096 Jul 24 23:58 lib
  -rw-r--r--1 mysql mysql 152629 Mar1 13:53 INSTALL-BINARY
  drwxr-xr-x3 mysql mysql   4096 Jul 24 23:58 include
  drwxr-xr-x2 mysql mysql   4096 Jul 24 23:58 docs
  drwxr-xr-x5 mysql mysql   4096 Jul 25 00:08 data
  -rw-r--r--1 mysql mysql17987 Mar1 13:45 COPYING
  drwxr-xr-x2 mysql mysql   4096 Jul 25 00:03 bin
  #
  3.5 修改环境变量
  # echo 'export PATH=/application/mysql/bin/:$PATH' >>/etc/profile
  # source /etc/profile
  # echo $PATH
  /application/mysql/bin/:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
  #
  3.6 添加开机自启动
  # chkconfig --add mysqld
  # chkconfig --level 3 mysqld on
  # chkconfig --list|grep mysqld
  mysqld         0:off1:off2:on3:on4:on5:on6:off
  #
  3.7 启动mysql数据库
  # /etc/init.d/mysqld start
  Starting MySQL.. SUCCESS!
  # lsof -i :3306
  COMMANDPIDUSER   FD   TYPE DEVICE SIZE/OFF NODE NAME
  mysqld4274 mysql   10uIPv423779      0t0TCP *:mysql (LISTEN)
  # netstat -tunlp|grep mysqld
  tcp      0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      4274/mysqld      
  #
  3.8 优化mysql
  # mysqladmin -uroot password "oldboy123"
  # mysql -u root -poldboy123 -e "drop user 'root'@'::1';"
  #mysql -u root -poldboy123 -e "drop user ''@'localhost';"
  # mysql -u root -poldboy123 -e "drop user ''@web01;"
  # mysql -u root -poldboy123 -e "drop user root@web01;"
  # mysql -u root -poldboy123 -e "select user,host from mysql.user;"
  +------+-----------+
  | user | host      |
  +------+-----------+
  | root | 127.0.0.1 |
  | root | localhost |
  +------+-----------+
  #mysql -u root -poldboy123 -e "flush privileges;"
  #mysql -u root -poldboy123 -e "drop database test;"
  #mysql -u root -poldboy123 -e "show databases;"
  +--------------------+
  | Database         |
  +--------------------+
  | information_schema |
  | mysql            |
  | performance_schema |
  +--------------------+
  #
  第4章 安装php
  4.1 上传php
  # ls -l /home/oldboy/tools/
  total 204636
  -rw-r--r-- 1 root root   4984397 Aug82011 libiconv-1.14.tar.gz
  -rw-r--r-- 1 root root 185870973 Jul3 10:52 mysql-5.5.49-linux2.6-x86_64.tar.gz
  drwxr-xr-x 9 1001 1001      4096 Jul 24 23:42 nginx-1.10.1
  -rw-r--r-- 1 root root    909077 Jun 12 11:43 nginx-1.10.1.tar.gz
  -rw-r--r-- 1 root root17773092 Jul3 12:18 php-5.5.32.tar.gz
  #
  4.2 安装php依赖包
  4.2.1 yum安装的依赖包
  # yum -y install zlib-devel libxml2 libxml2-devellibjpeg-turbo-develfreetype-devel libpng-devel gd-devel libcurl-devel libxslt-devellibmcrypt-devel mhash mcrypt
  4.2.2 源码安装的依赖包
  # tar xf libiconv-1.14.tar.gz
  # cd libiconv-1.14
  # ./configure --prefix=/usr/local/libiconv
  # make && make install
  4.2.3 编译安装php
  # ./configure \
  --prefix=/application/php5.5.32 \
  --with-mysql=/application/mysql/ \
  --with-pdo-mysql=mysqlnd \
  --with-mysqli=mysqlnd \
  --with-iconv-dir=/usr/local/libiconv \
  --with-freetype-dir \
  --with-jpeg-dir \
  --with-png-dir \
  --with-zlib \
  --with-libxml-dir=/usr \
  --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-zip \
  --enable-soap \
  --enable-short-tags \
  --enable-static \
  --with-xsl \
  --with-fpm-user=nginx \
  --with-fpm-group=nginx \
  --enable-opcache=no\
  --enable-ftp \
  --with-gettext
  正常编译结果:
  +--------------------------------------------------------------------+
  | 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 php5.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/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
  # ln -s /application/mysql/lib/libmysqlclient.so.18/usr/lib64/
  # touch ext/phar/phar.phar
  #make
  Generating phar.phar
  PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
  directorygraphiterator.inc
  directorytreeiterator.inc
  clicommand.inc
  invertedregexiterator.inc
  pharcommand.inc
  phar.inc
  
  Build complete.
  Don't forget to run 'make test'.
  
  #make install
   Archive_Tar    - installed: 1.4.0
   Console_Getopt - installed: 1.4.1
   Structures_Graph- installed: 1.1.1
   XML_Util       - installed: 1.3.0
   PEAR         - installed: 1.10.1
  Wrote PEAR system config file at: /application/php5.5.32/etc/pear.conf
  You may want to add: /application/php5.5.32/lib/php to your php.ini include_path
  /home/oldboy/tools/php-5.5.32/build/shtool install -c ext/phar/phar.phar /application/php5.5.32/bin
  ln -s -f phar.phar /application/php5.5.32/bin/phar
  Installing PDO headers:          /application/php5.5.32/include/php/ext/pdo/
  #
  4.3 创建软链接
  # ln -s /application/php5.5.32/ /application/php
  4.4 创建php-fpm配置文件和php启动文件
  # pwd
  /home/oldboy/tools/php-5.5.32
  # cp php.ini-production /application/php/lib/php.ini
  # ls -l /application/php/lib/
  total 72
  drwxr-xr-x 14 root root4096 Jul 25 00:43 php
  -rw-r--r--1 root root 69266 Jul 25 00:46 php.ini
  # cp /application/php/etc/php-fpm.conf.default /application/php/etc/php-fpm.conf
  # ls -l /application/php/etc/
  total 52
  -rw-r--r-- 1 root root1321 Jul 25 00:43 pear.conf
  -rw-r--r-- 1 root root 22610 Jul 25 00:47 php-fpm.conf
  -rw-r--r-- 1 root root 22610 Jul 25 00:43 php-fpm.conf.default
  #
  4.5 启动php
  # /application/php/sbin/php-fpm
  # netstat -tunlp|grep php-fpm
  tcp      0      0 127.0.0.1:9000            0.0.0.0:*                   LISTEN      8348/php-fpm      
  #
  # lsof -i :9000
  COMMANDPIDUSER   FD   TYPE DEVICE SIZE/OFF NODE NAME
  php-fpm 8348root    7uIPv4 131819      0t0TCP localhost:cslistener (LISTEN)
  php-fpm 8349 nginx    0uIPv4 131819      0t0TCP localhost:cslistener (LISTEN)
  php-fpm 8350 nginx    0uIPv4 131819      0t0TCP localhost:cslistener (LISTEN)
  #
  第5章 测试Nginx+php+mysql
  5.1 测试nginx+php链接
  5.1.1 修改nginx配置文件
  # cd /application/nginx/conf/
  # ls
  fastcgi.conf            koi-utf             nginx.conf         uwsgi_params
  fastcgi.conf.default    koi-win             nginx.conf.default   uwsgi_params.default
  fastcgi_params          mime.types          scgi_params          win-utf
  fastcgi_params.defaultmime.types.defaultscgi_params.default
  #
  # cat nginx.conf
  worker_processes1;
  events {
     worker_connections1024;
  }
  http {
     include       mime.types;
     default_typeapplication/octet-stream;
     sendfile      on;
     keepalive_timeout65;
     log_formatmain   '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
     server {
         listen       80;
         server_namelocalhost;
         location / {
           root   html;
           indexindex.php index.html index.htm;
         }
     location ~ .*\.(php|php5)?$ {
      fastcgi_pass127.0.0.1:9000;
      fastcgi_index index.php;
      include fastcgi.conf;
     }
      access_log logs/access_zabbix.log main;
     }
  }
  #
  5.1.2 重启nginx
  # ../sbin/nginx -t
  nginx: the configuration file /application/nginx-1.10.1/conf/nginx.conf syntax is ok
  nginx: configuration file /application/nginx-1.10.1/conf/nginx.conf test is successful
  #
  # ../sbin/nginx -s reload
  #
  5.1.3 编写phpinfo配置文件
  # cat phpinfo.php
  
  #
  5.1.4 测试php解析
  
  解析正常
  5.1.5 测试mysqltest.php文件
  # cat mysqltest.php
  
  
  #
  5.1.6 测试mysql链接
  
  原因:没有启动数据库,启动数据库正常
  
  第6章 安装zabbix
  6.1 上传zabbix软件
  # ls
  nginx-1.10.1php-5.5.32php-5.5.32.tar.gzzabbix-3.0.3.tar.gz
  # tar xf zabbix-3.0.3.tar.gz
  #
  6.2 安装zabbix依赖包
  # yum -y install mysql-devel libxml2-devel net-snmp-devel libcurl-devel
  6.3 编译安装zabbix
  # tar xf zabbix-3.0.3.tar.gz
  # cd /home/oldboy/tools/zabbix-3.0.3
  # ls
  aclocal.m4ChangeLog   config.sub    database   INSTALL      Makefile.inNEWS
  AUTHORS   compile       configure   depcomp    install-sh   man          README
  bin         conf          configure.acfrontendsm4         misc         src
  build       config.guessCOPYING       include    Makefile.ammissing      upgrades
  # ./configure --prefix=/application/zabbix-server --enable-server --with-mysql --with-net-snmp --with-libcurl --with-libxml2
  编译报错:
  checking size of void *... 8
  checking for mysql_config... /application/mysql/bin//mysql_config
  checking for main in -lmysqlclient... no
  configure: error: Not found mysqlclient library
  #
  解决方法:
  # sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysql_config
  
   Enable proxy:          no
  
   Enable agent:          no
  
   Enable Java gateway:   no
  
   LDAP support:          no
   IPv6 support:          no
  
  ***********************************************************
  *            Now run 'make install'                     *
  *                                                         *
  *            Thank you for using Zabbix!                  *
  *                                  *
  ***********************************************************
  
  #make install
  make: Nothing to be done for `install-exec-am'.
  make: Nothing to be done for `install-data-am'.
  make: Leaving directory `/home/oldboy/tools/zabbix-3.0.3'
  make: Leaving directory `/home/oldboy/tools/zabbix-3.0.3'
  #
  6.4 生成zabbix的web文件
  # mkdir /application/nginx/html/zabbix
  # cp -a /home/oldboy/tools/zabbix-3.0.3/frontends/php/* /application/nginx/html/zabbix
  #
  6.5 导入zabbix数据库
  6.5.1 创建zabbix数据库
  # mysql -uroot -poldboy123
  Welcome to the MySQL monitor.Commands end with ; or \g.
  Your MySQL connection id is 2
  Server version: 5.5.49 MySQL Community Server (GPL)
  
  Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
  
  Oracle is a registered trademark of Oracle Corporation and/or its
  affiliates. Other names may be trademarks of their respective
  owners.
  
  Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  
  mysql> create database zabbix_server default charset utf8;
  Query OK, 1 row affected (0.00 sec)
  
  mysql> grant all privileges on zabbix_server.* to zabbix@localhost identified by 'zabbix';
  Query OK, 0 rows affected (0.00 sec)
  
  mysql> flush privileges;
  Query OK, 0 rows affected (0.00 sec)
  
  mysql> \q
  Bye
  #
  6.5.2 导入数据库
  # cd database/mysql/
  # pwd
  /home/oldboy/tools/zabbix-3.0.3/database/mysql
  # mysql -uzabbix -pzabbix zabbix_server
页: [1]
查看完整版本: LNMP+Zabbix