一,FastDFS文件系统安装
#步骤1:下载并安装libevent
#1.1安装libevent
wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
tar -zxvf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable
./configure
make
make install
#1.2为libevent创建软链接到/lib库下,64位系统对应/lib64
ln -s /usr/local/lib/libevent* /lib/
ln -s /usr/local/lib/libevent* /lib64/
#1.3检查是否已经安装成功命令
ls -al /usr/local/lib | grep libevent
#步骤2:安装配置FastDFS文件系统
#2.1 安装FastDFS文件系统
wget http://fastdfs.googlecode.com/files/FastDFS_v4.06.tar.gz
tar -zxvf FastDFS_v4.06.tar.gz
cd FastDFS
vi make.sh
TARGET_PREFIX=/usr/local/FastDFS ---安装路径
TARGET_CONF_PATH=/etc/fdfs ---配置文件路径
WITH_LINUX_SERVICE=1 ---是否为linux服务
./make.sh
./make.sh install
#2.2创建存储目录
mkdir /home/fastdfs
mkdir /home/fastdfs/tracker
mkdir /home/fastdfs/storage
#2.3修改fastdfs配置文件
cd /etc/fdfs/
vim tracker.conf
port=888
base_path=/home/fastdfs/tracker
http.tracker_server_port=8888
vim storage.conf
port=889
group_name=group1
store_path0=/home/fastdfs/storage
tracker_server=10.116.84.117:888
vim client.conf
base_path=/home/fastdfs/tracker
tracker_server=10.116.84.117:888
http.tracker_server_port=8888
#步骤3:安装配置nginx
#3.1安装nginx
下载nginx-1.5.1.tar.gz版本
tar -zxvf nginx-1.5.1.tar.gz
cd /usr/local/nginx-1.5.1/src
wget https://sourceforge.net/projects/fastdfs/files/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz/download
tar -zxvf fastdfs-nginx-module_v1.16.tar
cd /usr/local/nginx-1.5.1
./configure --prefix=/usr/local/nginx-fdfs --add-module=/usr/local/nginx-1.5.1/src/fastdfs-nginx-module/src
make
make install
#3.2修改nginx.conf配置
cd /usr/local/nginx-fdfs/conf
vim nginx.conf
listen 8000;
location /group1/M00 {
root /home/fastdfs/storage/data;
ngx_fastdfs_module;
}
#3.3修改mod_fastdfs.conf(fastdfs-nginx-module模块使用的配置文件)
cp /usr/local/nginx-1.5.1/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
vim mod_fastdfs.conf
connect_timeout=2
network_timeout=30
base_path=/home/fastdfs/storage
tracker_server=10.116.84.117:888
storage_server_port=889
group_name=group1
store_path0=/home/fastdfs/storage
load_fdfs_parameters_from_tracker=true
log_filename=/home/fastdfs/nginxfdfsmod/ngnix_mod_fastdfs.log
#步骤4:验证是否安装成功
#4.1找一张测试图片test.jpg
上传一张测试图片到/home/fastdfs目录下test.jpg
#4.2上传文件到文件系统
/usr/local/bin/fdfs_test /etc/fdfs/client.conf upload /home/fastdfs/test.jpg
如下图则上传成功:
![](https://i-blog.csdnimg.cn/blog_migrate/8eb06798efded0a80b2b7352aaa37889.png)
获取地址,通过配置的nginx访问图片资源:
http://120.25.233.113:8000/group1/M00/00/00/CnRUdVdTmZ6AIYV-AAAbGTHIZk4388_big.jpg,能够正常访问则安装配置成功。
二,常用操作命令
#nginx启动命令
cd /usr/local/nginx-fdfs/sbin
./nginx
#nginx重新加载配置命令
./nginx -s reload
#启动跟踪器tracker
/usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf
#启动存储节点storage
/usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf
#查看服务进程ID
ps -aux | grep fdfs_trackerd
ps -aux | grep fdfs_storaged
#查看tracker及所有group运行状况
/usr/local/bin/fdfs_monitor /etc/fdfs/client.conf
通过Storage : ip_addr状态,查看存储节点是否可用,OFFLINE(已下线不可用),ACTIVE(激活可用)
#关闭进程
killall fdfs_trackerd
killall fdfs_storaged
或
/usr/local/bin/stop.sh /usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf
/usr/local/bin/stop.sh /usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf
#重启进程
/usr/local/bin/restart.sh /usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf
/usr/local/bin/restart.sh /usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf