日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

整合現(xiàn)有的Nginx與MongoDB的GridFS Nginx

 richsky 2012-04-23

整合現(xiàn)有的Nginx與MongoDB的GridFS Nginx-Gridfs”的安裝與配置過程[轉(zhuǎn)]

2012-02-14

環(huán)境說明:
CentOS 6 64bit Mini最小化安裝
MongoDB 1.8.2 【安裝配置方法詳見:最簡單實用的MongoDB安裝教程:在CentOS中使用 yum 安裝MongoDB及服務(wù)器端配置詳解
Nginx 1.0.5

本文將用費覆蓋方式安裝Nginx的擴展Nginx-Gridfs

Nginx的Nginx-Gridfs擴展地址:https://github.com/mdirolf/nginx-gridfs
可以使用wget下載,但是這個源碼中海鏈接著其它源碼,所有用git方法下載最方便,如果沒有安裝git的話按下面的步驟來

01查看git包的信息
02[root@vm ~]# yum info git
03**這里省略了不大重要的信息**
04Available Packages
05Name       : git
06Arch       : x86_64
07Version    : 1.7.1
08Release    : 2.el6_0.1
09Size       : 4.6 M
10Repo       : updates
11Summary    : Fast Version Control System
12URL        : http:///
13License    : GPLv2
14Description: Git is a fast, scalable, distributed revision control system with
15           : an unusually rich command set that provides both high-level
16           : operations and full access to internals.
17           :
18           : The git rpm installs the core tools with minimal dependencies.  To
19           : install all git packages, including tools for integrating with
20           : other SCMs, install the git-all meta-package.
21#安裝git包
22[root@vm ~]# yum -y install git

Ok,git工具安裝完成,下一步下載nginx-gridfs源碼包

一、安裝nginx-gridfs擴展

02[root@vm ~]# cd nginx-gridfs
03[root@vm nginx-gridfs]# git submodule init
04[root@vm nginx-gridfs]# git submodule update
05//進入我的nginx1.0.5的源碼目錄編譯安裝nginx-gridfs擴展
06[root@vm nginx-gridfs]# cd /root/nginx-1.0.5
07//編譯前先查看現(xiàn)有的nginx的編譯參數(shù)配置
08[root@vm nginx-1.0.5]#/usr/local/nginx/sbin/nginx -V nginx: nginx version: nginx/1.0.5
09nginx: TLS SNI support disabled
10nginx: configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6 
11//編譯配置在原有配置基礎(chǔ)上增加新的擴展(藍色部分)
12[root@vm nginx-1.0.5]# ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6 <strong>--add-module=/root/nginx-gridfs</strong>
13[root@vm nginx-1.0.5]# make
14[root@vm nginx-1.0.5]# make install

Nginx的nginx-gridfs擴展模塊安裝完成,檢查一下吧

1[root@vm nginx-1.0.5]# /usr/local/nginx/sbin/nginx -V
2nginx: nginx version: nginx/1.0.5
3nginx: built by gcc 4.4.4 20100726 (Red Hat 4.4.4-13) (GCC)
4nginx: TLS SNI support enabled
5nginx: configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6 --add-module=/root/nginx-gridfs

 

 二、在Nginx中配置nginx-gridfs

配置語法說明:
gridfs DB_NAME [root_collection=ROOT] [field=QUERY_FIELD] [type=QUERY_TYPE] [user=USERNAME] [pass=PASSWORD]

  • gridfs 表示告訴nginx服務(wù)器要調(diào)用gridfs模塊
  • root_collection= 指定Gridfs collection的前綴. 默認: fs
  • field= 指定用于查詢的字段 可以是 _id 和 filename. 默認: _id
  • type= 指定查詢的類型,這里支持 objectidstring 和int. 默認: objectid
  • user= 指定數(shù)據(jù)庫的用戶名. 默認: NULL
  • pass= 指定數(shù)據(jù)庫的密碼. 默認: NULL

