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

搭建完全分离式LNMP平台的简单案例

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-10-15 08:42:06 | 显示全部楼层 |阅读模式
案例拓扑图

wKioL1Q9NNyDOYpoAADB-wCoxsg241.jpg
安装配置nginx服务器

编译安装nginx时,需要事先安装 开发包组"Development Tools"和"Server Platform Development",同时还需专门安装pcre-devel包。
1
2
3
# yum -y groupinstall "Development Tools"
# yum -y groupinstall "Server Platform Development"
# yum -y install pcre-devel



首先添加nginx用户组和nginx用户

1
2
# groupadd -r nginx
# useradd -g nginx -r nginx



创建编译安装是所需要的目录
1
# mkdir -pv /var/tmp/nginx/client



编译安装nginx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# tar xf nginx-1.4.7.tar.gz
# cd nginx-1.4.7
# ./configure
  --prefix=/usr/local/nginx
  --sbin-path=/usr/local/nginx/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提供SysV init脚本
1
# vim /etc/rc.d/init.d/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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig:   - 85 15
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /etc/nginx/nginx.conf
# config:      /etc/sysconfig/nginx
# pidfile:     /var/run/nginx.pid
  
# Source function library.
. /etc/rc.d/init.d/functions
  
# Source networking configuration.
. /etc/sysconfig/network
  
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
  
nginx="/usr/local/nginx/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=([^ ]*).*//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 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    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 1
    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 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac



为此脚本赋予执行权限
1
# chmod +x /etc/rc.d/init.d/nginx



将nginx服务添加至服务管理列表,并让其开机自动启动
1
2
# chkconfig --add nginx
# chkconfig nginx on



编辑配置文件/etc/nginx/nginx.conf,在server段内添加如下内容
1
2
3
4
5
6
location ~ .php$ {
    fastcgi_pass   10.170.2.90:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /var/www/html$fastcgi_script_name;
    include        fastcgi_params;
}



启动nginx服务
1
# vim /etc/init.d/nginx start



测试nginx是否工作起来,在浏览器中键入10.170.2.80,可以得到如下页面
wKioL1Q9LSiw-gBgAAG9vqavcsc123.jpg

安装PHP服务器

编译安装php
1
2
3
4
# tar xf php-5.4.26.tar.bz2
# cd php-5.4.26
# ./configure --prefix=/usr/local/php5 --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --enable-fpm --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2
# make && make install



为php提供配置文件
1
# cp php.ini-production /etc/php.ini



配置php-fpm
1
2
3
4
5
# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
# chmod +x /etc/rc.d/init.d/php-fpm
# chkconfig --add php-fpm
# chkconfig php-fpm on
# cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf



编辑配置文件/usr/local/php5/etc/php-fpm.conf,将以下选项修改为相对应的值
1
2
3
4
5
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8
pid = /usr/local/php5/var/run/php-fpm.pid



在/var/www/html目录下提供测试页面index.php,其内容为
1
2
3
4
5
6
7
8
9
10
11
hello,nginx
        $link = mysql_connect('10.170.2.36','testuser','******');
        if ($link)
                echo "Success...";
        else
                echo "Failure...";

        mysql_close();
        phpinfo();
?>



启动php-fpm服务
1
# /etc/init.d/php-fpm start



测试nginx服务器与php服务器是否能够建立通信,在浏览器中键入10.170.2.80/index.php,可以得到如下页面
wKioL1Q9M63ijdb-AAI2nNDl8qs444.jpg
页面中显示Failure...,是因为后端的数据库还没有进行相应的配置

安装MariaDB服务器

编译安装mariadb-5.5.36
1
2
3
4
5
6
7
8
# tar xf mariadb-5.5.36-linux-x86_64.tar.gz -C /usr/local
# cd /usr/local/
# ln -sv mariadb-5.5.36-linux-x86_64/ mysql
# mkdir -pv /mysql/data
# groupadd -r mysql
# useradd -g mysql -s /sbin/nologin -M -d /mysql/data -r mysql
# chown -R mysql:mysql /mysql
# chown -R mysql:mysql /mysql/data



为数据库提供配置文件:
1
2
3
4
5
6
# cd mysql
# mkdir /etc/mysql
# chown -R root.mysql ./*
# cp support-files/my-large.cnf /etc/mysql/my.cnf
修改文件/etc/mysql/my.cnf文件内容,在thread_concurrency = 8行下添加一行:
datadir = /mysql/data



为数据库提供SysV启动脚本,并设置为开机启动:
1
2
3
# cp support-files/mysql.server /etc/init.d/mysqld
# chkconfig --add mysqld
# chkconfig mysqld on



初始化数据库并启动数据库:
1
2
3
4
5
6
7
# echo "export PATH=/usr/local/mysql/bin:$PATH" > /etc/profile.d/mysql.sh
# source /etc/profile.d/mysql.sh
# echo "/usr/local/mysql/lib" > /etc/ld.so.conf.d/mysql.conf
# ldconfig
# ln -sv /usr/local/mysql/include/ /usr/include/mysql
# scripts/mysql_install_db --user=mysql --datadir=/mysql/data/
# /etc/init.d/mysqld start



创建数据库并授权:
1
2
3
MariaDB [(none)]> CREATE DATABASE testdb;
MariaDB [(none)]> GRANT ALL ON testdb.* TO dscuser@'10.170.2.%' IDENTIFIED BY '******';
MariaDB [(none)]> FLUSH PRIVILEGES;



整体测试LNMP平台

在浏览器中键入10.170.2.80/index.php,可以得到如下页面
wKioL1Q9ND6RPJbOAAI3E1x54NM883.jpg
这次可以看到页面中显示Success...信息


运维网声明 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-26038-1-1.html 上篇帖子: centos 6.5 编译安装 httpd-2.4.10 下篇帖子: linux+php+apache+mysql+vsftp
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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