设为首页 收藏本站
查看: 1492|回复: 0

LNMP平台环境部署及应用

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-8-1 09:28:07 | 显示全部楼层 |阅读模式
                      目的:
(1)部署lnmp实现多个虚拟主机
(2)基于LNMP平台部署wordpress和phpmyadmin
(3)为其中一个主机提供https


环境:
192.168.1.104-------->nginx

192.168.1.110-------->php-fpm
192.168.1.113-------->mariadb


一、部署LNMP环境
nginx安装配置(192.168.1.104)
1、安装开发包组及依赖包
1
2
[iyunv@bogon nginx-1.10.0]# yum -y groupinstall Server Platform Development Development Tools
[iyunv@bogon nginx-1.10.0]# yum -y install pcre-devel openssl-devel zlib-devel



2、编译安装Nginx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
[iyunv@bogon ~]# tar xf nginx-1.10.0.tar.gz
[iyunv@bogon ~]# cd nginx-1.10.0/
[iyunv@bogon nginx-1.10.0]# ./configure
--prefix=/usr/local/nginx
--sbin-path=/usr/sbin/nginx
--conf-path=/etc/nginx/nginx.conf
--error-log-path=/var/log/nginx/error.log
--http-log-path=/var/log/nginx/access.log
--pid-path=/var/run/nginx.pid
--lock-path=/var/run/nginx.lock
--user=nginx
--group=nginx
--with-http_ssl_module
--with-http_v2_module
--with-http_dav_module
--with-http_stub_status_module
--with-stream_ssl_module
--with-threads
--with-file-aio
--with-http_realip_module
--with-http_addition_module
--with-http_sub_module
--with-http_flv_module
--with-http_mp4_module
--with-http_gunzip_module
--with-http_gzip_static_module
--with-http_random_index_module
--with-http_secure_link_module
--with-http_auth_request_module
--with-stream --with-http_slice_module
--http-client-body-temp-path=/var/cache/nginx/client_temp
--http-proxy-temp-path=/var/cache/nginx/proxy_temp
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp
--http-scgi-temp-path=/var/cache/nginx/scgi_temp

[iyunv@bogon nginx-1.10.0]# make -j 4 && make install





3、启动服务查看是否正常,此处需要注意用户是Nginx如果没人需要创建,否则服务无法启动。
1
2
3
[iyunv@bogon nginx-1.10.0]# useradd -r nginx ##创建nginx服务用户
[iyunv@bogon nginx-1.10.0]# mkdir -p /var/cache/nginx/client_temp##启动提示无此路径,创建即可
[iyunv@bogon nginx-1.10.0]# nginx ##启动服务





