正在加载中……
最新消息:欢迎大家访问,导航分类不完善,如果找不到自己想要的文章,可以通过【关键词】来进行搜索,^_^!

CentOS FastDFS结合Nginx及PHP安装配置篇

Linux专题 REKFAN.COM 18279浏览 0评论

更多


试验目的:
三台服务器上的环境都一样,三台服务器上同时安装上 storage 和 tracker , 实现多tracker运行 FastDFS !

测试环境:
必须 [CentOS 6.4 X86_64 , FastDFS_v4.06 , nginx-1.5.9 , fastdfs-nginx-module_v1.15 , libevent-2.0.21]
非必须 [pcre-8.35(伪静态) , ngx_cache_purge-2.1(反向代理) , openssl-1.0.1g(https)]

服务器IP:
server1+tracker1+storage1:192.168.10.11(fastdfs1.rekfan.com)
server2+tracker2+storage2:192.168.10.12(fastdfs2.rekfan.com)
server3+tracker2+storage3:192.168.10.13(fastdfs3.rekfan.com)

软件约定环境:
软件包下载目录:/usr/local/src
Nginx 安装目录:/usr/local/nginx
FastDFS 安装目录:/usr/local/fastdfs
FastDFS 数据目录:/rekfan/fastdfs_data

软件下载:
wget https://fastdfs.googlecode.com/files/FastDFS_v4.06.tar.gz -P /usr/local/src/
wget http://nginx.org/download/nginx-1.5.9.tar.gz -P /usr/local/src/
wget https://fastdfs.googlecode.com/files/fastdfs-nginx-module_v1.15.tar.gz -P /usr/local/src/
wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz -P /usr/local/src/
wget http://ftp.exim.llorien.org/pcre/pcre-8.35.tar.gz -P /usr/local/src/
wget http://labs.frickle.com/files/ngx_cache_purge-2.1.tar.gz -P /usr/local/src/
wget http://www.openssl.org/source/openssl-1.0.1g.tar.gz -P /usr/local/src/

安装步骤:
三台安装环境都一样,所以只写了安装一台的配置,剩下两台同如下步骤!

1.安装libevent
cd /usr/local/src/
tar zxvf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable
./configure --prefix=/usr/local/libevent
make && make install
ln -s /usr/local/libevent/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5

2. 安装FastDFS
#因为FastDFS安装后 文件存放比较零散,为了集中管理,建了如下目录,这里相关配置文件做了很多更改
useradd -r -s /bin/false fastdfs
mkdir -p /rekfan.com/fastdfs_data
chown -R fastdfs:fastdfs /rekfan.com/fastdfs_data

cd /usr/local/src
tar zxvf FastDFS_v4.06.tar.gz
cd FastDFS
# 因为我是给nginx添加fastdfs模块,所以不需要fastdfs支持 http 所以我就不需要去掉#WITH_HTTPD=1 前的注释了,直接编译
sed -i '61s/local/local\/fastdfs/' make.sh
./make.sh C_INCLUDE_PATH=/usr/local/libevent/include LIBRARY_PATH=/usr/local/libevent/lib
./make.sh install

注:如果提示下面的 "undefined reference to `clock_gettime' " 提示
#########################################################
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/libevent.a(event.o): In function `gettime':
(.text+0x439): undefined reference to `clock_gettime'
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/libevent.a(event.o): In function `event_base_new':
(.text+0x6fa): undefined reference to `clock_gettime'
collect2: ld returned 1 exit status
make: *** [fdfs_storaged] Error 1
#########################################################

解决方法:
vi打开 make.sh
将93行的 LIBS="$LIBS -lpthread" 更改为 LIBS="$LIBS -lpthread -lrt"
然后重新 ./make.sh

#安装完毕 添加服务
cp /usr/local/src/FastDFS/init.d/fdfs_trackerd /etc/init.d/
sed -i 's/usr\/local/usr\/local\/fastdfs/g' /etc/init.d/fdfs_trackerd
cp /usr/local/src/FastDFS/init.d/fdfs_storaged /etc/init.d/
sed -i 's/usr\/local/usr\/local\/fastdfs/g' /etc/init.d/fdfs_storaged

2.1.安装client
cd /usr/local/src/FastDFS/client/
make install

2.2.编辑tracker配置文件
sed -i '22s/home\/yuqing\/fastdfs/rekfan.com\/fastdfs_data/' /etc/fdfs/tracker.conf
sed -i 's/store_group=group2/store_group=rekfan1/' /etc/fdfs/tracker.conf
sed -i 's/run_by_group=/run_by_group=fastdfs/' /etc/fdfs/tracker.conf
sed -i 's/run_by_user=/run_by_user=fastdfs/' /etc/fdfs/tracker.conf
sed -i 's/http.server_port=8080/http.server_port=80/' /etc/fdfs/tracker.conf

