lnmp基于fastcgi实现nginx_php_mysql的分离_LNMP基于FastCGI实现Nginx,PHP,MySQL的分离
LNMP基于FastCGI实现Nginx,PHP,MySQL的分离
[日期:2012-11-12]
来源:Linux社区
作者:laoguang
[字体:大 中 小]
平时安装LNMP是把它们安装到同一台机器上,我想这个对大家来说丝毫没有挑战,下面我们实现把他们剥离到不同的机器上,让各个服务器直接分担原来的压力,也可以增加节点实现负载均衡,如:多增加一台php,让两台机器轮询的编译php,也可以在增加一台nginx,实现dns的轮询负载均衡。
规划:nginx:172.16.1.1
php(FASTCGI):172.16.1.2
MySQL:172.16.1.3
环境:RedHat 5.8 32位,yum可以正常使用,开发包组"Development Tools" "Development Libraries" "X Software Development"已经安装好,如果没有请先安装。SElinux确保已经关闭,iptables先关闭之。
操作步骤:
一.在172.16.1.1编译安装nginx
1.先安装pcre-devel,nginx的rewrite功能依赖pcre提供的库。
# yum -y install pcre-devel
2.为nginx建立用户,实现安全运行,指定uid的原因是为了与php通过nfs共享时权限方便
# groupadd -r -g 5000 nginx
# useradd -r -g nginx -u 5000 nginx
3.下载并编译安装nginx
# wget http://www.nginx.org/download/nginx-1.2.4.tar.gz
# tar xvf nginx-1.2.4.tar.gz
# cd nginx-1.2.4
#./configure \
--prefix=/usr \
--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
##各个选项意思就不讲解了,如果需要理解,请找google吧
# make && make install
4.为nginx提供SysV init脚本
新建文件/etc/rc.d/init.d/nginx,内容如下:
#!/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/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 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
为此脚本赋予执行权限:
# chmod +x /etc/rc.d/init.d/nginx
添加至服务管理列表,并让其开机自动启动:
# chkconfig --add nginx
# chkconfig nginx on
启动服务并测试
# service nginx start
直接访问172.16.1.1查看是否有nginx的欢迎信息,如果有代表nginx安装一切正常。
lnmp基于fastcgi实现nginx_php_mysql的分离_LNMP基于FastCGI实现Nginx,PHP,MySQL的分离相关推荐
- lnmp基于fastcgi实现nginx_php_mysql的分离_LNMP基于FastCGI实现Nginx,PHP,MySQL的架构分离...
架构图: 运行原理: 用户通过Ngsvr调度器访问wordpress,Ngsvr服务器会根据调度算法把请求负载均衡调度至Usvr1和Usvr2.并通过fastcgi协议与Usvr1.Usvr2通信返回 ...
- mysql配置读写分离无效_MySQL数据库的同步配置+MySql 读写分离
MySQL数据库的同步. MySQL是开源的关系型数据库系统.主从同步复制(Replication)是从一台MySQL数据库服务器(主服务器master)复制数据到另一个服务器(从服务器slave)的 ...
- mysql读写分离 同步_MySQL数据库的同步配置+MySql读写分离
使用mysql主从复制的好处有: 1.采用主从服务器这种架构,稳定性得以提升.如果主服务器发生故障,我们可以使用从服务器来提供服务. 2.在主从服务器上分开处理用户的请求,可以提升数据处理效率. 3. ...
- 基于Ameoba实现mysql读写分离
一.Amoeba介绍 Amoeba:基于Java研发,配置文件xml文档.对事务支持功能很差,不支持分布式读,尤其不支持分布式事务.默认监听在8066端口上.2.2.x开始支持单库事务,没有缓存功能, ...
- 基于mycat的mysql_基于Mycat中间件的MySQL读写分离
基于Mycat中间件的MySQL读写分离 简述 mycat是国内开源的数据库中间件,可以实现mysql读写分离和主备热切换,容灾,数据分片等功能. 详情:http://www.mycat.io/ 架构 ...
- 基于SpringBoot,来实现MySQL读写分离技术
作者:Yrion cnblogs.com/wyq178/p/13352707.html 前言 首先思考一个问题:在高并发的场景中,关于数据库都有哪些优化的手段?常用的有以下的实现方法:读写分离.加缓存 ...
- solidworks批量图号分离_SolidWorks2014基于宏实现快速图号名称分离.docx
SolidWorks2014基于宏实现快速图号名称分离 SolidWorks2014基于宏实现快速"图号名称"分离 当我们创建好一个Solidworks 零件以后,为了更快速把零件 ...
- 【论文精读】基于周期编码深度自编码器的心肺音盲单耳声源分离
文章信息 Blind Monaural Source Separation on Heart and Lung Sounds Based on Periodic-Coded Deep Autoenco ...
- 基于codesys开发的多轴运动控制程序框架,将逻辑与运动控制分离,将单轴控制封装成功能块,对该功能块的操作包含了所有的单轴控制
基于codesys开发的多轴运动控制程序框架,将逻辑与运动控制分离,将单轴控制封装成功能块,对该功能块的操作包含了所有的单轴控制(归零.点动.相对定位.绝对定位.设置当前位置.伺服模式切换等等). 程 ...
最新文章
- sql sever 中如何查看某个表的索引_查看执行计划:explain的type
- IDEA下用SBT搭建Spark Helloworld
- 关于MSSQL数据存储的问题
- Jira filter subscribe issues
- [转]Java7中的ForkJoin并发框架初探(上)——需求背景和设计原理
- scala初学之函数定义、流程控制、异常处理入门
- 添加谷歌翻译到你的网站
- ACE网络编程思考(二)
- 2016年CIO的五个优先级
- 服务器(Windows系统)自建蚂蚁(leanote)笔记超详细步骤(包含数据备份和数据还原)
- 崛起于Springboot2.X之集成单机Redis(14)
- oracle 12cora 03113,Oracle12.2 ORA-03113
- php微信 消息推送 配置,PHP微信公众号模板消息推送
- word文档中在文字的右上角加标注快捷键
- C语言中ret的作用,c-RET抑制剂 | c-RET Inhibitor
- (八)博客详情页面(内容排版typo.css)插件集成
- python 模拟键盘 linux,在Linux中使用Python模拟键盘按键,linuxpython
- 页面地址index.html,分析首页链接:/和/index.html
- 芝麻信用网页api php,谈谈php对接芝麻信用踩的坑
- 开机时间分析工具WPT Xperf使用