#添加启动脚本
vi /etc/init.d/nginx
- #! /bin/sh
- # Description: Startup script for webserver on CentOS. cp it in /etc/init.d and
- # chkconfig --add nginx && chkconfig nginx on
- # then you can use server command control nginx
- #
- # chkconfig: 2345 08 99
- # description: Starts, stops nginx
- set -e
- PATH=$PATH:/usr/local/nginx/sbin/
- DESC="nginx daemon"
- NAME=nginx
- DAEMON=/usr/local/nginx/sbin/$NAME
- CONFIGFILE=/usr/local/nginx/conf/nginx.conf
- PIDFILE=/usr/local/nginx/$NAME.pid
- SCRIPTNAME=/etc/init.d/$NAME
- # Gracefully exit if the package has been removed.
- test -x $DAEMON || exit 0
- d_start() {
- $DAEMON -c $CONFIGFILE || echo -n " already running"
- }
- d_stop() {
- kill -QUIT `cat $PIDFILE` || echo -n " not running"
- }
- d_reload() {
- kill -HUP `cat $PIDFILE` || echo -n " can't reload"
- }
- case "$1" in
- start)
- echo -n "Starting $DESC: $NAME"
- d_start
- echo "."
- ;;
- stop)
- echo -n "Stopping $DESC: $NAME"
- d_stop
- echo "."
- ;;
- reload)
- echo -n "Reloading $DESC configuration..."
- d_reload
- echo "reloaded."
- ;;
- restart)
- echo -n "Restarting $DESC: $NAME"
- d_stop
- sleep 1
- d_start
- echo "."
- ;;
- *)
- echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
- exit 3
- ;;
- esac
- 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
将
- <host id="" root-directory=".">
- <!--
- - webapps can be overridden/extended in the resin.xml
- -->
- <web-app id="/" root-directory="webapps/ROOT"/>
修改成:
- <host id="" root-directory=".">
- <!--
- - webapps can be overridden/extended in the resin.xml
- -->
- <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整合成功
