LNMP 部署及 建立bbs论坛

#####安装Nginx服务######
##1 安装环境依赖包##
[root@server1 opt]# yum -y install pcre-devel zlib-devel
##2 创建不可登录的用户,组##
[root@server1 opt]# useradd -M -s /sbin/nologin nginx

3 编译安装Nginx##

[root@server1 opt]# tar -xf nginx-1.6.0.tar.gz 
[root@server1 opt]# cd nginx-1.6.0/
[root@server1 nginx-1.6.0]# ./configure \
> --prefix=/usr/local/nginx \
> --user=nginx \
> --group=nginx \
> --with-http_stub_status_module
[root@server1 nginx-1.6.0]# make && make install

4 路径优化##

[root@server1 nginx-1.6.0]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin
[root@server1 nginx-1.6.0]# nginx                                    ###服务启动##

5 检查配置文件

[root@server1 nginx-1.6.0]# nginx -t                                ###检查配置文件##
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

[root@server1 nginx-1.6.0]# netstat -anpt | grep nginx     ###检查服务启动状态##
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      5105/nginx: master
 ## 6启动,停止Nginx ##
[root@server1 nginx-1.6.0]# killall -s QUIT nginx               ###关闭Nginx服务##
[root@server1 nginx-1.6.0]# nginx                                    
[root@server1 nginx-1.6.0]# netstat -anpt | grep nginx  
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      5154/nginx: master
 
########################补充############################
[root@server1 nginx-1.6.0]# killall -3 nginx   ####关闭服务的另外一种方式########
[root@server1 nginx-1.6.0]# killall -1 nginx   ####重新加载服务  killall -s HUP nginx####
[root@server1 nginx-1.6.0]# netstat -anpt | grep nginx  ###重新加载服务不会改变端口号###
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      5154/nginx: master 

7 添加 Nginx 系统服务

[root@server1 nginx-1.6.0]# vim /lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/bin/kill -s HUP $MAINPID
ExecStop=/usr/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
###说明###
[Service]服务运行参数的设置
Type=forking是后台运行的形式
ExecStart为服务的具体运行命令
ExecReload为重启命令
ExecStop为停止命令
PrivateTmp=True表示给服务分配独立的临时空间

安装nginx自带的检测软件

[root@server1 nginx-1.6.0]# yum -y install lynx
[root@server1 nginx-1.6.0]# lynx 127.0.0.1
                                                   Welcome to nginx!
                         Welcome to nginx!

   If you see this page, the nginx web server is successfully
   installed and working. Further configuration is required.

   For online documentation and support please refer to
   nginx.org.
   Commercial support is available at nginx.com.

   Thank you for using nginx.

###制作启动脚本的另一种方式###
[root@server1 nginx-1.6.0]# vi /etc/init.d/nginx
#!/bin/bash
# chkconfig: 35 20 80
# description: nginx server
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
   start)
    $PROG
    ;;
   stop)
    killall -s QUIT $(cat $PIDF)
    ;;
    restart)
    $0 stop
    $0 start
    ;;
    reload)
    killall -s HUP $(cat $PIDF)
    ;;
    *)
    echo "Usage: $0 {start|stop|reload|restart}"
    exit 1
esac
exit 0

8 更改nginx配置##

[root@server1 nginx-1.6.0]# vi /usr/local/nginx/conf/nginx.conf
user  nginx nginx;    ###更改用户###
worker_processes  4;  ###更改进程数###

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
error_log  logs/error.log  info; ###去掉# 设置报警提示方式###

events {
    use epoll;                                      ##新增use epoll 
    worker_connections 2048;             ##设置进程的并发数##
}

   log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '  ## 去掉#设置日志可是未 main ##
                      '$status $body_bytes_sent "$http_referer" '                               ## 去掉# ## 
                      '"$http_user_agent" "$http_x_forwarded_for"';                          ## 去掉# ## 

  access_log  logs/access.log  main;                                                                 ## 去掉# 设置全局的日志路径 ##

 keepalive_timeout  65;                                                                                     ## 设置保持时间 ##

 gzip  on;                                                                                                          ## 去掉#  开启gzip压缩功能 ##  

