blog.zhuohua.store's Archiver

admin 发表于 2019-9-12 22:29

LNMP一键安装包(lnmpa_CentOS6.9)

采用LNMPA架构,是让Nginx做前端、Apache做后端,让Nginx监听80端口,Apache监听非80端口;Nginx只负责前端的静态网页、JavaScript、图片等文件的处理,当客户端请求访问动态网页PHP时,由Nginx反向代理给Apache处理,Apache处理完后,再交给Nginx返回给客户端。


笺注:服务器必须已经连公网,且必须设置网络Yum源,同时服务器的DNS解析要正常!


主机信息:
[root@localhost ~]# cat /etc/redhat-release
[color=Purple]CentOS release 6.9 (Final)[/color]
[root@localhost ~]#
[root@localhost ~]# uname -r
2.6.32-696.el6.x86_64

[root@localhost ~]# hostname
localhost.localdomain
[root@localhost ~]# cat /etc/sysconfig/network |tail -1
HOSTNAME=localhost.localdomain

[root@localhost ~]# ifconfig eth0 |grep "inet addr" |awk '{print $2}' |awk -F: '{print $2}'
[color=Purple]192.168.168.130[/color]



软件可以在官网下载:[url]https://lnmp.org/[/url]

开始安装:
yum -y install screen wget
screen -S lnmp
tar -zxf lnmp1.3-full.tar.gz
cd lnmp1.3-full
./install.sh [color=Blue]lnmpa[/color]


设置数据库用户root@localhost的密码:(以下是把密码设置为 [color=DarkRed]888[/color] )
[attach]14981[/attach]


启用InnoDB Storage Engine,输入 [color=Blue]Y[/color] 再按回车键:
[attach]14982[/attach]


选择数据库版本,这里提供了较多版本的MySQL和MariaDB:
[attach]14983[/attach]


选择PHP版本:
[attach]14984[/attach]


选择是否安装内存优化:
[attach]14985[/attach]


需要设置管理员邮箱,该邮箱会在报错时显示在错误页面上:
[attach]14986[/attach]


选择Apache版本:
[attach]14987[/attach]


安装或取消安装:
[attach]14988[/attach]


下面是全自动安装的^_^ ^_^


安装成功了:(安装好后,最好重启一下服务器)
[attach]14989[/attach]

[attach]14990[/attach]


自动关闭SELinux的:
[attach]14991[/attach]


自动修改、保存防火墙规则的:
[attach]14992[/attach]

注释:
默认开启了TCP 80端口、关闭了TCP 3306端口;
开启了TCP 80端口,就可以正常访问站点了;
虽然Apache监听TCP 88端口,但无需在防火墙中打开TCP 88端口;
假如要客户端直接连接MySQL才要打开TCP 3306端口;




重启Apache:
[attach]14993[/attach]


重启Nginx:
[attach]14994[/attach]


重启MySQL:
[attach]14995[/attach]


重启LNMPA(会重启Nginx、MySQL、Apache)
[attach]14996[/attach]


Nginx、Apache、MySQL默认会随着系统的启动而启动:
[attach]14997[/attach]





MySQL的主配置文件:(查看MySQL的最大连接数)
[root@localhost ~]# cat [color=Blue]/etc/my.cnf[/color] |grep max_connections
max_connections = [color=Purple]500[/color]



