天天看點

Centos5下安裝tfs并使用nginx做通路

作業系統環境

[root@localhost ~]# uname -a

Linux localhost.localdomain 2.6.18-371.9.1.el5 #1 SMP Tue Jun 10 17:49:56 EDT 2014 x86_64 x86_64 x86_64 GNU/Linux

[root@localhost ~]# cat /etc/issue

CentOS release 5.10 (Final)

Kernel \r on an \m

[root@localhost ~]#

PS:以下操作我隻在如上系統進行驗證使用,僅供參考

1.更新yum源

2.安裝高版本mysql

 rpm -ivh *.rpm

 echo 'priority=1' >> /etc/yum.repos.d/remi.repo

 echo 'priority=1' >> /etc/yum.repos.d/epel-testing.repo

 echo 'priority=1' >> /etc/yum.repos.d/epel.repo

 檢查mysql 是否有可更新版本。發現有版本可以更新到mysql5.5.11。

yum --enablerepo=remi list mysql 

删除作業系統自帶的低版本的mysql

yum remove mysql

通過新yum源安裝高版本的mysql

yum -y --enablerepo=remi install mysql mysql-server mysql.x86_64  mysql-devel.x86_64

3.安裝支援包 automake autoconfig 和 libtool

驗證automake是否安裝rpm -qa |grep automake

驗證autoconfig是否安裝 /usr/bin/autoconf -V

auotmake 1.4以上版本需要安裝libuuid-devel,zlib-devel,mysql-devel三個開發包 

檢視以安裝的rpm包:rpm -qa|grep 包名

rpm -qa|grep libuuid

rpm -qa|grep zlib-devel

rpm -qa|grep mysql-devel

如果你使用RedHat5.x和Centos 5.x會找不到libuuid-devel包,請看下面。

RedHat5.x和Centos 5.x 安裝:  yum install uuidd

安裝其它支援包: yum install libtool zlib-devel

下面的readline包系統自帶了,ncurses包系統預設沒有,我也安裝,你安不安自已定吧。

[root@locatfs local]# yum install readline-devel readline

[root@locatfs local]# yum install ncurses-devel.x86_64  ncurses.x86_64

4.安裝ext4格式工具

[root@locatfs local]# yum install  e4fsprogs e4fsprogs-devel    

加載ext4子產品,讓系統支援ext4檔案系統

[root@locatfs local]#  modprobe ext4

5.安裝tb-common-utils

tb-common-utils是淘寶開發使用的一個公共庫

TFS依賴于底層開發包tbnet。tb-common-utils裡面含有tbsys和tbnet

首先編譯安裝tblib(tb-common-utils),這裡我安裝在和tfs同一個路徑。

gtest庫是單元測試架構,下面先安裝安裝gtest

[root@locatfs local]# unzip gtest-1.6.0.zip

[root@locatfs local]# cd gtest-1.6.0

[root@locatfs local]# ./configure

[root@locatfs local]# make

[root@locatfs local]# cd make/

[root@locatfs local]# ./sample1_unittest

安裝tb-common-utils

建立一個下載下傳目錄,并進入這個目錄。下載下傳源碼: 這裡下載下傳版本18的因為淘寶開發的東西不往下相容

編譯和安裝tbnet, tbsys庫

ps:建議将這行指令直接寫入~/.bash_profile,然後執行“. ~/.bash_profile”

修改:

[root@locatfs local]# vi /etc/profile

添加:(計劃安裝在/usr/local/tb/lib目錄)

export TBLIB_ROOT=/usr/local/tb/lib

生效:

[root@locatfs local]# source /etc/profile

[root@locatfs local]# cd tb-common-utils/

[root@locatfs local]# chmod +x *.sh

[root@locatfs local]# ./build.sh

安裝完成後,在TBLIB_ROOT表示的目錄(/usr/local/tb/lib),應該可以看到include、lib 兩個目錄。

6.編譯安裝TFS----

編譯安裝tfs   (安裝到 /usr/local/tfs目錄)

進入 tfs 目錄

[root@locatfs local]# cd tfs-2.2.10/

[root@locatfs local]# ./build.sh  init

[root@locatfs local]# ./configure --prefix=/usr/local/tfs --without-tcmalloc

[root@locatfs local]# make install

錯誤總結:

    cursers.c:2:21: 錯誤: curses.h:No such file or directory

解決辦法:

    安裝 ncurses-devel.x86_64  ncurses.x86_64軟體包繼續編譯

7.安裝nginx-tfs子產品

TFS子產品使用了一個開源的JSON庫來支援JSON,先安裝yajl-2.0.1

<a href="http://download.csdn.net/detail/xinsir88/7694379" target="_blank">http://download.csdn.net/detail/xinsir88/7694379</a>

[root@localhost opt]# cd lloyd-yajl-12ee82a/

[root@localhost lloyd-yajl-12ee82a]# ./configure --prefix=/usr/local/yajl &amp;&amp; make &amp;&amp; make install

 報錯

== removing old build files

== running CMake in build directory

./configure: line 41: cmake: command not found

The "cmake" program is required to configure yajl.

yum -y install cmake

繼續編譯通過

下載下傳tengine此軟體是nginx的升華版本,在nginx上二次開發

下載下傳nginx-tfs子產品

安裝tengine并添加ngix-tfs子產品

[root@localhost tengine-2.0.3]# ./configure --prefix=/usr/local/nginx --add-module=/opt/nginx-tfs-master &amp;&amp; make &amp;&amp; make install

報錯

./configure: error: the HTTP rewrite module requires the PCRE library.

You can either disable the module by using --without-http_rewrite_module

option, or install the PCRE library into the system, or build the PCRE library

statically from the source with nginx by using --with-pcre=&lt;path&gt; option.

解決辦法 

[root@localhost tengine-2.0.3]# yum -y install pcre-devel

繼續編譯tengine

啟動nginx報錯

/usr/local/nginx/sbin/nginx: error while loading shared libraries: libyajl.so.2: cannot open shared object file: No such file or directory

xx解決辦法

[root@localhost tengine-2.0.3]# ln -s /usr/local/lib/libyajl.so.2 /usr/lib64/libyajl.so.2

再次測試成功

啟動nginx

[root@localhost tengine-2.0.3]# /usr/local/nginx/sbin/nginx

8.使用nginx通路上傳圖檔路徑

修改nginx配置檔案

在nginx的http子產品中添加upstream

tfs_upstream tfs_ns {

        server 192.168.1.230:8108;

        type ns;

    }

在nginx的server子產品中添加tfs_pass

server {

        listen       80;

        server_name  localhost;

tfs_keepalive max_cached=100 bucket_count=10;

tfs_log "pipe:/usr/sbin/cronolog -p 30min /var/log/nginx/logs/cronolog/%Y/%m/%Y-%m-%d-%H-%M-tfs_access.log";

 location  ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {

              tfs_pass tfs://tfs_ns;

          }

        }

使用url通路圖檔

例如上傳的傳回值是xxxxxxxxxxxxxxxxxxxxxx.jpg

   通路使用 http:/NameserverIP/v1/tfs/xxxxxxxxxxxxxxxxxxxxxx.jpg

本文轉自 xinsir999 51CTO部落格,原文連結:http://blog.51cto.com/xinsir/1532724,如需轉載請自行聯系原作者