首页 > 其他 > 详细

CentOS6.4 安装OpenResty和Redis 并在Nginx中利用lua简单读取Redis数据

时间:2014-02-15 20:37:37      阅读:719      评论:0      收藏:0      [点我收藏+]

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

bubuko.com,布布扣

设置Nginx为服务和开机启动

vi /etc/rc.d/init.d/nginx

 

bubuko.com,布布扣
#!/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
bubuko.com,布布扣

 保存退出

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
bubuko.com,布布扣
#是否作为守护进程运行
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/
bubuko.com,布布扣

调整内存分配策略

vi /proc/sys/vm/overcommit_memory

CentOS6.4 安装OpenResty和Redis 并在Nginx中利用lua简单读取Redis数据

原文:http://www.cnblogs.com/kgdxpr/p/3550633.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!