fastDFS
yum -y install gcc* pcre pcre-devel openssl openssl-devel zlib zlib-devel gcc gcc-c++ openssl openssl-devel libevent libevent-devel perl unzip net-tools wget
创建FastDFS存储路径
mkdir -p /fastdfs/storage/group1
安装libfastcommon依赖包
tar -xvf libfastcommon-1.0.7.tar.gz
cd libfastcommon-1.0.7
./make.sh && ./make.sh install
创建软链接
libfastcommon.so默认安装到了/usr/lib64/libfastcommon.so,而FastDFS主程序设置的lib目录是/usr/local/lib,所以设置软连接
ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so
ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so
FastDFS主程序安装
tar -xvf fastdfs-5.05.tar.gz
cd fastdfs-5.05
./make.sh && ./make.sh install
配置FastDFS
创建调度器(tracker)、存储(storage)、客户端(client)配置文件
cd /etc/fdfs
cp tracker.conf.sample tracker.conf
cp client.conf.sample client.conf
cp storage.conf.sample storage.conf
修改tracker.conf配置
vim tracker.conf
base_path=/fastdfs/storage
store_lookup=2
store_group=group2
修改storage.conf配置
vim storage.conf
group_name=group1
port=23000
base_path=/fastdfs/storage/group1
store_path0=/fastdfs/storage/group1
tracker_server=192.168.168.107:22122
fastdfs-nginx模块配置
tar xf fastdfs-nginx-module_v1.16.tar.gz
vim /usr/local/src/fastdfs-nginx-module/src/config
将CORE_INCS="$CORE_INCS /usr/local/include/fastdfs /usr/local/include/fastcommon/"改成CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
拷贝配置文件
cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
cp /usr/local/src/fastdfs-5.05/conf/http.conf /etc/fdfs/
cp /usr/local/src/fastdfs-5.05/conf/mime.types /etc/fdfs/
vim /etc/fdfs/mod_fastdfs.conf
修改如下内容
base_path=/fastdfs/storage
tracker_server=192.168.168.107:22122
url_have_group_name = true
group_count = 1
[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/fastdfs/storage/group1
安装nginx
创建Nginx安装目录
mkdir -p /usr/local/nginx
解压缩
tar xf nginx-1.18.0.tar.gz
进入nginx安装包目录
cd nginx-1.18.0
预配编译安装
./configure --prefix=/usr/local/nginx --add-module=/usr/local/src/fastdfs-nginx-module/src && make && make install
修改Nginx配置文件
cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak
vim /usr/local/nginx/conf/nginx.conf
server {
listen 80;
server_name localhost;
location /group1/ {
root /fastdfs/storage/group1/data;
ngx_fastdfs_module;
}
}
开机自启
在/root目录下创建startup.sh文件,添加如下内容:
#!/bin/bash
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf
/usr/local/nginx/sbin/nginx
chmod +x /etc/rc.d/rc.local
创建多个存储分组
例如增加1个存储分组,
步骤1:复制1个storage.conf文件
cp storage_PPCf.conf storage_PPCd.conf
步骤2:创建存储路径
mkdir -p /fastdfs/storage/PPCd
步骤3:编辑分组信息
vim /etc/fdfs/storage1.conf
修改如下内容
group_name=group2
port=23001
base_path=/fastdfs/storage/PPCd
store_path0=/fastdfs/storage/PPCd
tracker_server=192.168.168.179:22122
步骤4:编辑fdfs/mod_fastdfs.conf文件
vim /etc/fdfs/mod_fastdfs.conf
注释掉
tracker_server=192.168.168.106:22122
#storage_server_port=23000
#group_name=group1
#store_path_count=1
#store_path0=/home/yuqing/fastdfs
修改内容如下
base_path=/fastdfs/storage
tracker_server=192.168.168.179:22122
url_have_group_name = true
group_count = 2
[group1]
group_name=PPCd
storage_server_port=23000
store_path_count=1
store_path0=/fastdfs/storage/PPCd
[group2]
group_name=PPCf
storage_server_port=23001
store_path_count=1
store_path0=/fastdfs/storage/PPCf
步骤5:修改nginx配置文件
vim /usr/local/nginx/conf/nginx.conf
server {
listen 802;
server_name localhost;
location /PPCd/
{
root /fastdfs/storage/PPCd/data;
ngx_fastdfs_module;
}
location /PPCf/
{
root /fastdfs/storage/PPCf/data;
ngx_fastdfs_module;
}
}
步骤6:启动分组
运行命令行:
/usr/bin/fdfs_storaged /etc/fdfs/storage1.conf
/usr/local/nginx/sbin/nginx -s reload
重启
/usr/bin/restart.sh /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
/usr/bin/restart.sh /usr/bin/fdfs_storaged /etc/fdfs/storage_PPCf.conf
/usr/bin/restart.sh /usr/bin/fdfs_storaged /etc/fdfs/storage_PPCd.conf
/usr/local/nginx/nginx/sbin/nginx -s reload
步骤7:加入到开机启动项
Vim /root/startup.sh
修改内容如下
#!/bin/bash
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf
/usr/bin/fdfs_storaged /etc/fdfs/storage1.conf
/usr/local/nginx/sbin/nginx
添加更多分组按照以上方法配置即可