server {                                                                                                             
        listen       80;                                                                                             ##  监听端口 ##
        server_name  localhost;                                                                             ## 服务名称地址 ##

        charset utf-8;                                                                                           ## 字符集该utf-8 ##

         access_log  logs/host.access.log  main;                                                      ## 设置虚拟主机的访问日志 默认# 自己设置路径 ##

     location / {                                                                                                  ## 访问的根目录 ## 
            root   /var/www/aa;                                                                             
            index  index.html index.htm;
        }
        
       #####添加统计模块###### 
location ~ /status {                                                                                            ##添加统计模块##
             stub_status  on;                                                                                    ##开启统计模块##
             access_log off;                                                                                      ##关闭访问日志##
         }  


[root@server1 nginx-1.6.0]# systemctl restart nginx.service

查看服务开启状态

[root@server1 nginx-1.6.0]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: [warn] 2048 worker_connections exceed open file resource limit: 1024     ##进程数不是2048##
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@server1 nginx-1.6.0]# ulimit - n 65500 >> /etc/rc.local                             ##修改进程数上限值##
[root@server1 nginx-1.6.0]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
 
     ####配置nginx的验证功能####
[root@server1 nginx-1.6.0]# yum -y install httpd-tools

[root@server1 nginx-1.6.0]# htpasswd -c /usr/local/nginx/passwd.db lisi
New password: 
Re-type new password: 
Adding password for user lisi
[root@server1 nginx-1.6.0]# cat /usr/local/nginx/passwd.db 
lisi:$apr1$T1jrAcdW$XjLO4lnb.SwoX.H0cW9fr1
[root@server1 nginx-1.6.0]# chown nginx /usr/local/nginx/passwd.db 
[root@server1 nginx-1.6.0]# chmod 400 /usr/local/nginx/passwd.db 
[root@server1 nginx-1.6.0]#vi /usr/local/nginx/conf/nginx.conf
location / {
            root   html;
            index  index.html index.htm;
                allow 192.168.106.30;          ###添加4行##
                deny all;
                auth_basic "secret";
                auth_basic_user_file /usr/local/nginx/passwd.db;
            }
  #####配置虚拟主机########
 server {
        listen       80;
        server_name  www.aaa.com;  ##  基于域名
  
        charset utf-8;

        access_log  logs/host.access.log  main;

        location / {
            root   /var/www/aaa;
            index  index.html index.htm;
               # allow 192.168.106.0/24;
               # deny all;
               # auth_basic "secret";
               # auth_basic_user_file /usr/local/nginx/passwd.db;
            }
        location /status {
             stub_status  on;
             access_log off;
        }
        #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;
        }
server {
        listen       8080;     ###基于端口  http://www.bbb.com:8080
        server_name  www.bbb.com;

        charset utf-8;
        gzip  on;
        access_log  logs/host.access.log  main;

        location / {
            root   /var/www/bbb;
            index  index.html index.htm;
                }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
                }

         }
server {
        listen       8080;
        server_name  192.168.106.30; ###基于ip  http://192.168.106.30:8080

        charset utf-8;
        gzip  on;
        access_log  logs/host.access.log  main;

        location / {
            root   /var/www/bbb;
            index  index.html index.htm;
                }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
                }

         }
[root@server1 ~]# vi /etc/profile                                 ####在里面添加    修改连接数  写进/etc/profile 每次运行bash都有运行此指令
ulimit -c unlimited
ulimit -n 102400
[root@server1 ~]# nginx -s reload                              ####重新加载nginx 
##########################################################
#####################安装mysql#############################
#########安装mysql######
yum -y install \
ncurses \
ncurses-devel \
bison \
cmake

useradd -s /sbin/nologin  mysql

###上传mysql-boost-5.7.20.tar.gz到opt目录下###
cd /opt
tar xf mysql-boost-5.7.20.tar.gz
cd /opt/mysql-5.7.20/

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DSYSCONFDIR=/etc \
-DSYSTEMD_PID_DIR=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8  \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=boost \
-DWITH_SYSTEMD=1

####配置选项含义###
1、DCMAKE_INSTALL_PREFIX:指定将 mysql 数据库程序安装到某目录下,
如目录/usr/local/ mysql。
2、DMYSQL_UNIX_ADDR:指定套接字文件的存储路径,数据库连接的文件
3、DSYSCONFDIR:指定初始化参数文件目录
3、DDEFAULT_CHARSET:指定默认使用的字符集编码,如 utf8。
5、DDEFAULT_COLLATION:指定默认使用的字符集校对规则,utf8_general_ci 是适用于 UTF-8 字符集的通用规则。
6、DWITH_INNOBASE_STORAGE_ENGINE=1 :安装INNOBASE存储引擎
7、DWITH_ARCHIVE_STORAGE_ENGINE=1 :安装ARCHIVE存储引擎 
8、DWITH_BLACKHOLE_STORAGE_ENGINE=1 :安装ARCHIVE存储引擎 
9、DWITH_PERFSCHEMA_STORAGE_ENGINE :安装FEDERATED存储引擎 

指定安装文件的安装路径时常用的选项:

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql         指定安装路径 
-DMYSQL_DATADIR=/data/mysql                     数据安装路径 
-DSYSCONFDIR=/etc                               配置文件的安装路径

