天天看点

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,如需转载请自行联系原作者