在CentOS 6.9 x86_64上搭建全功能的OpenResty 1.13.6.1笔记
好久沒(méi)有玩OpenResty,這段時(shí)間機(jī)會(huì)難得,趕緊實(shí)踐一下。下面是我在rMBP的CentOS 6.9 x86_64虛擬機(jī)上安裝目前最新版OpenResty 1.13.6.1的筆記。
OpenResty的下載地址是
https://openresty.org/cn/download.html
 
 
下面按照步驟說(shuō)明如下:
 
1.安裝依賴包
yum -y install readline-devel pcre-devel openssl-devel gcc gcc-c++ perl curl?
 
 
 
2.安裝Drizzle Nginx模塊的依賴庫(kù)
這是一個(gè)通過(guò)libdrizzle直連MySQL或Drizzle數(shù)據(jù)庫(kù)的nginx upstream模塊。默認(rèn)不包含在nginx發(fā)行包中,如果要啟用的話,你需要在configure時(shí)添加--with-http_drizzle_module選項(xiàng)。
 下面按照其依賴庫(kù)libdrizzle7,采用了春哥提交的舊版本,目前官網(wǎng)的最新版編譯不成功。因?yàn)槭荂++源碼包,需要安裝有g(shù)cc-c++庫(kù)來(lái)編譯。
 
wget http://openresty.org/download/drizzle7-2011.07.21.tar.gz
 tar zxvf drizzle7-2011.07.21.tar.gz?
 cd drizzle7-2011.07.21
 ./configure --without-server
 make libdrizzle-1.0?
 make install-libdrizzle-1.0
 
 
 
參考文獻(xiàn)
 https://github.com/openresty/drizzle-nginx-module#known-issues
 https://openresty.org/cn/drizzle-nginx-module.html
 http://blog.sina.com.cn/s/blog_4f9fc6e10101868j.html
 http://blog.csdn.net/clarencezi/article/details/21196539
 
 
3.安裝Postgres Nginx模塊的依賴庫(kù)
 該模塊默認(rèn)未啟用,可以在configure時(shí)添加--with-http_postgres_module來(lái)啟用它。該模塊需要使用外部libpq庫(kù),使用下面的命令安裝
 yum -y install postgresql-libs
 yum -y install postgresql-devel
 這兩個(gè)都安裝一下,不沖突,庫(kù)版本號(hào)目前是8.4
 
 參考文獻(xiàn)
 https://www.postgresql.org/
 https://github.com/FRiCKLE/ngx_postgres
 
 
4.編譯安裝OpenResty
這次將未啟用的模塊也編譯進(jìn)來(lái),以便后面的demo更順利。
wget https://openresty.org/download/openresty-1.13.6.1.tar.gz
 tar zxvf openresty-1.13.6.1.tar.gz
 cd openresty-1.13.6.1
 ./configure --prefix=/opt/openresty --with-http_drizzle_module --with-http_postgres_module --with-http_iconv_module
 gmake
 gmake install
 
注意,OpenResty 1.5.8.1+之后的版本默認(rèn)使用LuaJIT組件,在configure時(shí)無(wú)須使用--with-luajit編譯選項(xiàng)
 編譯中發(fā)現(xiàn)默認(rèn)使用的是LuaJIT 2.1版本
 
 
 
 
編譯完成之后的目錄結(jié)構(gòu)如下:
 
 
5.設(shè)置環(huán)境變量
 為了后面啟動(dòng)OpenResty的命令簡(jiǎn)單一些,不用在OpenResty的安裝目錄下面進(jìn)行啟動(dòng),我們?cè)O(shè)置環(huán)境變量來(lái)簡(jiǎn)化操作。
需要將OpenResty中的nginx可執(zhí)行程序的路徑添加到系統(tǒng)可搜索目錄下面:
 vim /etc/profile
 在末尾添加
 export PATH=/opt/openresty/nginx/sbin:$PATH
 保存退出之后,使之生效
 source /etc/profile
 可以使用echo $PATH來(lái)查看是否已經(jīng)生效
 
 
 將剛才安裝的動(dòng)態(tài)庫(kù)libdrizzle.so生效
 vim /etc/ld.so.conf
 開(kāi)頭添加
 /usr/local/lib
 保存退出之后,執(zhí)行刷新
 ldconfig
 執(zhí)行下面的命令查看
 ldconfig -p | grep --color libdrizzle
 
 
 
 6.配置
 為了不相互干擾,我們將安裝目錄和開(kāi)發(fā)目錄分開(kāi)存放,創(chuàng)建新目錄來(lái)存放配置文件
 mkdir -p ~/or_test/{conf,logs}
 在~/or_test/conf/nginx.conf配置中添加如下內(nèi)容
 
worker_processes  1;
error_log logs/error.log;
events {worker_connections 1024;
}
http {server {listen 20000;location / {default_type text/html;content_by_lua 'ngx.say("<p>hello, world</p>")';}}
}下面了解一下OpenResty的選項(xiàng)
-p 設(shè)置prefix
-c 設(shè)置配置文件路徑
-t 測(cè)試配置文件并退出
-s 發(fā)送指定信號(hào)給master進(jìn)程
 
查看nginx版本號(hào)
 
校驗(yàn)配置文件合法性
nginx -p ~/or_test
nginx -p ~/or_test -t
重啟
nginx -p ~/or_test -s reload
查看nginx是否正常開(kāi)啟。
 
7.測(cè)試
在命令行輸入
curl -i http://localhost:20000
 
在火狐瀏覽器中的效果
 
 
8.性能測(cè)試Benchmark
 ab -c10 -n50000 http://localhost:20000/
 對(duì)測(cè)試結(jié)果,我們只關(guān)心這項(xiàng)指標(biāo)
 Requests per second:? ? 17797.10 [#/sec] (mean)
 
 
對(duì)比春哥官網(wǎng)上的數(shù)據(jù)
 https://openresty.org/cn/benchmark.html
 17k+ r/s vs 20k+ r/s
 略有遜色一丟丟,但是考慮到我使用的是虛擬機(jī),而且公司網(wǎng)絡(luò)的原因,結(jié)果還是令人滿意的。
 
 
總結(jié)
以上是生活随笔為你收集整理的在CentOS 6.9 x86_64上搭建全功能的OpenResty 1.13.6.1笔记的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
 
                            
                        - 上一篇: 在Ubuntu 16.04.3 LTS上
- 下一篇: OpenResty中遇到Can't lo
