TFS的nginx模块配置

在部署完基本的tfs环境之后,就可以通过tfstool工具开始上传文件,上传完的文件可以通过ds_client工具来读取,也可以通过web方式来展示,本文介绍nginxtfs模块配置来实现http形式展现tfs文件系统上传后的文件。当然如果你高兴的话,也可以用tengine来实现。

 

环境介绍:

tfs nameserver服务器  192.168.1.225/24

tfs dataserver服务器  192.168.1.227/24

tfs-nginx服务器       192.168.1.12/24


一:下载nginx-tfs模块 (12服务器)

https://github.com/alibaba/nginx-tfs


二:下载nginx源码包,安装必须的rpm包  (12服务器)

1
2
3
4
5
6
7
8
9
10
# cd /usr/local/src/
# wget http://nginx.org/download/nginx-1.3.14.tar.gz
# yum -y install pcre pcre-devel  openssl openssl-devel  perl perl-devel perl-ExtUtils-Embed 
  
需要cmake支持,cmake编译可参考mysql5.5安装文档
# wget https://codeload.github.com/lloyd/yajl/legacy.tar.gz/2.1.0
# tar -zxvpf 2.1.0 
# cd lloyd-yajl-66cb08c/
# ./configure 
# make && make install


三:编译安装nginx,并添加tfs模块

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# tar -zxvpf nginx-1.3.14.tar.gz
# unzip nginx-tfs-master.zip 
# cd nginx-1.3.14
#./configure --prefix=/usr/local/nginx \
--user=nobody \
--group=nobody \
--with-select_module \ 
--with-poll_module \
--with-file-aio \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_gzip_static_module \
--with-http_secure_link_module \
--with-http_sub_module \
--with-http_stub_status_module \
--with-http_perl_module  \
--add-module=/usr/local/src/nginx-tfs-master


五:配置nginx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# cat /usr/local/nginx/conf/nginx.conf
user  nobody;
worker_processes  2;
  
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
error_log  logs/error.log  info;
  
pid        logs/nginx.pid;
  
  
events {
    worker_connections  10240;
}
  
  
http {
    include       mime.types;
    default_type  application/octet-stream;
  
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
  
    #access_log  logs/access.log  main;
  
    sendfile        on;
    #tcp_nopush     on;
  
    #keepalive_timeout  0;
    keepalive_timeout  65;
  
    gzip  on;
  
  
    tfs_upstream tfs_rc {
        server 192.168.1.225:8108;
        type ns;
        rcs_zone name=tfs1 size=128M;
        rcs_interface eth0;
        rcs_heartbeat lock_file=/usr/local/nginx/logs/lk.file interval=10s;
    }
  
    server {
          listen       7500;
          server_name  localhost;
  
          tfs_keepalive max_cached=100 bucket_count=10;
          #tfs_log "pipe:/usr/local/cronolog/sbin/ -p 30min /path/to/nginx/logs/cronolog/%Y/%m/%Y-%m-%d-%H-%M-tfs_access.log";
  
          location / {
              tfs_pass tfs://tfs_rc;
          }
    }
}

配置nginx启动脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# cat /etc/init.d/nginx 
#!/bin/sh 
# nginx - this script starts and stops the nginx daemon 
# chkconfig:   - 85 15 
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \ 
#               proxy and IMAP/POP3 proxy server 
# processname: nginx 
# config:      /etc/nginx/nginx.conf 
# config:      /etc/sysconfig/nginx 
# pidfile:     /var/run/nginx.pid 
  
# Source function library. 
. /etc/rc.d/init.d/functions 
  
# Source networking configuration. 
. /etc/sysconfig/network 
  
# Check that networking is up. 
[ "$NETWORKING" = "no" ] && exit 0 
  
nginx="/usr/local/nginx/sbin/nginx" 
prog=$(basename $nginx) 
  
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf" 
  
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx 
  
lockfile=/var/lock/subsys/nginx 
  
start() { 
    [ -x $nginx ] || exit 5 
    [ -f $NGINX_CONF_FILE ] || exit 6 
    echo -n $"Starting $prog: " 
    daemon $nginx -c $NGINX_CONF_FILE 
    retval=$? 
    echo 
    [ $retval -eq 0 ] && touch $lockfile 
    return $retval 
  
stop() { 
    echo -n $"Stopping $prog: " 
    killproc $prog -QUIT 
    retval=$? 
    echo 
    [ $retval -eq 0 ] && rm -f $lockfile 
    return $retval 
killall -9 nginx 
  
restart() { 
    configtest || return $? 
    stop 
    sleep 1 
    start 
  
reload() { 
    configtest || return $? 
    echo -n $"Reloading $prog: " 
    killproc $nginx -HUP 
RETVAL=$? 
    echo 
  
force_reload() { 
    restart 
  
configtest() { 
$nginx -t -c $NGINX_CONF_FILE 
  
rh_status() { 
    status $prog 
  
rh_status_q() { 
    rh_status >/dev/null 2>&1 
  
case "$1" in 
    start) 
        rh_status_q && exit 0 
    $1 
        ;; 
    stop) 
        rh_status_q || exit 0 
        $1 
        ;; 
    restart|configtest) 
        $1 
        ;; 
    reload) 
        rh_status_q || exit 7 
        $1 
        ;; 
    force-reload) 
        force_reload 
        ;; 
    status) 
        rh_status 
        ;; 
    condrestart|try-restart) 
        rh_status_q || exit 0 
            ;; 
    *)    
      echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" 
        exit 2 
esac

五:启动nginx

1
2
3
4
5
6
7
8
9
# echo '/usr/local/lib' >> /etc/ld.so.conf
# ldconfig
# /usr/local/nginx/sbin/nginx  -t
  
# chmod +x /etc/init.d/nginx 
# chkconfig --add nginx
  
# service nginx start
Starting nginx: [  OK  ]

六:使用tfstool客户端上传一份文档,图片等资源 (225服务器)

1
2
# /usr/local/tfs/bin/tfstool -s 192.168.1.225:8108
TFS> put /etc/resolv.conf

TFS的nginx模块配置


1
TFS> put /root/1.jpg

TFS的nginx模块配置


使用web浏览器读取tfs内的文件,这里值得注意的是端口后面的url一定是/v1/,tfs三个字符可以用任意字符代替,例如一个空格字符,或者aaaa,bbb等,但至少需要存在一个字符,这个应该是tfs-nginx模块源码的问题,未细究!


http://192.168.1.12:7500/v1/tfs/T1vtxTByhT1RCvBVdK

也可以使用url http://192.168.1.12:7500/v1/abc/T1vtxTByhT1RCvBVdK来访问

TFS的nginx模块配置

http://192.168.1.12:7500/v1/tfs/T1TyxTByJT1RCvBVdK

也可以使用url http://192.168.1.12:7500/v1/ /T1TyxTByJT1RCvBVdK 来访问

TFS的nginx模块配置

本文转自斩月博客51CTO博客,原文链接http://blog.51cto.com/ylw6006/1558631如需转载请自行联系原作者


ylw6006