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服务器)

# 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模块

# 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

# 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启动脚本

# 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

# 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服务器)

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

wKiom1QlNanysHbOAAy0UW_3D7Y622.jpg


TFS> put /root/1.jpg

wKioL1QlNeuiOb94AAvyEzmtfgM177.jpg


使用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来访问

wKioL1QlNh_gNGvZAAETQ36vmJI905.jpg

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

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

wKiom1QlNg-jxvJ5ABBq0Hga_C0902.jpg

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值