由于MySQL支持很多的存储引擎而默认编译的存储引擎包括:csv、myisam、myisammrg和heap。若要安装其它存储引擎,可以使用类似如下编译选项:

-DWITH_INNOBASE_STORAGE_ENGINE=1          安装INNOBASE存储引擎 
-DWITH_ARCHIVE_STORAGE_ENGINE=1           安装ARCHIVE存储引擎 
-DWITH_BLACKHOLE_STORAGE_ENGINE=1         安装BLACKHOLE存储引擎 
-DWITH_FEDERATED_STORAGE_ENGINE=1         安装FEDERATED存储引擎 


若要明确指定不编译某存储引擎,可以使用类似如下的选项:

-DWITHOUT_<ENGINE>_STORAGE_ENGINE=1 

比如:

-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1        不启用或不编译EXAMPLE存储引擎 
-DWITHOUT_FEDERATED_STORAGE_ENGINE=1 
 -DWITHOUT_PARTITION_STORAGE_ENGINE=1

如若要编译进其它功能,如SSL等,则可使用类似如下选项来实现编译时使用某库或不使用某库:

-DWITH_READLINE=1 
 -DWITH_SSL=system           表示使用系统上的自带的SSL库 
-DWITH_ZLIB=system 
 -DWITH_LIBWRAP=0

其它常用的选项:

-DMYSQL_TCP_PORT=3306                       设置默认端口的 
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock           MySQL进程间通信的套接字的位置 
-DENABLED_LOCAL_INFILE=1                    是否启动本地的LOCAL_INFILE 
 -DEXTRA_CHARSETS=all                        支持哪些额外的字符集 
-DDEFAULT_CHARSET=utf8                      默认字符集 
-DDEFAULT_COLLATION=utf8_general_ci         默认的字符集排序规则 
-DWITH_DEBUG=0                              是否启动DEBUG功能 
-DENABLE_PROFILING=1                        是否启用性能分析功能

##################################################################################################

------注意:如果在CMAKE的过程中有报错---
        当报错解决后,需要把源码目录中的CMakeCache.txt文件删除,然后再重新CMAKE,否则错误依旧
------注意:make: *** No targets specified and no makefile found. Stop.解决方法
        1、wget http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.6.tar.gz
        2.、tar zxvf ncurses-5.6.tar.gz
        3、 ./configure -prefix=/usr/local -with-shared-without-debug
        4、make
        5、make install

###############################################################################################

######编译安装####

make && make install


#####数据库目录进行权限调整###

chown -R mysql:mysql /usr/local/mysql/


#####建立调整配置文件########

vi /etc/my.cnf