4、配置Nginx基于域名的虚拟主机
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
server {
        listen       80;
        server_name  www.magedu.com;

        location / {
            root   /web/host1;
            index  index.php index.html index.htm;
        }

        location ~ \.php$ {
            root           /web/host1;
            fastcgi_pass   192.168.1.110:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /web/host1/$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
     
     
     
server {
        listen       80;
        server_name  www.maweijun.com;

        location / {
            root   /web/host2;
            index  index.php index.html index.htm;
        }

        location ~ \.php$ {
            root           /web/host2;
            fastcgi_pass   192.168.1.110:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /web/host2/$fastcgi_script_name;
            include        fastcgi_params;
        }
    }





5、建立首页及其路径
1
2
3
4
5
[iyunv@bogon ~]# mkdir -p /web/host1
[iyunv@bogon ~]# mkdir -p /web/host2

[iyunv@bogon ~]# echo "host1" >/web/host1/index.html
[iyunv@bogon ~]# echo "host2" >/web/host2/index.html





6、检查配置文件是否正确,然后重新加载文件,测试即可
1
2
3
4
[iyunv@bogon ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[iyunv@bogon ~]# nginx -s reload





部署php-fpm服务(192.168.1.110)
1、安装php-fpm程序
1
2
3
[iyunv@pxe130 ~]# yum -y install php-fpm
[iyunv@pxe130 ~]# yum -y install php-mysql
[iyunv@pxe130 host2]# yum -y install php-mbstring





2、编辑主机配置文件,修改相关配置选项
1
2
3
[iyunv@pxe130 ~]# vim /etc/php-fpm.d/
listen = 192.168.1.110:9000   ###监听php-fpm能够与外部通信的地址
listen.allowed_clients = 192.168.1.104  ####允许的客户端主机,此处指httpd主机





3、启动服务
1
[iyunv@pxe130 ~]# systemctl start php-fpm.service





4、建立与httpd服务主机上相同的网页路径,测试php和httpd连接是否正常。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
[iyunv@bogon ~]# mkdir -p /web/host1
[iyunv@bogon ~]# mkdir -p /web/host2
[iyunv@pxe130 ~]# vim /web/host1/index.php

host1
<?php
$conn = mysql_connect('192.168.1.113','test','test');
        if ($conn)
                echo "mysql is ok";
        else
                echo "mysql is bad";
phpinfo();
?>
   
[iyunv@pxe130 ~]# vim /web/host1/index.php

host 2
<?php
$conn = mysql_connect('192.168.1.113','test','test');
        if ($conn)
                echo "mysql is ok";
        else
                echo "mysql is bad";
phpinfo();
?>




部署mariadb服务(192.168.1.113)
1、安装程序
1
2
[iyunv@pxe132 ~]# yum -y install mariadb-server
[iyunv@pxe132 ~]# systemctl start mariadb





2、授权用户,测试mariadb和php是否连接正常。
1
MariaDB [(none)]> grant all on test.* to 'test'@'192.168.%.%' identified by 'test';



1
2
3
4
5
MariaDB [(none)]> create database wpdb;####用于WordPress使用
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all on wpdb.* to 'wpuser'@'192.168.%.%' identified by 'wppass';
Query OK, 0 rows affected (0.00 sec)



1
2
3
4
5
MariaDB [(none)]> create database phpmyadmin;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all on phpmyadmin.* to 'phpuser'@'192.168.%.%' identified by 'phppass';
Query OK, 0 rows affected (0.00 sec)





3、测试
wKiom1ecxqGRM3_cAABjRSgRfSw081.jpg
wKioL1ecxqGjNxnKAABgFB5RQOg747.jpg


ok此时我们的LNMP环境就部署完成了。




二、基于LNMP平台部署WordPress和phpmyadmin应用


1、部署WordPress
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[iyunv@pxe130 ~]# unzip wordpress-4.3.1-zh_CN.zip
[iyunv@pxe130 ~]# mv wordpress /web/host1/
[iyunv@pxe130 ~]# cd /web/host1/WordPress
[iyunv@pxe130 wordpress]# cp wp-config-sample.php wp-config.php
[iyunv@pxe130 wordpress]# vim wp-config.php

/** WordPress数据库的名称 */
define('DB_NAME', 'wpdb');

/** MySQL数据库用户名 */
define('DB_USER', 'wpuser');

/** MySQL数据库密码 */
define('DB_PASSWORD', 'wppass');

/** MySQL主机 */
define('DB_HOST', '192.168.1.113');

/** 创建数据表时默认的文字编码 */
define('DB_CHARSET', 'utf8');



1
[iyunv@pxe130 host1]# scp -r wordpress/ root@192.168.1.104:/web/host1/   ###复制一份给httpd





2、部署phpmyadmin
1
2
3
4
5
6
7
8
9
[iyunv@pxe130 ~]# unzip phpMyAdmin-4.4.14.1-all-languages
[iyunv@pxe130 ~]# mv phpMyAdmin-4.4.14.1-all-languages /web/host2/phpmyadmin
[iyunv@pxe130 libraries]# cd phpmyadmin/libraries/
[iyunv@pxe130 libraries]# vim config.default.php

$cfg['blowfish_secret'] = 'Tfg6ORIzhZu/uA';
$cfg['Servers'][$i]['host'] = '192.168.1.113';
$cfg['Servers'][$i]['user'] = 'phpuser';
$cfg['Servers'][$i]['password'] = 'phppass';



1
[iyunv@pxe130 host2]# scp -r phpmyadmin/ root@192.168.1.104:/web/host2/







部署过程中phpmyadmin访问出现了session没有缓存,,此时只需要在/etc/php.ini中修改缓存路径,然后修改下权限就可了
1
2
3
4
session.save_path = "/var/lib/php/session"

[iyunv@pxe130 ~]# ll -d /var/lib/php/session/
drwxrwxrwx 2 root nginx 50 Jul 18 22:40 /var/lib/php/session/




wKiom1ec1X3jxblhAABTHZMyVfY719.jpg
wKioL1ec1X6h3glGAACe1lqig7o165.jpg

三、为其中一个站点设置为https方式访问
(1)建立CA

1
2
3
4
5
6
7
[iyunv@pxe130 CA]# (umask 077; openssl genrsa -out /etc/pki/CA/private/cakey.pem 2048)

[iyunv@pxe130 CA]# openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -out
/etc/pki/CA/cacert.pem -days 3655

[iyunv@pxe130 CA]# touch {serial,index.txt}
[iyunv@pxe130 CA]# echo 01> serial




(2)httpd服务生成密钥及生成请求证书

1
2
3
4
5
6
7
8
[iyunv@bogon ~]# mkdir /etc/nginx/ssl
[iyunv@bogon ~]# cd /etc/nginx/ssl/            
[iyunv@bogon ssl]# (umask 077;openssl genrsa -out /etc/nginx/ssl/nginx.key 2048)

[iyunv@bogon ssl]# openssl req -new -key /etc/nginx/ssl/nginx.key -out
/etc/nginx/ssl/nginx.csr -days 365
  
scp nginx.csr root@192.168.1.110:/




(3)CA上签署http证书申请:
1
2
3
[iyunv@pxe130 CA]# openssl ca -in /nginx.csr -out /etc/pki/CA/certs/nginx.crt -days 365

[iyunv@pxe130 certs]# scp nginx.crt root@192.168.1.104:/etc/nginx/ssl




(4)编辑httpd配置文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
server {
        listen       80;
        listen       443 ssl;   ###指定使用ssl,且监听443端口
        ssl_certificate  /etc/nginx/ssl/nginx.crt; ###指定公钥路径
        ssl_certificate_key  /etc/nginx/ssl/nginx.key; ###指定私钥路径
        server_name  www.maweijun.com;

        location / {
            root   /web/host2;
            index  index.php index.html index.htm;
        }

        location ~ \.php$ {
            root           /web/host2;
            fastcgi_pass   192.168.1.110:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /web/host2/$fastcgi_script_name;
            include        fastcgi_params;
        }
    }




(5)测试
wKioL1ec3emRYG-rAACz9cUjwlA560.jpg
                   


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-251657-1-1.html 上篇帖子: LNMP_PHP慢执行日志 下篇帖子: rpm包方式实现LNMP
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表