openesty redis configration
4577 ワード
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