2.3.编辑storage配置文件
sed -i 's/group_name=group1/group_name=rekfan1/' /etc/fdfs/storage.conf
sed -i '37s/home\/yuqing\/fastdfs/rekfan.com\/fastdfs_data/' /etc/fdfs/storage.conf
sed -i '100s/home\/yuqing\/fastdfs/rekfan.com\/fastdfs_data/' /etc/fdfs/storage.conf
sed -i "109s/192.168.209.121:22122/192.168.10.11:22122/" /etc/fdfs/storage.conf
sed -i 's/run_by_group=/run_by_group=fastdfs/' /etc/fdfs/storage.conf
sed -i 's/run_by_user=/run_by_user=fastdfs/' /etc/fdfs/storage.conf
sed -i 's/http.server_port=8888/http.server_port=80/' /etc/fdfs/storage.conf

2.4.编辑client配置文件
sed -i '10s/home\/yuqing\/fastdfs/rekfan.com\/fastdfs_data/' /etc/fdfs/client.conf
sed -i "14s/192.168.0.197:22122/192.168.10.11:22122/" /etc/fdfs/client.conf
sed -i '58s/8080/80/' /etc/fdfs/client.conf

3.安装php扩展
注:这里php已经安装好了 路径在/usr/local/php
php安装方法请阅:http://blog.rekfan.com/articles/199.html
cd /usr/local/src/FastDFS/php_client/
ln -s /usr/local/fastdfs/lib/libfdfsclient.so /usr/lib/
ln -s /usr/local/fastdfs/lib/libfastcommon.so /usr/lib/
ln -s /usr/local/fastdfs/include/fastcommon /usr/local/include/
ln -s /usr/local/fastdfs/include/fastdfs /usr/local/include/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
cat fastdfs_client.ini >> /etc/php.ini

4.安装nginx扩展
注:这里nginx已经安装好了 路径在/usr/local/nginx
nginx安装方法请阅:http://blog.rekfan.com/articles/141.html

#解压fastdfs-nginx-module
cd /usr/local/src
tar zxvf fastdfs-nginx-module_v1.15.tar.gz
sed -i '4s/local/local\/fastdfs/g' /usr/local/src/fastdfs-nginx-module/src/config
sed -i '5s/local\///' /usr/local/src/fastdfs-nginx-module/src/config
sed -i '6s/etc\/fdfs/usr\/local\/nginx\/conf/' /usr/local/src/fastdfs-nginx-module/src/config

#之前以前安装过了,现在是重新编译nginx,多加一条 --add-module=/usr/local/src/fastdfs-nginx-module/src
cd /usr/local/src/nginx-1.5.9
./configure --prefix=/usr/local/nginx --user=www --group=www --add-module=../ngx_cache_purge-2.1 --add-module=/usr/local/src/fastdfs-nginx-module/src  --with-http_stub_status_module --with-http_ssl_module --with-openssl=../openssl-1.0.1g --with-pcre=/usr/local/src/pcre-8.35
make && make install

#复制更改mod_fastdfs配置文件

cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /usr/local/nginx/conf/
sed -i 's/tmp/var\/log\/nginx_logs/' /usr/local/nginx/conf/mod_fastdfs.conf
sed -i "s/tracker:/192.168.10.11:/" /usr/local/nginx/conf/mod_fastdfs.conf
sed -i 's/group_name=group1/group_name=rekfan1/' /usr/local/nginx/conf/mod_fastdfs.conf
sed -i 's/group_name = false/group_name = ture/' /usr/local/nginx/conf/mod_fastdfs.conf
sed -i '62s/home\/yuqing\/fastdfs/rekfan.com\/fastdfs_data/' /usr/local/nginx/conf/mod_fastdfs.conf
sed -i '98s/#/##/' /usr/local/nginx/conf/mod_fastdfs.conf
sed -i 's/log_filename=/log_filename=\/var\/log\/nginx_logs\/mod_fastdfs.log/' /usr/local/nginx/conf/mod_fastdfs.conf
chown www:www /var/log/nginx_logs

4.1.修改nginx.conf配置文件

在server中增加配置:
访问路径不带group名(storage只有一个group的情况),如/M00/00/00/xxx:
location /M00 {
ngx_fastdfs_module;
}
访问路径带group名(storage对应有多个group的情况),如/group1/M00/00/00/xxx:
location ~ /group([0-9])/M00 {
ngx_fastdfs_module;
}

--------------------------------------------------------------------
其他相关文章:

CentOS FastDFS结合Nginx及PHP安装配置篇 [点击进入查看]

CentOS FastDFS配置之Tracker配置 [点击进入查看]

CentOS FastDFS配置之Storage配置 [点击进入查看] 

CentOS FastDFS配置之Client配置 [点击进入查看]

CentOS FastDFS配置之常见错误 [点击进入查看]

转载请注明:|REKFAN|系统运维| » CentOS FastDFS结合Nginx及PHP安装配置篇

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址