1、下载OpenResty和Redis
OpenResty下载地址:wget http://openresty.org/download/ngx_openresty-1.4.3.6.tar.gz
Redis下载地址:wget http://download.redis.io/releases/redis-2.8.6.tar.gz
2、安装依赖包
yum install -y gcc gcc-c++ readline-devel pcre-devel openssl-devel tcl
3、安装OpenResty
tar zxvf ngx_openresty-1.4.3.6.tar.gz cd ngx_openresty-1.4.3.6 ./configure make make install
lua和redis等相关模块就已经安装完成,利用下面命令查看。
/usr/local/openresty/nginx/sbin/nginx -V
设置Nginx为服务和开机启动
vi /etc/rc.d/init.d/nginx
#!/bin/bash # Tengine Startup script# processname: nginx # chkconfig: - 85 15 # description: nginx is a World Wide Web server. It is used to serve # pidfile: /var/run/nginx.pid # config: /usr/local/nginx/conf/nginx.conf nginxd=/usr/local/openresty/nginx/sbin/nginx nginx_config=/usr/local/openresty/nginx/conf/nginx.conf nginx_pid=/usr/local/openresty/nginx/logs/nginx.pid RETVAL=0 prog="nginx" # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ ${NETWORKING} = "no" ] && exit 0 [ -x $nginxd ] || exit 0 # Start nginx daemons functions. start() { if [ -e $nginx_pid ];then echo "tengine already running...." exit 1 fi echo -n $"Starting $prog: " daemon $nginxd -c ${nginx_config} RETVAL=$? echo [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx return $RETVAL } # Stop nginx daemons functions. stop() { echo -n $"Stopping $prog: " killproc $nginxd RETVAL=$? echo [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid } reload() { echo -n $"Reloading $prog: " #kill -HUP `cat ${nginx_pid}` killproc $nginxd -HUP RETVAL=$? echo } # See how we were called. case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) stop start ;; status) status $prog RETVAL=$? ;; *) echo $"Usage: $prog {start|stop|restart|reload|status|help}" exit 1 esac exit $RETVAL
保存退出
chmod 775 /etc/rc.d/init.d/nginx #赋予文件执行权限 chkconfig --level 012345 nginx on #设置开机启动 service nginx start
4、安装Redis
tar zxvf redis-2.6.14.tar.gz mv redis-2.6.14 redis cd redis make make install
设置Redis的配置文件
vi /usr/local/redis/redis.conf
#是否作为守护进程运行 daemonize yes #如以后台进程运行,则需指定一个pid,默认为/var/run/redis.pid pidfile redis.pid #绑定主机IP,默认值为127.0.0.1 #bind 127.0.0.1 #Redis默认监听端口 port 6379 #客户端闲置多少秒后,断开连接,默认为300(秒) timeout 300 #日志记录等级,有4个可选值,debug,verbose(默认值),notice,warning loglevel verbose #指定日志输出的文件名,默认值为stdout,也可设为/dev/null屏蔽日志 logfile stdout #可用数据库数,默认值为16,默认数据库为0 databases 16 #保存数据到disk的策略 #当有一条Keys数据被改变是,900秒刷新到disk一次 save 900 1 #当有10条Keys数据被改变时,300秒刷新到disk一次 save 300 10 #当有1w条keys数据被改变时,60秒刷新到disk一次 save 60 10000 #当dump .rdb数据库的时候是否压缩数据对象 rdbcompression yes #本地数据库文件名,默认值为dump.rdb dbfilename dump.rdb #本地数据库存放路径,默认值为 ./ dir /var/lib/redis/
调整内存分配策略
vi /proc/sys/vm/overcommit_memory
CentOS6.4 安装OpenResty和Redis 并在Nginx中利用lua简单读取Redis数据
原文:http://www.cnblogs.com/kgdxpr/p/3550633.html