Nginx配置文件中的具體寫法:
/usr/local/nginx/conf/nginx.conf

1#方法1:
2location /static/ {
3             gridfs ebook; #指定db 為ebook,其它均為默認,默認服務(wù)器為本地
4}
1方法2:
2location /static/ {
3        gridfs ebook
4               field=filename
5               type=string;
6        mongo 127.0.0.1:27017;
7}
1 方法3,用于副本集:
2location /static/ {
3         gridfs ebook;
4                field=filename
5                type=string;
6         mongo "foo"
7                192.168.1.60:27017
8                192.168.1.61:27017;
9}
1方法4,這種是一個完整參數(shù)的配置例子 location /static/ {
2    gridfs ebook
3           root_collection=book
4           field=_id
5           type=int
6           user=admin
7           pass=admin;
8    mongo 127.0.0.1:27017;
9}

*以上方法中 換行不是必要,僅僅是為了看的清晰
我的一個完整的配置

01server
02{
03    listen       80;
04    server_name static.ebook.vm6;
05 
06    location /
07        {
08            gridfs ebook
09            field=filename
10            type=string;
11        }
12 
13    log_format  static.ebook.vm6  '$remote_addr - $remote_user [$time_local] $request '
14         '$status $body_bytes_sent $http_referer '
15         '$http_user_agent $http_x_forwarded_for';
16    access_log  /home/wwwlogs/static.ebook.vm6.log  static.ebook.vm6;
17}

注:在測試配置時要記住不要將nginx的文件過期緩存時間配置開啟了,最好是在配置好服務(wù)器后再做這個工作,否則很容易造成配置錯誤的假象。我在配置過程用就遇到了這樣的問題
到這里你也許可以正常使用Nginx-Gridfs了,其實不然。
當(dāng)你重新啟動系統(tǒng)后你會發(fā)現(xiàn)用瀏覽器訪問服務(wù)器上的web站點沒有響應(yīng),這是因為系統(tǒng)啟動過程中Nginx啟動比MongoDB早,它初始化的時候不能正確鏈接MongoDB數(shù)據(jù)庫。
了解關(guān)于CentOS的守護進程啟動順序相關(guān)的解釋可以看看百度百科的這篇文章:http://wenku.baidu.com/view/f13befcfa1c7aa00b52acb40.html
查看啟動順序:

1[root@vm ~]# ls /etc/rc3.d
2K10saslauthd   K86cgred        S02lvm2-monitor  S11auditd        S25netfs      S55sshd    S90crond
3K50netconsole  K87restorecond  S08ip6tables     S12rsyslog       S26udev-post  S64mysql     S99local
4K74ntpd        K89rdisc        S08iptables      S22messagebus    S50php-fpm    S80postfix
5K75ntpdate     K95cgconfig     S10network       S24avahi-daemon  S55nginx      S85mongod
1[root@vm ~]# ls /etc/rc5.d
2K10saslauthd   K86cgred        S02lvm2-monitor  S11auditd        S25netfs      S55sshd    S90crond
3K50netconsole  K87restorecond  S08ip6tables     S12rsyslog       S26udev-post  S64mysql     S99local
4K74ntpd        K89rdisc        S08iptables      S22messagebus    S50php-fpm    S80postfix
5K75ntpdate     K95cgconfig     S10network       S24avahi-daemon  S55nginx      S85mongod

這些都是鏈接到/etc/init.d/目錄里的相應(yīng)守護進程啟動腳本
S55nginx 意思是nginx守護進程啟動順序為55
S85mongod 意思是mongod守護進程的啟動順序是85,問題就在這mongod比nginx晚啟動
修改啟動順序,將mongod的啟動順序值改為比nginx小的數(shù)
[root@vm ~]# mv /etc/rc3.d/S85mongod /etc/rc3.d/S54mongod
[root@vm ~]# mv /etc/rc5.d/S85mongod /etc/rc5.d/S54mongod
ok,現(xiàn)在reboot重啟下看看是不是問題已經(jīng)不存在了!

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多