首页 > 代码库 > Centos5下安装tfs并使用nginx做访问
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源
更新yun可以参照http://xinsir.blog.51cto.com/5038915/1532659
2.安装高版本mysql
wget http://centos.ustc.edu.cn/epel/5/x86_64/epel-release-5-4.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/5/remi/x86_64/remi-release-5.9-1.el5.remi.noarch.rpm
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是淘宝开发使用的一个公共库
tbsys是对操作系统服务的封装,tbnet则提供了网络框架。 tbnet和tbsys被作为tb-common-utils被开源了,可以访问 http://code.taobao.org/trac/tb-common-utils/wiki
TFS依赖于底层开发包tbnet。tb-common-utils里面含有tbsys和tbnet
首先编译安装tblib(tb-common-utils),这里我安装在和tfs同一个路径。
(http://code.taobao.org/svn/tb-common-utils/trunk/ tb-common-utils)
gtest库是单元测试框架,下面先安装安装gtest
自行上网下载gtest, (http://download.csdn.net/detail/xinsir88/7664211)
[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]# make
[root@locatfs local]# ./sample1_unittest
安装tb-common-utils
新建一个下载目录,并进入这个目录。下载源码: 这里下载版本18的因为淘宝开发的东西不往下兼容
svn checkout -r 18 http://code.taobao.org/svn/tb-common-utils/trunk/ tb-common-utils
编译和安装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目录)
[root@locatfs local]# svn checkout http://code.taobao.org/svn/tfs/tags/release-2.2.10 tfs-2.2.10
进入 tfs 目录
[root@locatfs local]# cd tfs-2.2.10/
[root@locatfs local]# chmod +x *.sh
[root@locatfs local]# ./build.sh init
[root@locatfs local]# ./configure --prefix=/usr/local/tfs --without-tcmalloc
[root@locatfs local]# make
[root@locatfs local]# make install
7.安装nginx-tfs模块
TFS模块使用了一个开源的JSON库来支持JSON,先安装yajl-2.0.1
http://download.csdn.net/detail/xinsir88/7694379
[root@localhost opt]# cd lloyd-yajl-12ee82a/
[root@localhost lloyd-yajl-12ee82a]# ./configure --prefix=/usr/local/yajl && make && 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.
It‘s available from most ports/packaging systems and http://cmake.org
解决办法:
yum -y install cmake
继续编译通过
下载tengine此软件是nginx的升华版本,在nginx上二次开发
wget http://tengine.taobao.org/download/tengine-2.0.3.tar.gz
下载nginx-tfs模块
wget https://codeload.github.com/alibaba/nginx-tfs/zip/master
安装tengine并添加ngix-tfs模块
[root@localhost tengine-2.0.3]# ./configure --prefix=/usr/local/nginx --add-module=/opt/nginx-tfs-master && make && 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=<path> option.
解决办法
[root@localhost tengine-2.0.3]# yum -y install pcre-devel
继续编译tengine
[root@localhost tengine-2.0.3]# ./configure --prefix=/usr/local/nginx --add-module=/opt/nginx-tfs-master && make && make install
启动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;
}
}