Apache的主配置文件:
[root@localhost ~]# tail -1 [color=Blue]/usr/local/apache/conf/httpd.conf[/color]
[color=Purple]IncludeOptional conf/vhost/*.conf[/color]
注释:Apache会加载/usr/local/apache/conf/vhost/下后缀为.conf的配置文件(即虚拟主机的Apache配置文件)


[root@localhost ~]# cat /usr/local/apache/conf/httpd.conf |grep [color=DarkRed]88[/color]
Listen 127.0.0.1:[color=DarkRed]88[/color]
ServerName 127.0.0.1:[color=DarkRed]88[/color]
注释:Apache监听TCP [color=DarkRed]88[/color]端口。


[root@localhost ~]# vi /usr/local/apache/conf/httpd.conf

默认站点的根目录:
[attach]14998[/attach]





Nginx版本信息:
[root@localhost ~]# nginx -v
nginx version: nginx/[color=Purple]1.10.0[/color]

[root@localhost ~]# nginx -V
nginx version: nginx/[color=Purple]1.10.0[/color]
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module


Nginx的主配置文件:
[root@localhost ~]# head -3 [color=Blue]/usr/local/nginx/conf/nginx.conf[/color]
user  [color=Purple]www[/color] [color=Purple]www[/color];
worker_processes [color=Purple]auto[/color];


[root@localhost ~]# cat /usr/local/nginx/conf/nginx.conf |grep -A6 "default_server"
        listen [color=DarkRed]80[/color] default_server; [color=RoyalBlue]#Nginx监听TCP 80端口[/color]
        #listen [::]:80 default_server ipv6only=on;
        server_name www.lnmp.org;
        index index.html index.htm index.php;
        root  [color=Purple]/home/wwwroot/default[/color]; [color=RoyalBlue]#默认站点的根目录[/color]
        #error_page   404   /404.html;
        include [color=DarkRed]proxy-pass-php.conf[/color]; [color=RoyalBlue]#引用的Nginx代理配置文件[/color]


[root@localhost ~]# tail -3 /usr/local/nginx/conf/nginx.conf
[color=Purple]include vhost/*.conf;[/color]
}
注释:Nginx会加载/usr/local/nginx/conf/vhost/下后缀为.conf的配置文件(即虚拟主机的Nginx配置文件)





PHP版本信息:
[root@localhost ~]# php -v
PHP [color=Purple]5.6.22[/color] (cli) (built: Jun 23 2020 02:21:42)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    [color=Blue]with Zend Guard Loader v3.3, Copyright (c) 1998-2014, by Zend Technologies[/color]

备注:
[color=Blue]Zend Guard Loader[/color] 是用于加速PHP的,能提高30%-40%速度;默认会自动安装并启用;
PHP7系列都不再支持Zend Guard Loader


PHP的配置文件:
[root@localhost ~]# find / -name php.ini
[color=Purple]/usr/local/php/etc/php.ini[/color]


PHP的配置文件中关于Zend Guard Loader的配置信息:
[root@localhost ~]# vi /usr/local/php/etc/php.ini
[color=Purple][Zend ZendGuard Loader]
zend_extension=/usr/local/zend/ZendGuardLoader.so
zend_loader.enable=1
zend_loader.disable_licensing=0
zend_loader.obfuscation_level_support=3
zend_loader.license_path=[/color]





客户端直接访问服务器IP( [color=Blue]http://192.168.168.130[/color] )可以看到这个页面:
[attach]14999[/attach]


默认站点的根目录:
[attach]15000[/attach]


PHP探针:( http://192.168.168.130[color=Blue]/p.php[/color] )
[attach]15001[/attach]


PHP测试页:( http://192.168.168.130[color=Blue]/phpinfo.php[/color] )
[attach]15002[/attach]

[attach]15003[/attach]







######
Pureftpd (一款FTP服务器软件)

运行脚本,安装Pureftpd:
cd /root/lnmp1.3-full
./pureftpd.sh

[attach]15004[/attach]

Pureftpd安装成功:
[attach]15005[/attach]


Pureftpd处于运行状态时:
[root@localhost ~]# pgrep -l [color=Blue]pure-ftpd[/color]
[color=Purple]8520 pure-ftpd[/color]

[root@localhost ~]# service [color=DarkRed]pureftpd[/color] status
[color=Purple]Pure-FTPd is running.[/color]


Pureftpd默认会随着系统的启动而启动:
[root@localhost ~]# chkconfig --list [color=DarkRed]pureftpd[/color]
pureftpd        0:关闭  1:关闭  2:启用  [color=Purple]3:启用[/color]  4:启用  [color=Purple]5:启用[/color]  6:关闭


Pureftpd在防火墙对应的端口:
[root@localhost ~]# cat /etc/sysconfig/iptables
# Generated by iptables-save v1.4.7 on Fri Jun 26 23:05:09 2020
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [1:156]
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 3306 -j DROP
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
[color=Purple]-A INPUT -p tcp -m tcp --dport 20 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 21 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 20000:30000 -j ACCEPT [/color]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
# Completed on Fri Jun 26 23:05:09 2020




添加基于域名的虚拟主机(站点):( 用于 Wordpress )
lnmp vhost add
[attach]15006[/attach]


这里选择了开启站点日志,会同时开启此站点的Apache、Nginx的日志功能:
[attach]15007[/attach]


给此站点创建FTP用户:(这里创建的FTP用户对本站点目录有完全控制的权限)
[attach]15008[/attach]


站点 [color=Blue]word.zhuohua.store [/color]的配置信息:
[attach]15009[/attach]



查看虚拟主机(站点)列表:(一个站点有两个虚拟主机,Apache、Nginx各有一个)
lnmp vhost list
[attach]15010[/attach]



一个站点有两个配置文件,Apache、Nginx各有一个:

站点 [color=Blue]word.zhuohua.store [/color]的Apache配置文件:
[root@localhost ~]# cat /usr/local/apache/conf/vhost/[color=Blue]word.zhuohua.store.conf [/color]
<VirtualHost *:[color=DarkRed]88[/color]> [color=RoyalBlue]#监听的端口为TCP 88[/color]
ServerAdmin webmaster@example.com
php_admin_value open_basedir "/home/wwwroot/word.zhuohua.store:/tmp/:/var/tmp/:/proc/"
DocumentRoot "/home/wwwroot/word.zhuohua.store"
ServerName [color=Blue]word.zhuohua.store[/color]
ServerAlias  www.zhuohua.store zhuohua.store
ErrorLog "/home/wwwlogs/word.zhuohua.store-error_log"
CustomLog "/home/wwwlogs/word.zhuohua.store-access_log" combined
<Directory "/home/wwwroot/word.zhuohua.store">
    SetOutputFilter DEFLATE
    Options FollowSymLinks
    AllowOverride All [color=RoyalBlue]#开启此站点的伪静态功能[/color]
    Order allow,deny
    Allow from all
    DirectoryIndex index.html index.php
</Directory>
</VirtualHost>


###

站点 [color=Blue]word.zhuohua.store[/color] 的Nginx配置文件:
[root@localhost ~]# cat /usr/local/nginx/conf/vhost/[color=Blue]word.zhuohua.store.conf[/color] |grep -v ^$
server
    {
        listen [color=DarkRed]80[/color]; [color=RoyalBlue]#监听的端口为TCP 80[/color]
        #listen [::]:80;
        server_name [color=Blue]word.zhuohua.store[/color] www.zhuohua.store zhuohua.store;
        index index.html index.htm index.php default.html default.htm default.php;
        root  /home/wwwroot/word.zhuohua.store;
        #error_page   404   /404.html;
        include [color=DarkRed]proxy-pass-php.conf[/color];  [color=RoyalBlue]#引用的Nginx代理配置文件[/color]
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }
        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }
        location ~ /\.
        {
            deny all;
        }
        access_log  /home/wwwlogs/word.zhuohua.store.log;
}



默认站点、站点[color=Blue]word.zhuohua.store[/color]引用的Nginx代理配置文件:
[root@localhost ~]# cat /usr/local/nginx/conf/[color=DarkRed]proxy-pass-php.conf[/color]
        location /
        {
            try_files $uri @apache;
        }

        location @apache
        {
            internal;
            proxy_pass http://127.0.0.1:88;
            include [color=DarkRed]proxy.conf[/color];
        }

        location ~ [^/]\.php(/|$)
        {
            proxy_pass http://127.0.0.1:88;
            include [color=DarkRed]proxy.conf[/color];
        }


[root@localhost ~]# cat /usr/local/nginx/conf/[color=DarkRed]proxy.conf[/color]
proxy_connect_timeout 300s;
proxy_send_timeout   900;
proxy_read_timeout   900;
proxy_buffer_size    32k;
proxy_buffers     4 32k;
proxy_busy_buffers_size 64k;
proxy_redirect     off;
proxy_hide_header  Vary;
proxy_set_header   Accept-Encoding '';
proxy_set_header   Host   $host;
proxy_set_header   Referer $http_referer;
proxy_set_header   Cookie $http_cookie;
proxy_set_header   X-Real-IP  $remote_addr;
proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;



服务器本地登录MySQL:
[attach]15011[/attach]


创建数据库:( 用于 Wordpress )
create database [color=DarkRed]wordpress[/color];

创建数据库用户([color=Blue]happy@localhost[/color])并赋权:( 用于 Wordpress )
grant all on [color=DarkRed]wordpress[/color].* to [color=Blue]happy@localhost[/color] identified by '1688';
FLUSH PRIVILEGES;

[attach]15012[/attach]


查看库[color=DarkRed]wordpress[/color]的字符集:
mysql> show create database [color=DarkRed]wordpress[/color];
+-----------+-----------------------------------------------------------------------+
| Database  | Create Database                                                       |
+-----------+-----------------------------------------------------------------------+
| wordpress | [color=Purple]CREATE DATABASE `wordpress` /*!40100 DEFAULT CHARACTER SET utf8mb4 */[/color] |
+-----------+-----------------------------------------------------------------------+
1 row in set (0.00 sec)

