很多人在练习部署LNMP环境的时候,大都数是部署在同一个虚拟机上面的。但是实际工作中,我们一般都是分离部署的。

今天我就用3台虚拟机,部署下LNMP环境。以供参考!

网络拓扑图:

首先准备3台虚拟机:

nginx:192.168.1.214

php:192.168.1.202

mysql:192.168.1.217

首先安装ngix(192.168.1.214):

1
2
3
4
5
6
7
8
9
10
11
12
13
 #解决依赖
 
  yum install -y gcc,openssl-devel,pcre-devel,zilb-devel  pcre-devel
 
    
 
 #关闭防火墙和修改selinux
 
   service iptables stop
 
   chkconfig iptables off
 
   sed -i's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
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
 #添加一个nginx用户
  [root@nginx ~]# groupadd -g 108 -r nginx
  [root@nginx ~]# useradd -u 108 -r -g 108 nginx
  [root@nginx ~]# tar zxvf nginx-1.6.0.tar.gz
  [root@nginx ~]# cd nginx-1.6.0
  [root@nginx ~]# ./configure   
--prefix=/usr/local/  
--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/nginx.pid/    
--lock-path=/var/lock/nginx.lock/  
--user=nginx/   
--group=nginx/  
--with-http_ssl_module/    
--with-http_flv_module/  
--with-http_stub_status_module/  
--with-http_gzip_static_module/  
--http-client-body-temp-path=/var/tmp/nginx/client/   
--http-proxy-temp-path=/var/tmp/nginx/proxy/   
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/   
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi/   
--http-scgi-temp-path=/var/tmp/nginx/scgi/  
--with-pcre
  make && make install

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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
[root@nginx ~]# cat /etc/init.d/nginx
#!/bin/sh 
# config:      /etc/nginx/nginx.conf 
# config:      /etc/sysconfig/nginx 
# pidfile:     /var/run/nginx.pid 
# Check that networking is up. 
"$NETWORKING" "no" ] && exit 
nginx="/usr/sbin/nginx" 
prog=$(basename $nginx) 
NGINX_CONF_FILE="/etc/nginx/nginx.conf" 
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx 
lockfile=/var/lock/subsys/nginx 
make_dirs() { 
   # make required directories 
   user=`nginx -V 2>&1 | grep "configure arguments:" sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -` 
   options=`$nginx -V 2>&1 | grep 'configure arguments:'
   for opt in $options; do 
       if [ `echo $opt | grep '.*-temp-path'` ]; then 
           value=`echo $opt | cut -d "=" -f 2` 
           if [ ! -d "$value" ]; then 
               # echo "creating" $value 
               mkdir -p $value && chown -R $user $value 
           fi 
       fi 
   done 
start() { 
    [ -x $nginx ] || exit 
    [ -f $NGINX_CONF_FILE ] || exit 
    make_dirs 
    echo -n $"Starting $prog: " 
    daemon $nginx -c $NGINX_CONF_FILE 
    retval=$? 
    echo 
    [ $retval -eq 0 ] && touch $lockfile 
    return $retval 
stop() { 
    echo -n $"Stopping $prog: " 
    killproc $prog -QUIT 
    retval=$? 
    echo 
    [ $retval -eq 0 ] && rm -f $lockfile 
    return $retval 
restart() { 
    configtest || return $? 
    stop 
    sleep 
    start 
reload() { 
    configtest || return $? 
    echo -n $"Reloading $prog: " 
    killproc $nginx -HUP 
    RETVAL=$? 
    echo 
force_reload() { 
    restart 
configtest() { 
  $nginx -t -c $NGINX_CONF_FILE 
rh_status() { 
    status $prog 
rh_status_q() { 
    rh_status >/dev/null 2>&1 
case "$1" in 
    start) 
        rh_status_q && exit 
        $1 
        ;; 
    stop) 
        rh_status_q || exit 
        $1 
        ;; 
    restart|configtest) 
        $1 
        ;; 
    reload) 
        rh_status_q || exit 
        $1 
        ;; 
    force-reload) 
        force_reload 
        ;; 
    status) 
        rh_status 
        ;; 
    condrestart|try-restart) 
        rh_status_q || exit 
            ;; 
    *) 
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" 
        exit 
esac

添加执行权限:

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@nginx ~]# chmod +x /etc/init.d/nginx
#添加脚本到开机启动项
[root@nginx ~]# chkconfig --add nginx
[root@nginx ~]# chkconfig nginx on 
[root@nginx ~]# chkconfig nginx --list 
nginx              0:关闭    1:关闭    2:启用    3:启用    4:启用    5:启用    6:关闭
#启动nginx
[root@nginx ~]# service nginx start
正在启动 nginx:                                           [确定]
#查看端口是否正常
[root@nginx ~]# netstat -ntlp | grep :80
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      3889/nginx
# Nginx安装与配置完毕

#安装MySQL(192.168.1.217)

#注意:这里是直接解压MySQL的

1
2
3
4
#添加MySQL用户
[root@localhost ~]#groupadd -r mysql
[root@localhost ~]#useradd -r -g mysql -s
[root@localhost ~]#/sbin/nologin mysql
1
2
3
4
5
6
7
#解压到指定路径
[root@localhost ~]#tar xf mysql-5.5.33-linux2.6-x86_64.tar.gz -C /usr/local/
[root@localhost ~]#cd /usr/local/
[root@localhost ~]#ln -sv /usr/local/mysql-5.5.33-linux2.6-x86_64/ /usr/local/mysql
`/usr/local/mysql' -> `/usr/local/mysql-5.5.33-linux2.6-x86_64/'
[root@localhost ~]#cd mysql
[root@localhost ~]#chown -R root.mysql *
1
2
3
4
5
6
#初始化数据库;并指定其用户和data目录
scripts/mysql_install_db --user=mysql--datadir=/Mysql/data
ls /Mysql/data/
lost+found  mysql 
mysql-bin.000001  mysql-bin.000002  mysql-bin.index 
performance_schema  test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#没有报错并生成以上文件即可
cp support-files/my-large.cnf /etc/my.cnf 配置一个配置文件
vi /etc/my.cnf   更改已下配置选项;具体选项根据自己需要配置
# The MySQL server
[mysqld]
port            = 3306
socket          = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
# Try number of CPU's*2 for
thread_concurrency
thread_concurrency = 4
datadir = /Mysql/data 新增一行
1
2
3
4
5
6
7
8
9
10
11
12
#提供一个服务脚本
cp support-files/mysql.server
/etc/rc.d/init.d/mysqld
chmod +x /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
chkconfig --list mysqld
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off
service mysqld start
Starting
MySQL...                                         
[  OK  ]
1
2
3
4
5
6
#用mysql命令启动成功后错误信息
vi /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
ln -sv /usr/local/mysql/include/ /usr/include/mysql
`/usr/include/mysql' ->`/usr/local/mysql/include/'
vi /etc/man.config
1
2
3
4
5
6
7
8
9
定位到MANPATH
MANPATH /usr/man
MANPATH /usr/share/man
MANPATH /usr/local/man
MANPATH /usr/local/share/man
MANPATH /usr/X11R6/man
MANPATH /usr/local/mysql/man #添加一行
echo /usr/local/mysql/lib/ >
/etc/ld.so.conf.d/mysql.conf

#若是想要编译安装MySQL可以参考我之前的文章:

http://liangey.blog.51cto.com/9097868/1626945

安装PHP

1
yum install zlib libxml libjpegfreetype gd curl libiconv zlib-devel libxml2-devel libjpeg-devel freetype-devellibpng-devel gd-devel curl-devel libmcrypt-devel  libxslt* bzip2* -y
1
2
3
4
5
6
7
8
9
10
11
#添加nginx用户
useradd nginx 
#安装libiconv-1.14库
tar zxvf libiconv-1.14.tar.gz 
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
echo $?
make 
echo $?
make install
echo $?
1
2
3
4
5
6
#安装libmcrypt-2.5.8.tar.gz库
tar zxvflibmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make
make install
1
2
3
4
5
6
#安装mhash-0.9.9.9
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure
make
make install
1
2
3
4
5
6
7
#安装mcrypt
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
/sbin/ldconfig
./configureLD_LIBRARY_PATH=/usr/local/lib
make
make install
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
38
39
tar zxvf php-5.3.27.tar.gz
cd php-5.3.27
./configure--prefix=/application/php5.3.27 
--with-mysqli=mysqlnd /
--with-pdo-mysql=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-safe-mode/ 
--enable-bcmath/ 
--enable-shmop /
--enable-sysvsem/
--enable-inline-optimization /
--with-curl /
--with-curlwrappers /
--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-zend-multibyte /
--enable-static /
--with-xsl/
--enable-ftp
make && make install
1
2
3
#若make出错
/home/tools/php-5.3.27/sapi/cli/php:error while loading shared libraries: libmysqlclient.so.18: cannot open sharedobject file: No such file or directory
make: *** [ext/phar/phar.php] 错误 127
1
2
3
4
5
#解决方法
ln -s/application/mysql/lib/libmysqlclient.so.18 /usr/lib64/
make
make install
ln -s /application/php5.3.27//application/php
1
2
3
4
5
6
7
8
9
#配置PHP
cp php.ini-production /application/php/lib/php.ini
cd /application/php/etc/
 
vim php-fpm.conf
#修改如下:
user = nginx
group = nginx
listen = 192.168.1.202:9000
1
2
3
4
#启动php-fpm
 /etc/init.d/php-fpm start
 netstat -lntup|grep 9000
tcp        0      0 192.168.1.202:9000          0.0.0.0:*                   LISTEN      1422/php-fpm

#整合Nginx和PHP

#这里是在Nginx(192.168.1.214)下操作:

1
2
3
4
5
6
7
8
9
10
11
12
vim /etc/nginx/nginx.conf
  location / {
            root   /www;  #更改目录
            index  index.php index.html index.htm;  #添加一个index.php
        }
  location ~ \.php$ {
            root           /www;#更改目录
            fastcgi_pass   192.168.1.202:9000;  #这里为PHP服务器的地址
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi_params;
        }
1
2
3
vim /etc/nginx/fastcgi_params
#添加以下这行:
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
1
2
3
4
5
6
7
8
#创建一个/www目录,并且创建一个test.php文件
 mkdir /www
 chown nginx:nginx /www/
 cd /www
 vim test.php
 <?php
 phpinfo();
 ?>

#注意:这里先不要重启nginx

#以下操作是在PHP:192.168.1.202中进行

1
2
3
4
5
6
7
mdkir /www
chown -R nginx:nginx /www/
cd /www/
vim test.php
<?php
phpinfo();
?>
1
2
#重启php-fpm
/etc/init.d/php-fpm restart
1
2
#在nginx中重启nginx服务
 /etc/init.d/nginx restart

在浏览器中输入:192.168.1.214/test.php

出现以下页面,证明nginx和php整合成功了!

#最后是创建一个wordpress站点

1
2
3
4
5
6
7
8
创建站点,首先我们的nginx必须要跟MySQL是互通的。现在我们先在MySQL下授权nginx这台服务器能够访问数据库:
#这里是在MySQL(192.168.1.217)下操作的:
mysql -uroot -proot 登陆数据库
#创建一个数据库
mysql> create database wp;
mysql> use wp;
mysql> grant all privileges on wp.* to 'wpuser'@'192.168.1.%' identified by '123456';
mysql> flush privileges;
1
2
3
#在nginx的/www目录下面解压wordpress-4.1-zh_CN.tar.gz
 [root@localhost www]#tar zxvf wordpress-4.1-zh_CN.tar.gz 
 [root@localhost www]#cp -r wordpress/* .
1
2
3
4
#在php的/www目录下面解压
wordpress-4.1-zh_CN.tar.gz
 [root@localhost www]#tar zxvf wordpress-4.1-zh_CN.tar.gz 
 [root@localhost www]#cp -r wordpress/* .
1
2
3
4
#重启nginx服务和php-fpm服务
 /etc/init.d/nginx restart
  
 /etc/init.d/php-fpm restart

#浏览器中输入:192.168.1.214,会出现设置的页面

本文出自 “9527” 博客,请务必保留此出处http://liangey.blog.51cto.com/9097868/1630038

LNMP分离式部署实例[转]的更多相关文章

  1. Linux系统——LNMP分离式部署

    #### 安装nginx ```[root@localhost ~]# tar xf nginx-1.10.2.tar.gz -C /usr/src/[root@localhost ~]# cd /u ...

  2. LNMP分离式部署

    #### LNMP组合工作流程 在LNMP组合工作时,首先是用户通过浏览器输入域名请求Nginx Web服务,如果请求是静态资源,则由Nginx解析返回给用户:如果是动态请求(.php结尾),那么Ng ...

  3. 企业级LNMP分离式部署

    安装MySQL数据库   安装步骤介绍 本例采用MySQL二进制安装包进行安装演示 (1) 创建mysql用户的账号   [root@mysql ~]# groupadd mysql [root@my ...

  4. Solr 4.0 部署实例教程

    Solr 4.0 部署实例教程 Solr 4.0的入门基础教程,先说一点部署之后肯定会有人用solrj,solr 4.0好像添加了不少东西,其中CommonsHttpSolrServer这个类改名为H ...

  5. SQL Server 2008 数据库镜像部署实例之三 配置见证服务器

    SQL Server 2008 数据库镜像部署实例之三 配置见证服务器 前面已经完成了镜像数据库的配置,并进行那个了故障转移测试.接下来将部署见证服务器,实现自动故障转移. 一.关于见证服务器 1.若 ...

  6. SQL Server 2008 数据库镜像部署实例之二 配置镜像,实施手动故障转移

    SQL Server 2008 数据库镜像部署实例之二 配置镜像,实施手动故障转移 上一篇文章已经为配置镜像数据库做好了准备,接下来就要进入真正的配置阶段 一.在镜像数据库服务器上设置安全性并启动数据 ...

  7. SQL Server 2008 数据库镜像部署实例之一 数据库准备

    SQL Server 2008 数据库镜像部署实例之一 数据库准备 一.目标 利用Sql Server 2008 enterprise X64,建立异步(高性能)镜像数据库,同时建立见证服务器实现自动 ...

  8. LNMP架构部署

    第1章 部署LNMP架构步骤 1.1 ①部署Linux系统(OK) 基本优化完成(ip地址设置 yum源更新 字符集设置) 安全优化完成(iptables关闭 selinux关闭 /tmp/ 1777 ...

  9. Puppet基于Master/Agent模式实现LNMP平台部署

    前言 随着IT行业的迅猛发展,传统的运维方式靠大量人力比较吃力,运维人员面对日益增长的服务器和运维工作,不得不把很多重复的.繁琐的工作利用自动化处理.前期我们介绍了运维自动化工具ansible的简单应 ...

随机推荐

  1. JAVA-开发IDE版本

    Eclipse发布的完整列表包括: Neon, June 22, 2016 Mars, June 24, 2015 Luna, June 25, 2014 Kepler, June 26, 2013 ...

  2. Mysql 使用Group 和Case When统计数据

    项目是基于:thinkcmf的,新的需求是对各栏目的文章数量进行统计 SQl很简单,先根据分类ID进行分组,然后再通过CASE WHEN 再统计不同文章状态数量 ) as count , =已审核 , ...

  3. jQuery 图片裁剪插件 Jcrop

    Jcrop是一个jQuery图片裁剪插件,它能为你的WEB应用程序快速简单地提供图片裁剪的功能.特点如下: 对所有图片均unobtrusively(无侵入的,保持DOM简洁) 支持宽高比例锁定 支持 ...

  4. Mybatis源码分析之Mapper执行SQL过程(三)

    上两篇已经讲解了SqlSessionFactory的创建和SqlSession创建过程.今天我们来分析myabtis的sql是如何一步一步走到Excutor. 还是之前的demo    public  ...

  5. iOS开发点滴 - 关闭键盘

    有时候系统显示的键盘会挡住视图中某些重要的控件,这个时候当用户按下换行键,就应该取消UITextField对象的第一响应(First Responder)状态而关闭键盘. 1. 首先,视图控制器必须遵 ...

  6. PHP 字符串编码的转换

    原文链接:http://mangguo.org/php-string-encoding-convert-and-detect/ GBK 和 UTF-8 编码的转换是一个非常恶心的事情,比如像 PHP ...

  7. SQL字符串分割解析

    常用以下三种: [1]substring( expression ,start , length ): [2]CHARINDEX ( expression1 , expression2 [ , sta ...

  8. MySql安装完成后设置远程访问的角本

    一.方法: 登陆安装Mysql的机器的Mysql, 执行: GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password001!' ...

  9. httpclient Accept-Encoding 乱码

    解决方法 HttpEntity httpEntity = httpResponse.getEntity(); if (httpEntity != null) { if (httpEntity.getC ...

  10. C语言之函数调用06—彩球排列

    //函数调用+递归法 /* ========================================================== 题目:将4个红球,3个白球.3个黄球排成一排,共同拥有 ...