• 部署LNMP架构


    一、LNMP架构简介

    LNMP平台就是Linux、Ngnix、MySQL、PHP的组合架构,需要Linux服务器、MySQL数据库、PHP解析环境
    Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。Mysql是一个小型关系型数据库管理系统。PHP是一种在服务器端执行的嵌入HTML文档的脚本语言。

    二、Nginx编译安装

     1 [root@localhost ~]# yum -y install gcc gcc-c++ make pcre-devel zlib-devel
     2 
     3 [root@localhost ~]# tar zxf nginx-1.12.2.tar.gz
     4 [root@localhost ~]# cd nginx-1.12.2/
     5 [root@localhost nginx-1.12.2]# ./configure 
     6 --prefix=/usr/local/nginx 
     7 --user=nginx 
     8 --group=nginx 
     9 --with-http_stub_status_module ###统计状态模块
    10 
    11 [root@localhost nginx-1.12.2]# make && make install
    12 
    13 [root@localhost ~]# useradd -M -s /sbin/nologin nginx  ###创建一个不可登录的程序用户
    14 
    15 [root@localhost ~]# ln -s /usr/local/nginx/sbin/nginx /usr/bin ###优化执行路径
    16 [root@localhost ~]# nginx ###启动服务
    17 [root@localhost ~]# netstat -anpt | grep nginx ###查看nginx服务是否开启
    18 tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      16429/nginx: master
    19 
    20 [root@localhost ~]# killall -s QUIT nginx ###选项-s QUIT等于-3 停止服务
    21 [root@localhost ~]# netstat -anpt | grep nginx
    22 
    23 [root@localhost ~]# killall -s HUP nginx ###选项-s HUP等于-1 重新加载
    24 [root@localhost ~]# netstat -anpt | grep nginx
    25 tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      16488/nginx: master
    26 
    27 [root@localhost ~]# vi /etc/init.d/nginx ###制作管理脚本
    28 #!/bin/bash
    29 #chkconfig: 35 20 80
    30 #description: nginx server
    31 PROG="/usr/local/nginx/sbin/nginx"
    32 PIDF="/usr/local/nginx/logs/nginx.pid"
    33 
    34 case "$1" in
    35     start)
    36        $PROG
    37        ;;
    38     stop)
    39        killall -s QUIT $(cat $PIDF)
    40        ;;
    41     restart)
    42        $0 stop
    43        $0 start
    44        ;;
    45     reload)
    46        killall -s HUP $(cat $PIDF)
    47        ;;
    48     *)
    49        echo "Usage: $0 {start|stop|reload|status}"
    50        exit 1
    51 esac
    52 exit 0
    53 
    54 [root@localhost ~]# chmod +x /etc/init.d/nginx
    55 [root@localhost ~]# chkconfig --add nginx

    三、编译安装Mysql数据库

    3.1、安装环境

    1 [root@localhost ~]# yum -y install 
    2 ncurses 
    3 ncurses-devel 
    4 bison 
    5 cmake

    3.2、创建不可登录的用户

    1 [root@localhost ~]# useradd -s /sbin/nologin mysql

    3.3、上传安装包到/opt目录下解压缩并进行cmake配置

     1 [root@localhost ~]# cd /opt
     2 [root@localhost opt]# tar zxf mysql-boost-5.7.20.tar.gz
     3 
     4 [root@localhost mysql-5.7.20]# cmake 
     5 -DCMAKE_INSTALL_PREFIX=/usr/local/mysql 
     6 -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock 
     7 -DSYSCONFDIR=/etc 
     8 -DSYSTEMD_PID_DIR=/usr/local/mysql 
     9 -DDEFAULT_CHARSET=utf8  
    10 -DDEFAULT_COLLATION=utf8_general_ci 
    11 -DWITH_INNOBASE_STORAGE_ENGINE=1 
    12 -DWITH_ARCHIVE_STORAGE_ENGINE=1 
    13 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 
    14 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 
    15 -DMYSQL_DATADIR=/usr/local/mysql/data 
    16 -DWITH_BOOST=boost 
    17 -DWITH_SYSTEMD=1

    3.4、编译安装

    1 [root@localhost mysql-5.7.20]# make && make install

    3.5、数据库目录进行权限调整

    1 [root@localhost ~]# chown -R mysql:mysql /usr/local/mysql/

    3.6、建立调整配置文件

     1 [root@localhost ~]# vi /etc/my.cnf
     2 [client]
     3 port = 3306
     4 default-character-set=utf8
     5 socket = /usr/local/mysql/mysql.sock
     6 
     7 [mysql]
     8 port = 3306
     9 default-character-set=utf8
    10 socket = /usr/local/mysql/mysql.sock
    11 
    12 [mysqld]
    13 user = mysql
    14 basedir = /usr/local/mysql
    15 datadir = /usr/local/mysql/data
    16 port = 3306
    17 character_set_server=utf8
    18 pid-file = /usr/local/mysql/mysqld.pid
    19 socket = /usr/local/mysql/mysql.sock
    20 server-id = 1
    21 
    22 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES

    3.7、调整配置文件权限

    1 [root@localhost ~]# chown mysql:mysql /etc/my.cnf

    3.8、设置环境变量

    1 [root@localhost ~]# echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >>/etc/profile
    2 [root@localhost ~]# echo 'export PATH' >> /etc/profile
    3 [root@localhost ~]# source /etc/profile

    3.9、初始化数据库

    1 [root@localhost ~]# cd /usr/local/mysql/
    2 [root@localhost mysql]# bin/mysqld 
    3 --initialize-insecure 
    4 --user=mysql 
    5 --basedir=/usr/local/mysql 
    6 --datadir=/usr/local/mysql/data

    3.10、编辑启动文件

    1 [root@localhost ~]# cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/

    3.11、启动mysql数据库并查看状态

    1 [root@localhost ~]# systemctl start mysqld
    2 [root@localhost ~]# netstat -anpt | grep mysqld
    3 tcp6       0      0 :::3306                 :::*                    LISTEN      67263/mysqld

    3.12、设置root登陆并设置密码

    1 [root@localhost ~]# mysqladmin -uroot -p password 

     

    四、编译安装PHP环境解析

    4.1、安装环境依赖包

     1 [root@localhost ~]# yum -y install 
     2 libjpeg 
     3 libjpeg-devel 
     4 libpng libpng-devel 
     5 freetype freetype-devel 
     6 libxml2 
     7 libxml2-devel 
     8 zlib zlib-devel 
     9 curl curl-devel 
    10 openssl openssl-devel

    4.2、上传文件至opt目录下并解压缩

    1 [root@localhost ~]# cd /opt
    2 [root@localhost opt]# tar jxf php-7.1.10.tar.bz2

    4.3、configure配置

     1 [root@localhost opt]# cd php-7.1.10/
     2 [root@localhost php-7.1.10]# ./configure 
     3 --prefix=/usr/local/php 
     4 --with-mysql-sock=/usr/lcoal/mysql/mysql.sock 
     5 --with-mysqli 
     6 --with-zlib 
     7 --with-curl 
     8 --with-gd 
     9 --with-jpeg-dir 
    10 --with-png-dir 
    11 --with-freetype-dir 
    12 --with-openssl 
    13 --enable-fpm 
    14 --enable-mbstring 
    15 --enable-xml 
    16 --enable-session 
    17 --enable-ftp 
    18 --enable-pdo 
    19 --enable-tokenizer 
    20 --enable-zip

    4.4、编译安装

    1 [root@localhost php-7.1.10]# make && make install

    4.5、php有三个配置文件,php.ini 核心配置文件,php-fpm.conf 进程服务配置文件,www.conf扩展配置文件

    1 [root@localhost php-7.1.10]# cp php.ini-development /usr/local/php/lib/php.ini
    2 [root@localhost php-7.1.10]# vi /usr/local/php/lib/php.ini
    3 date.timezone = Asia/Shanghai
    4 mysqli.default_socket = /usr/lcoal/mysql/mysql.sock

    4.6、配置及优化fpm模块

     1 [root@localhost php-7.1.10]# cd /usr/local/php/etc/
     2 [root@localhost etc]# cp php-fpm.conf.default php-fpm.conf
     3 [root@localhost etc]# cd php-fpm.d/
     4 [root@localhost php-fpm.d]# cp www.conf.default www.conf
     5 [root@localhost etc]# vi php-fpm.conf
     6 pid = run/php-fpm.pid ###去掉;号
     7 
     8 [root@localhost etc]# /usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini
     9 [root@localhost etc]# netstat -ntap | grep 9000
    10 tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN       118685/php-fpm: mas
    11 
    12 [root@localhost etc]# ln -s /usr/local/php/bin/* /usr/local/bin
    13 [root@localhost etc]# ps aux | grep -c "php-fpm" ###查看php-fpm进程数
    14 4

    4.7、配置Nginx支持PHP功能

     1 [root@localhost ~]# vi /usr/local/nginx/conf/nginx.conf
     2  location ~ .php$ {
     3             root           /var/www/aa;
     4             fastcgi_pass   127.0.0.1:9000;
     5             fastcgi_index  index.php;
     6             include        fastcgi.conf;
     7         }
     8 
     9 [root@localhost ~]# vi /var/www/aa/index.php
    10 <?php
    11 phpinfo();
    12 ?>
    13 
    14 [root@localhost ~]# systemctl restart nginx

    4.8、在客户端测试 http://192.168.73.40/index.php

     4.9、测试数据库工作是否正常

     1 [root@localhost ~]# mysql -u root -p
     2 Enter password: ###输入之前设置的密码
     3 
     4 mysql> create database test;
     5 Query OK, 1 row affected (0.00 sec)
     6 
     7 mysql> grant all on bbs.* to 'bbsuser'@'%' identified by 'admin123';
     8 Query OK, 0 rows affected, 1 warning (0.01 sec)
     9 
    10 mysql> grant all on bbs.* to 'bbsuser'@'localhost' identified by 'admin123';
    11 Query OK, 0 rows affected, 1 warning (0.00 sec)
    12 
    13 mysql> flush privileges;
    14 Query OK, 0 rows affected (0.01 sec)
    15 
    16 [root@localhost ~]# vi /usr/local/nginx/html/index.php ###更改测试页内容
    17 <?php
    18 $link=mysqli_connect('192.168.73.40','bbsuser','admin123');
    19 if($link) echo "<h1>Success!</h1>";
    20 else echo "Fail!!";
    21 ?>
    22 [root@localhost ~]# systemctl restart nginx

    4.10、在客户端输入 http://192.168.73.40/index.php测试

    五、部署Discuz!社区论坛Web应用

    5.1、安装

     1 [root@localhost ~]# cd /opt
     2 [root@localhost opt]# unzip Discuz_X3.4_SC_UTF8.zip ###将安装包放在/opt目录下并解压缩
     3 [root@localhost opt]# cd dir_SC_UTF8/
     4 [root@localhost dir_SC_UTF8]# cp -r upload /var/www/aa/bbs
     5 [root@localhost dir_SC_UTF8]# cd /var/www/aa/bbs/
     6 ###给安装论坛的文件权限
     7 [root@localhost bbs]# chown -R root:nginx ./config
     8 [root@localhost bbs]# chown -R root:nginx ./data
     9 [root@localhost bbs]# chown -R root:nginx ./uc_client
    10 [root@localhost bbs]# chown -R root:nginx ./uc_server
    11 [root@localhost bbs]# chmod -R 777 ./config
    12 [root@localhost bbs]# chmod -R 777 ./data
    13 [root@localhost bbs]# chmod -R 777 ./uc_client
    14 [root@localhost bbs]# chmod -R 777 ./uc_server
    15 [root@localhost bbs]# systemctl restart nginx

    5.2、在客户端输入 http://192.168.73.40/bbs/install/index.php 进行论坛安装

    5.3、安装完毕再用http://192.168.73.40/bbs/index.php登录论坛

     5.4、登录http://192.168.73.40/bbs/admin.php可以直接进管理中心

  • 相关阅读:
    取最小未用的账号
    Oracle 同义词
    RMAN备份报 RMAN-06059 错误
    Oracle11g memory_target
    基础记录
    uboot启动流程
    android有关生命周期探讨
    can协议
    java虚拟机
    内存管理机制
  • 原文地址:https://www.cnblogs.com/xuhao0705/p/13828294.html
Copyright © 2020-2023  润新知