注释:
数据库的默认字符集为 [color=Blue]utf8mb4_general_ci[/color]
新建数据库时,不指定其字符集,就是使用默认字符集



查看数据库用户([color=Blue]happy@localhost[/color])的权限:
mysql> show grants for [color=Blue]happy@localhost[/color];
+--------------------------------------------------------------+
| Grants for happy@localhost                                   |
+--------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'happy'@'localhost'                    |
| [color=Purple]GRANT ALL PRIVILEGES ON `wordpress`.* TO 'happy'@'localhost'[/color] |
+--------------------------------------------------------------+
2 rows in set (0.00 sec)


Wordpress 的具体安装可参考:[url=http://blog.zhuohua.store/viewthread.php?tid=79&extra=page%3D1]LNMP一键安装包(lnmp_CentOS6.9)[/url]

笺注:
站点目录下的文件和文件夹的属主和属组都要设置为 [color=Blue]www[/color]
环境支持htm、html、php这三种网页 ^_^  ^_^  ^_^



Wordpress安装成功后,站点目录里会自动生成Apache的伪静态规则文件( [color=Blue].htaccess [/color])
[attach]15013[/attach]

备注:
Apache的伪静态规则文件一般都为 [color=Blue].htaccess [/color]
有些Apache站点在其根目录里放入 [color=Blue].htaccess [/color]文件就可以实现伪静态了;文件里面写的伪静态规则需要程序开发那边提供,不是通用的。

Apache的伪静态规则与Nginx的伪静态规则是不一样的,两者并不通用。

基于LNMPA架构的站点只使用Apache的伪静态文件和伪静态规则;无需另外去设置Nginx的伪静态文件。



默认情况下,Wordpress的伪静态规则文件[color=Blue].htaccess[/color]里是没有伪静态规则的:
[attach]15014[/attach]


站点虽然使用了伪静态规则文件,但Wordpress还没有真正开启伪静态功能:
[attach]15015[/attach]


Wordpress还要在后台开启伪静态功能:
设置》固定链接》固定链接设置
选择自定义结构,加上 [color=Blue]/%post_id%.htm[/color]
[attach]15016[/attach]


伪静态开启成功:( 文章的URL的表现形式都显示为静态页面 )
[attach]15017[/attach]


伪静态开启后,也不是说所有URL的表现形式都显示为静态页面:
[attach]15018[/attach]


Wordpress会根据配置去自动生成伪静态规则:
[attach]15019[/attach]














########

删除虚拟主机(站点):
lnmp vhost del
[attach]15020[/attach]


会同时删除站点[color=Blue]word.zhuohua.store[/color]的Nginx 、Apache虚拟主机:
[attach]15021[/attach]


需要手动删除站点word.zhuohua.store的目录:
[root@localhost ~]# cd /home/wwwroot/
[root@localhost wwwroot]# ls
default  word.zhuohua.store
[root@localhost wwwroot]#
[root@localhost wwwroot]#[color=Blue] rm -rf word.zhuohua.store[/color]
[root@localhost wwwroot]#
[root@localhost wwwroot]# ls
Default


需要手动删除站点word.zhuohua.store的数据库:
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| [color=Purple]wordpress [/color]         |
+--------------------+
5 rows in set (0.00 sec)

mysql> [color=Blue]drop database wordpress;[/color]
Query OK, 12 rows affected (0.32 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql>








########

卸载LNMPA架构:

[attach]15022[/attach]


[attach]15023[/attach]


[attach]15024[/attach]





相关文章:
[url=http://blog.zhuohua.store/viewthread.php?tid=80&page=1&extra=#pid81]LNMP一键安装包(lamp_CentOS6.9)[/url]
[url=http://blog.zhuohua.store/viewthread.php?tid=363&page=1&extra=#pid440]Zabbix调用Python3脚本监控Linux下的MySQL[/url]

[url=http://blog.zhuohua.store/viewthread.php?tid=473&page=1&extra=#pid901]CentOS8_lnmp1.7_LNMPA[/url]
[url=http://blog.zhuohua.store/viewthread.php?tid=427&page=1&extra=#pid855]CentOS8_Tomcat8+JDK1.7+MySQL/MariaDB[/url]

[url=http://blog.zhuohua.store/viewthread.php?tid=206&page=1&extra=#pid207]Windows2012R2_UPUPW_ANK(Apache/Nginx)+WordPress[/url]





#################################
#################################
[url=https://weidian.com/?userid=823531601&wfr=wx&sfr=app&source=shop]亲,学习研究也要劳逸结合哦,来我微店逛逛,买点东西好好犒劳犒劳自己和家人吧^_^^_^[/url]

[url=https://weidian.com/item.html?itemID=905482571142028053079&wfr=wx&sfr=app&source=goods_home]休闲零食传承世家风干牛肉干 手撕风干牛肉四川特产【非偏远地区满79包邮】[/url]
[url=https://weidian.com/item.html?itemID=905482571142028053079&wfr=wx&sfr=app&source=goods_home][attach]2151[/attach][/url]

[url=https://weidian.com/item.html?itemID=905482571141828030433&wfr=wx&sfr=app&source=goods_home]长虹办公室鼠标加热保暖桌垫毯电脑暖手桌面发热板电热台板写字台[/url]
[url=https://weidian.com/item.html?itemID=905482571141828030433&wfr=wx&sfr=app&source=goods_home][attach]2149[/attach][/url]

[url=https://weidian.com/item.html?itemID=905482571141697401852&wfr=wx&sfr=app&source=goods_home]飞科电熨斗蒸汽家用熨斗家用电烫斗蒸气手持迷你电熨斗FI9308包邮[/url]
[url=https://weidian.com/item.html?itemID=905482571141697401852&wfr=wx&sfr=app&source=goods_home][attach]2153[/attach][/url]

[url=https://weidian.com/item.html?itemID=905482571142562276239&wfr=wx&sfr=app&source=goods_home]新款男长款拉链潮男士钱包男士手拿包 商务皮夹钱夹-JKPJ1806[/url]
[url=https://weidian.com/item.html?itemID=905482571142562276239&wfr=wx&sfr=app&source=goods_home][attach]2150[/attach][/url]

[url=https://weidian.com/item.html?itemID=905482571142001608813&wfr=wx&sfr=app&source=goods_home]韩版定型斜挎单肩手提包SN-两层活动女包8874[/url]
[url=https://weidian.com/item.html?itemID=905482571142001608813&wfr=wx&sfr=app&source=goods_home][attach]2152[/attach][/url]

页: [1]

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.