openresty redis configuration

本文档详细介绍了如何配置OpenResty及其Lua模块lua-resty-mongol,并提供了使用示例。此外,还介绍了Redis的安装配置过程,包括编译安装、初始化脚本设置及服务启动配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

PART I openresty configuration
# yum -y install perl-devel perl-ExtUtils-Embed
# wget http://openresty.org/download/ngx_openresty-1.4.3.6.tar.gz
# tar zxvf ngx_openresty-1.4.3.6.tar.gz
# ./configure --prefix=/root/test/openresty \
--with-luajit \
--with-http_iconv_module \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_perl_module 
--with-debug 
# gmake && gmake install

PART II lua-resty-mongol configuration
1. get the lasest package
# git clone git://github.com/bigplum/lua-resty-mongol.git
2. modify the makefile
# vi Makefile
OPENRESTY_PREFIX=/root/test/openresty

PREFIX ?= /root/test/openresty
LUA_INCLUDE_DIR ?= $(PREFIX)/luajit/include/luajit-2.0
LUA_LIB_DIR ?= $(PREFIX)/lualib
INSTALL ?= install

.PHONY: all test install

all: ;

install: all
        $(INSTALL) -d $(LUA_LIB_DIR)/resty/mongol
        $(INSTALL) lib/resty/mongol/*.lua $(LUA_LIB_DIR)/resty/mongol


test:
        PATH=$(OPENRESTY_PREFIX)/nginx/sbin:$$PATH prove -I../test-nginx/lib -r t
3. installation 
# make install
4. test mongodb.lua
-- example.lua
local mongo = require "resty.mongol"
conn = mongo:new()
conn:set_timeout(1000)
ok, err = conn:connect("192.168.1.208","27017")
if not ok then
    ngx.say("connect failed: "..err)
end
local db = conn:new_db_handle ( "ddb" )
db:auth("admin","admin")
col = db:get_col("testData")
r = col:find_one({name})
ngx.say(r["name"])


-- testmongodb.lua
local mongo = require "resty.mongol"
conn = mongo:new()
ok, err = conn:connect("192.168.1.208","27017")
if not ok then
    ngx.say("connect failed: "..err)
end

local db = conn:new_db_handle("ddb")
db:auth("admin","admin")
col = db:get_col("ddb")

r, err = col:insert(, nil, true)

if not r then
    ngx.status = 400
    ngx.say("not ok")
else
    ngx.say("ok")
end

local ok, err = conn:set_keepalive(0,1000)
if not ok then
    ngx.say("failed to set keepalive: ", err)
    return
end

PART III redis configuration
1. download redis
wget http://download.redis.io/releases/redis-2.6.16.tar.gz
tar zxvf redis-2.6.16.tar.gz
# make or make CFLAGS="-march=i686"  
# make test

2. install tcl
wget http://downloads.sourceforge.net/project/tcl/Tcl/8.6.1/tcl8.6.1-src.tar.gz?r=http%3A%2F%2Fwww.linuxfromscratch.org%2Fblfs%2Fview%2Fsvn%2Fgeneral%2Ftcl.html&ts=1384333410&use_mirror=jaist
cd unix &&
./configure --prefix=/usr           \
            --without-tzdata        \
            --mandir=/usr/share/man \
            $([ $(uname -m) = x86_64 ] && echo --enable-64bit) &&
make &&

sed -e "s@^\(TCL_SRC_DIR='\).*@\1/usr/include'@" \
    -e "/TCL_B/s@='\(-L\)\?.*unix@='\1/usr/lib@" \
    -i tclConfig.sh
    
make install &&
make install-private-headers &&
ln -v -sf tclsh8.6 /usr/bin/tclsh &&
chmod -v 755 /usr/lib/libtcl8.6.so
# which tclsh
/usr/bin/tclsh

Command Explanations
--without-tzdata: This switch prevents installation of the shipped timezone data which are older than the ones provided in LFS.
$([ $(uname -m) = x86_64 ] && echo --enable-64bit): This switch is used to enable 64 bit support in Tcl on 64 bit operating systems.
make install-private-headers: This command is used to install the Tcl library interface headers used by other packages if they link to the Tcl library.
ln -v -sf tclsh8.6 /usr/bin/tclsh: This command is used to create a compatibility symbolic link to the tclsh8.6 file as many packages expect a file named tclsh.
sed -e ... tclConfig.sh: The Tcl package expects that its source tree is preserved so that packages depending on it for their compilation can utilize it. This sed removes the references to the build directory and replaces them with saner system-wide locations.

3. In order to install Redis binaries into /usr/local/bin
# make install

4. complete the redis configuration
1) copy the initlial scripts
# cp redis-2.6.16/utils/redis_init_script /etc/init.d/redis_6379

2) create the necessary directory
# mkdir /etc/redis
# mkdir -p /var/redis/6379

3) modify the configuration of redis
# cp redis-2.6.16/redis.conf /etc/redis/6379.conf
# daemonize => yes, pidfile => /var/run/redis_6379.pid, port => 6379, (153)dir => /var/redis/6379 

4) modify the program to boot
# chkconfig: 345 26 74
# description: start the redis server
chkconfig --add redis_6379
chkconfig redis_6379 on


转载于:https://my.oschina.net/u/1449160/blog/198640

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值