[root@vm5 ~]# tar zxvf drizzle7-2011.07.21.tar.gz
[root@vm5 ~]# cd drizzle7-2011.07.21
[root@vm5 drizzle7-2011.07.21]# ./configure --without-server
[root@vm5 drizzle7-2011.07.21]# make libdrizzle-1.0
[root@vm5 drizzle7-2011.07.21]# make install-libdrizzle-1.0
[root@vm5 ~]# tar zxvf ngx_openresty-1.2.4.14.tar.gz
[root@vm5 ~]# cd ngx_openresty-1.2.4.14
[root@vm5 ngx_openresty-1.2.4.14]# ./configure --prefix=/usr/local/openresty --with-luajit --with-http_drizzle_module --with-libdrizzle=/usr/local
[root@vm5 ngx_openresty-1.2.4.14]# gmake
[root@vm5 ngx_openresty-1.2.4.14]# gmake install
Query OK, 0 rows affected (0.00 sec)
mysql> insert into users values(1,'zhangsan',24);
Query OK, 1 row affected (0.00 sec)
mysql> insert into users values(2,'lisi',26);
Query OK, 1 row affected (0.00 sec)
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream mysql {
drizzle_server 127.0.0.1:3306 dbname=test user=root protocol=mysql;
}
server {
listen 80;
server_name localhost;
root html;
index index.html index.htm;
location = /mysql-status {
drizzle_status;
}
location / {
drizzle_pass mysql;
drizzle_query "select id,username,age from users where id=1";
rds_json on;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
nginx: the configuration file /usr/local/openresty/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/openresty/nginx/conf/nginx.conf test is successful
[root@vm5 conf]# /usr/local/openresty/nginx/sbin/nginx -c /usr/local/openresty/nginx/conf/nginx.conf
[root@vm5 conf]# netstat -ntupl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 28013/mysqld
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 28036/nginx.conf
tcp 0 0 :::22 :::* LISTEN 2901/sshd
[{"id":1,"username":"zhangsan","age":24}]
[root@vm5 nginx]# curl localhost/mysql-status
worker process: 29491
upstream mysql
active connections: 0
connection pool capacity: 0
servers: 1
peers: 1
[{"id":1,"username":"zhangsan","age":24}]
[root@vm5 nginx]# curl localhost/?id=2
[{"id":2,"username":"lisi","age":26}]
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
root html;
index index.html index.htm;
location / {
content_by_lua '
local mysql = require "resty.mysql"
local db,err = mysql:new()
if not db then
ngx.say("failed to instantiate mysql: ",err)
return
end
db:set_timeout(1000)
local ok,err,errno,sqlstate = db:connect{
host = "127.0.0.1",
port = 3306,
database = "test",
user = "root",
password = "",
max_package_size = 1024
}
if not ok then
ngx.say("failed to connect: ", err, ": ", errno, " ", sqlstate)
return
end
res,err,errno,sqlstate = db:query("select id,username,age from users where id=1")
if not res then
ngx.say("bad result: ", err, ": ", errno, ": ", sqlstate, ".")
return
end
local cjson = require "cjson"
ngx.say(cjson.encode(res))
';
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
[root@vm5 lua]# touch /usr/local/openresty/nginx/conf/lua/mysql.lua
nginx: the configuration file /usr/local/openresty/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/openresty/nginx/conf/nginx.conf test is successful
[root@vm5 conf]# killall -HUP nginx
[{"username":"zhangsan","age":24,"id":1}]
[{"username":"lisi","age":26,"id":2}]
[root@vm5 conf]# curl localhost/?id=1
[{"username":"zhangsan","age":24,"id":1}]