[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock

[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock

[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 1

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


chown mysql:mysql /etc/my.cnf

#######设置环境变量####

echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
echo 'export PATH' >> /etc/profile
source /etc/profile

cd /usr/local/mysql/

bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data

cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
systemctl enable mysqld
systemctl start mysqld
systemctl status mysqld
netstat -anpt | grep 3306

mysqladmin -u root -p password "abc123" //刚开始没密码是空的直接回车,然后输入密码abc123,在此确认abc123,这是在root账户下运行的

mysql -u root -p     ##这个命令敲下,提示要输入密码,这个就是刚才设置的密码abc123
####################安装PHP环境#####
yum -y install \
libjpeg \
libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 \
libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel

-------------以下两行可能用不到-----------
vi /usr/local/httpd/bin/apxs
#!/usr/bin/perl -w

#######上传php-7.1.10.tar.bz2包到opt目录下#####
cd /opt
tar xjvf php-7.1.10.tar.bz2
cd php-7.1.10
./configure \
--prefix=/usr/local/php \
--with-mysql-sock=/usr/local/mysql/mysql.sock \
--with-mysqli \
--with-zlib \
--with-curl \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-openssl \
--enable-fpm \
--enable-mbstring \
--enable-xml \
--enable-session \
--enable-ftp \
--enable-pdo \
--enable-tokenizer \
--enable-zip

#######编译详解#####
1、prefix=/usr/local/php 			###指定将 PHP 程序安装到哪个目录下
2、with-apxs2=/usr/local/httpd/bin/apxs 	###设置 Apache HTTP Server 提供的 apxs 模块支持程序的文件位置
3、with-mysql-sock=/usr/local/mysql/mysql.sock 	###指定mysql的mysql.sock位置
4、with-mysqli 	###mysqli扩展技术不仅可以调用MySQL的存储过程、处理MySQL事务,而且还可以使访问数据库工作变得更加稳定。
5、with-zlib				###支持zlib功能--压缩流
6、with-curl				###开启curl扩展功能
libcurl目前支持http、https、ftp、gopher、telnet、dict、file和ldap协议。libcurl同时也支持HTTPS认证、HTTP POST、HTTP PUT、 FTP 上传(这个也能通过PHP的FTP扩展完成)、HTTP 基于表单的上传、代理、cookies和用户名+密码的认证。PHP中使用cURL实现Get和Post请求的方法
7、with-gd				###激活gd库的支持
8、with-jpeg-dir 				###要激活 jpeg 的支持
9、with-png-dir				###要激活png的支持
10、enable-mbstring 			###启用多字节字符串功能,以便支持中文等代码。



make && make install

cp php.ini-development /usr/local/php/lib/php.ini	###将php.ini-development开发样板,复制到生产环境中去

vi /usr/local/php/lib/php.ini
mysqli.default_socket = /usr/local/mysql/mysql.sock
date.timezone = Asia/Shanghai

/usr/local/php/bin/php -m //验证安装的模块
#############################配置及优化FPM模块#####################
cd /usr/local/php/etc/ ##复制2个模板
cp php-fpm.conf.default php-fpm.conf
cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default  www.conf


cd /usr/local/php/etc/
vi php-fpm.conf
pid = run/php-fpm.pid #去掉;


/usr/local/php/sbin/php-fpm  -c /usr/local/php/lib/php.ini  ##-c 是指带配置文件启动
netstat -anpt | grep 9000
ln -s /usr/local/php/bin/* /usr/local/bin/   
ps aux | grep -c "php-fpm"     ###查看次数


添加php-fpm启动项
[Unit]
Description=php-fpm
After=network.target

[Service]
Type=forking        #后台运行
PIDFile=/usr/local/php/var/run/php-fpm.pid   #PID文件位置
ExecStartPre=/usr/local/php/sbin/php-fpm -t  #启动前先干什么,-t 是先测试配置文件是否正确 -c 是带配置参数启动 
ExecStart=/usr/local/php/sbin/php-fpm     #启动命令
ExecStop=/usr/bin/kill -s QUIT $MAINPID   #重载reload
ExecReload=/usr/bin/kill -s HUP $MAINPID   # #停止服务
PrivateTmp=true   #为服务分配独立的临时空间

[Install]
WantedBy=multi-user.target

[root@server1 ~]# systemctl start php-fpm.service 
[root@server1 ~]# netstat -anpt | grep 9000
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      2001/php-fpm: maste 


遇到的问题
[root@server1 ~]# systemctl start php-fpm.service 
Warning: php-fpm.service changed on disk. Run 'systemctl daemon-reload' to reload units.
[root@server1 ~]# systemctl daemon-reload


###########################让nginx支持PHP功能#########################
 location ~ \.php$ {
            root           /var/www/aaa;   #设置自己的站点
            fastcgi_pass   127.0.0.1:9000; 
            fastcgi_index  index.php;
           # fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi.param;
 vi /var/www/aaa/index.php
        }
<?php                         ##测试网页###
phpinfo();
?>
#########测试数据库工作是否正常######################

[root@server1 aaa]# mysql              ###登录mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.20 Source distribution

Copyright (c) 2000, 2017, 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 bbs;         #创建数据库
Query OK, 1 row affected (0.01 sec)

mysql> grant all on bbs.* to 'bbsuser'@'localhost' identified by '123456';  #给本地授权
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> grant all on bbs.* to 'bbsuser'@'%' identified by '123456';   #给远程授权
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> exit
Bye



[root@server1 aaa]# cd /var/www/aaa/
[root@server1 aaa]# vi index.php 


<?php                         ##测试网页###
$link=mysqli_connect('192.168.106.30','bbsuser','123456');
if($link) echo "<h1>success!</h1>";  
else echo "fail!";
?>
#######################LNMP应用部署bbs论坛#######################
cd /opt/   ###上传 bbs论坛文件
unzip Discuz_X3.4_SC_UTF8.zip -d /opt/ ###解压
cd dir_SC_UTF8/ 
ls -lh
cp -r upload/ /var/www/aaa/bbs ###复制文件到网站根目录
cd /var/www/aaa/bbs/
ls -lh
chmod -R 777 ./config/ ###授权给4个文件
chmod -R 777 ./data/
chmod -R 777 ./uc_client/
chmod -R 777 ./uc_server/
chown -R root:nginx ./config/ ###指定宿主
chown -R root:nginx ./data/
chown -R root:nginx ./uc_client/
chown -R root:nginx ./uc_server/

http://IP/bbs/install/index.php  ##登录网址进行安装,其中数据填之前的用户和密码

http://IP/bbs/index.php           ## 登录bbs网址
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值