引用
-跟踪服务器
192.168.21.231 fdfs_tracker(22122)
-存储服务器
192.168.21.232 nginx(mod_fdfs)(8888) fdfs_storage(23000)
192.168.21.233 nginx(mod_fdfs)(8888) fdfs_storage(23000)
-客户端
192.168.21.231 fdfs_client
-下载网关
192.168.21.231 nginx(80)
192.168.21.231 fdfs_tracker(22122)
-存储服务器
192.168.21.232 nginx(mod_fdfs)(8888) fdfs_storage(23000)
192.168.21.233 nginx(mod_fdfs)(8888) fdfs_storage(23000)
-客户端
192.168.21.231 fdfs_client
-下载网关
192.168.21.231 nginx(80)
(0)系统设置
# vi /etc/sysconfig/network-scripts/ifcfg-eth0 # systemctl stop NetworkManager # systemctl disable NetworkManager # service network restart # vi /etc/sysctl.d/disable_ipv6.conf net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1 # sysctl -p/etc/sysctl.d/disable_ipv6.conf # ip a # vi /etc/sysconfig/selinux SELINUX=disabled # systemctl stop firewalld # systemctl disable firewalld # yum -y install gcc gcc-c++ kernel-devel pcre pcre-devel make libevent perl perl-devel gzip gzip-devel openssl-devel libxml2-devel wget unzip net-tools # yum clean all # yum makecache # useradd fastdfs -M -s /sbin/nologin # useradd nginx -M -s /sbin/nologin # shutdown -r now
(1)安装FastDFS依赖包libfastcommon
# cd /usr/local/src # wget https://github.com/happyfish100/libfastcommon/archive/master.zip --no-check-certificate -O libfastcommon-master.zip # unzip libfastcommon-master.zip # cd libfastcommon-master # ./make.sh && ./make.sh install mkdir -p /usr/lib64 mkdir -p /usr/lib install -m 755 libfastcommon.so /usr/lib64 install -m 755 libfastcommon.so /usr/lib mkdir -p /usr/include/fastcommon
(2)安装FastDFS
# cd /usr/local/src # wget https://github.com/happyfish100/fastdfs/archive/V5.09.tar.gz --no-check-certificate -O fastdfs-V5.09.tar.gz # tar -zxvf fastdfs-V5.09.tar.gz # cd fastdfs-5.09 # ./make.sh && ./make.sh install # ll /etc/init.d/ |grep fdfs -rwxr-xr-x 1 root root 918 Mar 17 15:32 fdfs_storaged -rwxr-xr-x 1 root root 920 Mar 17 15:32 fdfs_trackerd # ll /etc/fdfs/ -rw-r--r-- 1 root root 1461 Mar 17 15:32 client.conf.sample -rw-r--r-- 1 root root 7927 Mar 17 15:32 storage.conf.sample -rw-r--r-- 1 root root 105 Mar 17 15:32 storage_ids.conf.sample -rw-r--r-- 1 root root 7318 Mar 17 15:32 tracker.conf.sample # ll /usr/bin|grep fdfs -rwxr-xr-x 1 root root 315495 Mar 17 15:32 fdfs_appender_test -rwxr-xr-x 1 root root 315272 Mar 17 15:32 fdfs_appender_test1 -rwxr-xr-x 1 root root 302120 Mar 17 15:32 fdfs_append_file -rwxr-xr-x 1 root root 301780 Mar 17 15:32 fdfs_crc32 -rwxr-xr-x 1 root root 302179 Mar 17 15:32 fdfs_delete_file -rwxr-xr-x 1 root root 302914 Mar 17 15:32 fdfs_download_file -rwxr-xr-x 1 root root 302504 Mar 17 15:32 fdfs_file_info -rwxr-xr-x 1 root root 316333 Mar 17 15:32 fdfs_monitor -rwxr-xr-x 1 root root 1102214 Mar 17 15:32 fdfs_storaged -rwxr-xr-x 1 root root 325431 Mar 17 15:32 fdfs_test -rwxr-xr-x 1 root root 320552 Mar 17 15:32 fdfs_test1 -rwxr-xr-x 1 root root 448889 Mar 17 15:32 fdfs_trackerd -rwxr-xr-x 1 root root 303106 Mar 17 15:32 fdfs_upload_appender -rwxr-xr-x 1 root root 304126 Mar 17 15:32 fdfs_upload_file
(3)配置跟踪服务器
# mkdir -p /data/fastdfs/tracker # cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf # vi /etc/fdfs/tracker.conf disabled=false port=22122 base_path=/data/fastdfs/tracker # cp /usr/local/src/fastdfs-5.09/conf/http.conf /etc/fdfs/ # cp /usr/local/src/fastdfs-5.09/conf/mime.types /etc/fdfs/ # /etc/init.d/fdfs_trackerd start # netstat -unltp|grep fdfs # ls /data/fastdfs/tracker/ # cat /data/fastdfs/tracker/logs/trackerd.log
(4)配置存储服务器
# mkdir -p /data/fastdfs/storage # cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf # vi /etc/fdfs/storage.conf disabled=false port=23000 http.server_port=8888 base_path=/data/fastdfs/storage store_path0=/data/fastdfs/storage tracker_server=192.168.21.231:22122 # cp /usr/local/src/fastdfs-5.09/conf/http.conf /etc/fdfs/ # cp /usr/local/src/fastdfs-5.09/conf/mime.types /etc/fdfs/ # /etc/init.d/fdfs_storaged start # netstat -unltp|grep fdfs # ls /data/fastdfs/storage
(5)配置客户端
# cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf # vi /etc/fdfs/client.conf base_path=/data/fastdfs/tracker tracker_server=192.168.21.231:22122
文件上传下载测试
# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /usr/local/src/fastdfs-5.09/README.md group1/M00/00/00/wKgV6FjLk9eAMFQOAAAJTOwCGr42261.md # cd /tmp # /usr/bin/fdfs_download_file /etc/fdfs/client.conf group1/M00/00/00/wKgV6FjLk9eAMFQOAAAJTOwCGr42261.md fastdfs-5.09-README.md
(6)存储服务器安装nginx(mod_fdfs)
# cd /usr/local/src # wget https://github.com/happyfish100/fastdfs-nginx-module/archive/master.zip --no-check-certificate -O fastdfs-nginx-module-master.zip # unzip fastdfs-nginx-module-master.zip # cd /usr/local/src # wget http://nginx.org/download/nginx-1.9.9.tar.gz -O nginx-1.9.9.tar.gz # tar -zxvf nginx-1.9.9.tar.gz # cd nginx-1.9.9 # ./configure --prefix=/usr/local/nginx-1.9.9 --add-module=../fastdfs-nginx-module-master/src # make && make install # ln -s /usr/local/nginx-1.9.9 /usr/local/nginx # cp -r /usr/local/src/fastdfs-nginx-module-master/src/mod_fastdfs.conf /etc/fdfs/ # vi /etc/fdfs/mod_fastdfs.conf connect_timeout=10 base_path=/tmp tracker_server=192.168.21.231:22122 storage_server_port=23000 url_have_group_name=true store_path0=/data/fastdfs/storage group_name=group1 # vi /usr/local/nginx/conf/nginx.conf server { listen 8888; location ~/group[0-9]/ { ngx_fastdfs_module; } } # /usr/local/nginx/sbin/nginx # netstat -unltp|grep nginx
以上步骤安装两台服务器(192.168.21.232、192.168.21.233)
确认nginx
http://192.168.21.232:8888/
Welcome to nginx!
http://192.168.21.233:8888/
Welcome to nginx!
确认文件:
http://192.168.21.232:8888/group1/M00/00/00/wKgV6FjLk9eAMFQOAAAJTOwCGr42261.md
http://192.168.21.233:8888/group1/M00/00/00/wKgV6FjLk9eAMFQOAAAJTOwCGr42261.md
(7)下载网关安装nginx
# cd /usr/local/src # wget http://nginx.org/download/nginx-1.9.9.tar.gz -O nginx-1.9.9.tar.gz # tar -zxvf nginx-1.9.9.tar.gz # cd nginx-1.9.9 # ./configure --prefix=/usr/local/nginx-1.9.9 # make && make install # ln -s /usr/local/nginx-1.9.9 /usr/local/nginx # vi /usr/local/nginx/conf/nginx.conf upstream fdfs { server 192.168.21.232:8888; server 192.168.21.233:8888; } server { location ~/group[0-9]/ { proxy_pass http://fdfs; } } # /usr/local/nginx/sbin/nginx # netstat -unltp|grep nginx
确认文件:
http://192.168.21.231/group1/M00/00/00/wKgV6FjLk9eAMFQOAAAJTOwCGr42261.md
以上就安装完成了,可以客户端再次上传图片测试各服务器是否同步:
# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /tmp/test.jpg group1/M00/00/00/wKgV6VjLmKGAEGocAAJmqsSfEXA036.jpg
确认文件:
http://192.168.21.232:8888/group1/M00/00/00/wKgV6VjLmKGAEGocAAJmqsSfEXA036.jpg
http://192.168.21.233:8888/group1/M00/00/00/wKgV6VjLmKGAEGocAAJmqsSfEXA036.jpg
http://192.168.21.231/group1/M00/00/00/wKgV6VjLmKGAEGocAAJmqsSfEXA036.jpg