手机版
你好,游客 登录 注册
背景:
阅读新闻

CentOS下Nginx、Resin、Memcached整合

[日期:2012-03-11] 来源:Linux社区  作者:kerry [字体:大 中 小]

#添加启动脚本
vi /etc/init.d/nginx

  1. #! /bin/sh  
  2.    
  3. # Description: Startup script for webserver on CentOS. cp it in /etc/init.d and  
  4. # chkconfig --add nginx && chkconfig nginx on    
  5. # then you can use server command control nginx  
  6. #  
  7. # chkconfig: 2345 08 99  
  8. # description: Starts, stops nginx  
  9.    
  10. set -e  
  11.    
  12. PATH=$PATH:/usr/local/nginx/sbin/  
  13. DESC="nginx daemon" 
  14. NAME=nginx 
  15. DAEMON=/usr/local/nginx/sbin/$NAME  
  16. CONFIGFILE=/usr/local/nginx/conf/nginx.conf  
  17. PIDFILE=/usr/local/nginx/$NAME.pid  
  18. SCRIPTNAME=/etc/init.d/$NAME  
  19.    
  20. # Gracefully exit if the package has been removed.  
  21. test -x $DAEMON || exit 0  
  22.    
  23. d_start() {  
  24.   $DAEMON -c $CONFIGFILE || echo -n " already running"  
  25. }  
  26.    
  27. d_stop() {  
  28.   kill -QUIT `cat $PIDFILE` || echo -n " not running"  
  29. }  
  30.    
  31. d_reload() {  
  32.   kill -HUP `cat $PIDFILE` || echo -n " can't reload"  
  33. }  
  34.    
  35. case "$1" in  
  36.   start)  
  37.    echo -n "Starting $DESC: $NAME"  
  38.    d_start  
  39.    echo "."  
  40.  ;;  
  41.   stop)  
  42.    echo -n "Stopping $DESC: $NAME"  
  43.    d_stop  
  44.    echo "."  
  45.  ;;  
  46.   reload)  
  47.    echo -n "Reloading $DESC configuration..."  
  48.    d_reload  
  49.    echo "reloaded."  
  50.   ;;  
  51.   restart)  
  52.    echo -n "Restarting $DESC: $NAME"  
  53.    d_stop  
  54.    sleep 1  
  55.    d_start  
  56.    echo "."  
  57.  ;;  
  58.   *)  
  59.    echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2  
  60.    exit 3  
  61.  ;;  
  62. esac  
  63.    
  64. exit 0  

#将nginx添加到启动服务中
chmod 700 /etc/init.d/nginx
/etc/init.d/nginx start
/sbin/chkconfig --add nginx
/sbin/chkconfig --level 2345 nginx on

#---------------------------- 安装memcache ------------------------------#
cd /opt
tar -xzf libevent-2.0.11-stable.tar.gz
cd libevent-2.0.11-stable
./configure
make;make install
ln -s /usr/local/lib/libevent-2.0.so.5 /lib64/libevent-2.0.so.5

cd /opt
tar -xzf memcached-1.4.5.tar.gz
cd memcached-1.4.5
./configure --prefix=/usr/local/memcached --with-libevent=/usr
make;make install

#基本使用方法:
-l 监听的地址memcached 无身份验证功能,严禁在无防护
-p 监听的端口状态下,直接监听外网端口!!!默认11211
-d 以daemon 形式运行,一般皆需增加此参数
-u 以何用户身份运行,一般选nobody 等低权用户
-m 最大可用内存,以兆为单位
-c 最大的同时并发数,默认1024
-f 增长因子
-P PID 文件
启动:
/usr/local/memcached/bin/memcached -d -m 1024 -p 11211 -u www -c 4096
关闭:
killall -9 memcached

#开面启动
echo "/usr/local/memcached/bin/memcached -d -m 1024 -p 11211 -u www -c 4096" >> /etc/rc.local

#---------------------------- nginx、resin整合 -------------------------#
#将resin的默认目录与nginx的目录相同
vi /usr/local/resin/conf/resin.xml
将

  1. <host id="" root-directory="."> 
  2.   <!--  
  3.      - webapps can be overridden/extended in the resin.xml  
  4.     --> 
  5.   <web-app id="/" root-directory="webapps/ROOT"/> 


修改成:
 

  1. <host id="" root-directory="."> 
  2.   <!--  
  3.      - webapps can be overridden/extended in the resin.xml  
  4.     --> 
  5.   <web-app id="/" root-directory="/data/www/web001"/> 

#创建一个测试文件
vi /data/www/web001/index.jsp
2 + 2 = <%= 2 + 2 %>

#重启nginx、resin
/etc/init.d/nginx restart
/etc/init.d/resin restart

#访问http://www.linuxidc.com 如果看到2 + 2 = 4,就证明nginx、resin整合成功

linux
相关资讯       Nginx  CentOS教程 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款