Centos6单服务器安装配置FastDFS
测试环境:
必须 [CentOS 6.4 X86_64 , FastDFS_v4.06 , nginx-1.8.0 , fastdfs-nginx-module_v1.15, libevent-2.0.22]
非必须 [pcre-8.37(伪静态) , ngx_cache_purge-2.3(反向代理) , openssl-1.0.2c(https)]
服务器IP:
server1+tracker1+storage1:192.168.0.82(fastdfs1.rekfan.com)
软件约定环境:
软件包下载目录:/usr/local/src
Nginx 安装目录:/data/webserver/nginx
FastDFS 安装目录:/data/fastdfs
FastDFS 数据目录:/data/fastdfs_data
软件下载:
cd /usr/local/src/
wget https://fastdfs.googlecode.com/files/FastDFS_v4.06.tar.gz
wget http://nginx.org/download/nginx-1.8.0.tar.gz
wget https://fastdfs.googlecode.com/files/fastdfs-nginx-module_v1.15.tar.gz
wget https://sourceforge.net/projects/levent/files/libevent/libevent-2.0/libevent-2.0.22-stable.tar.gz
wget http://sourceforge.net/projects/pcre/files/pcre/8.37/pcre-8.37.tar.gz
wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz
wget http://www.openssl.org/source/openssl-1.0.2c.tar.gz
安装步骤:
先卸载旧版本的libevent
1. 安装libevent
cd /usr/local/src/
tar zxvf libevent-2.0.22-stable.tar.gz
cd libevent-2.0.22-stable
./configure
make && make install
ln -s /usr/local/lib/libevent-2.0.so.5/usr/lib64/
2. 安装FastDFS
因为FastDFS安装后文件存放比较零散,为了集中管理,建了如下目录,这里相关配置文件做了很多更改
useradd -r -s /bin/false fastdfs
mkdir -p /data/fastdfs_data
chown -R fastdfs:fastdfs /data/fastdfs_data
cd /usr/local/src
tar zxvf FastDFS_v4.06.tar.gz
cd FastDFS
./make.sh
./make.sh install
#安装完毕添加服务
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配置文件
cp/usr/local/src/FastDFS/conf/tracker.conf /etc/fdfs/
sed -i '22s/home\/yuqing\/fastdfs/data\/fastdfs_data/'/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 '37s/home\/yuqing\/fastdfs/data\/fastdfs_data/'/etc/fdfs/storage.conf
sed -i '100s/home\/yuqing\/fastdfs/data\/fastdfs_data/' /etc/fdfs/storage.conf
sed -i "109s/192.168.209.121:22122/192.168.0.82: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/data\/fastdfs_data/'/etc/fdfs/client.conf
sed -i "14s/192.168.0.197:22122/192.168.0.82:22122/"/etc/fdfs/client.conf
sed -i '58s/8080/80/' /etc/fdfs/client.conf
3.安装php扩展
注:这里php已经安装好了路径在/usr/local/php
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扩展cd /usr/local/src
tar zxvf fastdfs-nginx-module_v1.15.tar.gz
sed -i '6s/etc\/fdfs/data\/webserver\/nginx\/conf/' /usr/local/src/fastdfs-nginx-module/src/config
安装nginx需要的zlib
yum install zlib-devel -y
groupadd www
useradd -g www www -s /bin/false
解压nginx、pcre、openssl、ngx_cache_purge
cd /usr/local/src/nginx-1.8.0
./configure --prefix=/data/webserver/nginx --user=www --group=www --add-module=../ngx_cache_purge-2.3--add-module=/usr/local/src/fastdfs-nginx-module/src --with-http_stub_status_module --with-http_ssl_module--with-openssl=../openssl-1.0.2c --with-pcre=/usr/local/src/pcre-8.37
make && make install
#复制更改mod_fastdfs配置文件
cp/usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /data/webserver/nginx/conf/
sed -i 's/tmp/data\/webserver\/nginx\/logs\/nginx_logs/' /data/webserver/nginx/conf/mod_fastdfs.conf
sed -i "s/tracker:/192.168.0.82:/" /data/webserver/nginx/conf/mod_fastdfs.conf
#sed -i 's/group_name=group1/group_name=rekfan1/' #/data/webserver/nginx/conf/mod_fastdfs.conf
sed -i 's/group_name = false/group_name = ture/' /data/webserver/nginx/conf/mod_fastdfs.conf
sed -i '62s/home\/yuqing\/fastdfs/data\/fastdfs_data/' /data/webserver/nginx/conf/mod_fastdfs.conf
sed -i '98s/#/##/' /data/webserver/nginx/conf/mod_fastdfs.conf
sed -i 's/log_filename=/log_filename=\/data\/webserver\/nginx\/logs\/nginx_logs\/mod_fastdfs.log/'/data/webserver/nginx/conf/mod_fastdfs.conf
mkdir/data/webserver/nginx/logs/nginx_logs
chown www:www /data/webserver/nginx/logs/nginx_logs
4.1.修改nginx.conf配置文件
在server中增加配置:
访问路径不带group名(storage只有一个group的情况),如/M00/00/00/xxx:
location /M00 {
root /data/fastdfs_data/data;
ngx_fastdfs_module;
}
访问路径带group名(storage对应有多个group的情况),如/group1/M00/00/00/xxx:
location ~ /group([0-9])/M00 {
ngx_fastdfs_module;
}