fastDFS+Nginx单机部署

fastdfs-nginx-module_v1.16.tar.gz
nginx-1.10.0.tar.gz
ngx_cache_purge-2.3.tar.gz
FastDFS_v5.08.tar.gz
fastdfs_client_java._v1.25.tar.gz

fastdfs.client.zip

libfastcommon-master.zip

fastDFS+Nginx一键部署.sh

一、环境准备:
跟踪服务器(Tracker Server): 192.168.10.10 #实验IP,实际情况作修改即可
存储服务器(Storage Server):192.168.10.10
操作系统:CentOS7
数据存储目录:
/fastdfs/tracker

       /fastdfs/storage

安装包:
1. FastDFS_v5.08.tar.gz:FastDFS源码
2. libfastcommon-master.zip:(从 FastDFS 和 FastDHT 中提取出来的公共 C 函数库)
3. fastdfs-nginx-module-master.zip:storage节点http服务nginx模块
4. nginx-1.10.0.tar.gz:Nginx安装包
ngx_cache_purge-2.3.tar.gz:图片缓存清除Nginx模块(集群环境会用到)
下载完成后,将压缩包解压到/usr/local/src目录下

      systemctl stop firewalld ; systemctl disable firewalld  #关闭防火墙并设置为开机不启动
      setenforce 0 ; sed -i 's/enforcing/disabled/g' /etc/selinux/configure   #关闭SELINUX并设为开机不启动
      systemctl  stop NetworkManager ; systemctl  disable NetworkManager #关闭图形化IP避免干扰

1、安装所需的依赖包
yum install make cmake gcc gcc-c++
2、安装libfatscommon
cd /usr/local/src
yum install -y unzip zip #安装unzip命令
unzip libfastcommon-master.zip #解压
cd libfastcommon-master
./make.sh && ./make.sh install #编译&&安装
3、安装FastDFS
cd /usr/local/src
tar -xzvf FastDFS_v5.08.tar.gz #解压
cd FastDFS
./make.sh && ./make.sh install #编译&&安装
#####检查一下文件是否齐全######
1> 服务脚本:
/etc/init.d/fdfs_storaged
/etc/init.d/fdfs_trackerd
2> 配置文件(示例配置文件):
[root@localhost ~]# ll /etc/fdfs/
-rw-r–r-- 1 root root 1461 6月 5 03:21 client.conf.sample
-rw-r–r-- 1 root root 7927 6月 5 03:21 storage.conf.sample
-rw-r–r-- 1 root root 7200 6月 5 03:21 tracker.conf.sample
3> 命令行工具
[root@localhost ~]# ll /usr/bin/fdfs_*
-rwxr-xr-x 1 root root 315416 6月 5 03:21 /usr/bin/fdfs_appender_test
-rwxr-xr-x 1 root root 315192 6月 5 03:21 /usr/bin/fdfs_appender_test1
-rwxr-xr-x 1 root root 302040 6月 5 03:21 /usr/bin/fdfs_append_file
-rwxr-xr-x 1 root root 301704 6月 5 03:21 /usr/bin/fdfs_crc32
-rwxr-xr-x 1 root root 302112 6月 5 03:21 /usr/bin/fdfs_delete_file
-rwxr-xr-x 1 root root 302840 6月 5 03:21 /usr/bin/fdfs_download_file
-rwxr-xr-x 1 root root 302432 6月 5 03:21 /usr/bin/fdfs_file_info
-rwxr-xr-x 1 root root 316256 6月 5 03:21 /usr/bin/fdfs_monitor
-rwxr-xr-x 1 root root 1102064 6月 5 03:21 /usr/bin/fdfs_storaged
-rwxr-xr-x 1 root root 325360 6月 5 03:21 /usr/bin/fdfs_test
-rwxr-xr-x 1 root root 320472 6月 5 03:21 /usr/bin/fdfs_test1
-rwxr-xr-x 1 root root 447936 6月 5 03:21 /usr/bin/fdfs_trackerd
-rwxr-xr-x 1 root root 303032 6月 5 03:21 /usr/bin/fdfs_upload_appender
-rwxr-xr-x 1 root root 304048 6月 5 03:21 /usr/bin/fdfs_upload_file
二、配置tracker服务器
1、复制tracker样例配置文件,并重命名
cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
2、修改tracker配置文件
vim /etc/fdfs/tracker.conf
# 修改的内容如下:
disabled=false # 启用配置文件
port=22122 # tracker服务器端口(默认22122)
base_path=/fastdfs/tracker # 存储日志和数据的根目录
#其它没有特殊要求不用改
详细配置文件官方文档:http://bbs.chinaunix.net/thread-1941456-1-1.html
3、创建存储日志和数据指定的目录
mkdir -p /fastdfs/tracker
4、启动tracker服务器
/etc/init.d/fdfs_trackerd start
#初次启动,会在/fastdfs/tracker目录下生成logs、data两个目录。
drwxr-xr-x 2 root root 178 6月 5 09:50 data
drwxr-xr-x 2 root root 26 6月 5 09:07 logs
5、检查FastDFS Tracker Server是否启动成功:
[root@localhost ~]# ps -ef | grep fdfs_trackerd
root 3676 1 0 09:06 ? 00:00:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
root 4045 3935 0 09:59 pts/1 00:00:00 grep --color=auto fdfs_trackerd
三、配置storage服务器
1、复制storage样例配置文件,并重命名
cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
2、编辑配置文件
vi /etc/fdfs/storage.conf
# 修改的内容如下:
disabled=false # 启用配置文件
port=23000 # storage服务端口
base_path=/fastdfs/storage # 数据和日志文件存储根目录
store_path0=/fastdfs/storage # 第一个存储目录
tracker_server=192.168.10.10:22122 # 这里是tracker服务器IP和端口 切记不能填写127.0.0.1,否则服务起不来 data目录不出现。
http.server_port=8888 # http访问文件的端口
没有特殊要求其他无需修改
详细配置文件官方文档:http://bbs.chinaunix.net/thread-1941456-1-1.html
3、创建基础数据目录
mkdir -p /fastdfs/storage
4、启动storage服务器
/etc/init.d/fdfs_storaged start
重启服务命令如下:/etc/init.d/fdfs_storaged restart /etc/fdfs/storage.conf
初次启动,会在/fastdfs/storage目录下生成logs、data两个目录。
drwxr-xr-x 259 root root 8192 6月 5 09:50 data
drwxr-xr-x 2 root root 26 6月 5 09:50 logs
5、检查FastDFS Tracker Server是否启动成功
[root@localhost ~]# ps -ef | grep fdfs_storaged
root 4027 1 1 09:50 ? 00:00:08 /usr/bin/fdfs_storaged /etc/fdfs/storage.conf
root 4062 3935 0 10:03 pts/1 00:00:00 grep --color=auto fdfs_storaged
6、服务监听测试
看到以下标红的ACTIVE就OK了
[root@localhost nginx]# /usr/bin/fdfs_monitor /etc/fdfs/storage.conf
[2018-06-05 11:54:21] DEBUG - base_path=/fastdfs/storage, connect_timeout=30, network_timeout=60, tracker_ser
Storage 1:
id = 192.168.10.10
ip_addr = 192.168.10.10 (localhost.localdomain) ACTIVE
http domain =

last_synced_timestamp = 1970-01-01 08:00
四、在所有storage节点安装fastdfs-nginx-module和Nginx
1、解压 fastdfs-nginx-module_v1.16.tar.gz
cd /usr/local/src
tar -xzvf fastdfs-nginx-module_v1.16.tar.gz
2、修改 fastdfs-nginx-module 的 config 配置文件
vim /usr/local/src/fastdfs-nginx-module/src/config
ngx_addon_name=ngx_http_fastdfs_module
HTTP_MODULES=“ H T T P M O D U L E S n g x h t t p f a s t d f s m o d u l e " N G X A D D O N S R C S = " HTTP_MODULES ngx_http_fastdfs_module" NGX_ADDON_SRCS=" HTTPMODULESngxhttpfastdfsmodule"NGXADDONSRCS="NGX_ADDON_SRCS n g x a d d o n d i r / n g x h t t p f a s t d f s m o d u l e . c " C O R E I N C S = " ngx_addon_dir/ngx_http_fastdfs_module.c" CORE_INCS=" ngxaddondir/ngxhttpfastdfsmodule.c"COREINCS="CORE_INCS /usr/include/fastdfs /usr/include/fastcommon”
CORE_LIBS=" C O R E L I B S − L / u s r / l i b − l f a s t c o m m o n − l f d f s c l i e n t " C F L A G S = " CORE_LIBS -L/usr/lib -lfastcommon -lfdfsclient" CFLAGS=" CORELIBSL/usr/liblfastcommonlfdfsclient"CFLAGS="CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='2561024’ -DFDFS_MOD_CONF_FILENAME=‘“/etc/fdfs/mod_fastdfs.conf”’"
3、安装Nginx上传当前的稳定版本 Nginx(nginx-1.10.0.tar.gz)到/usr/local/src 目录
4、安装编译 Nginx 所需的依赖包
yum install gcc gcc-c++ make automake autoconf libtool pcre
zlib openssl openssl-devel
5、编译安装 Nginx (添加 fastdfs-nginx-module 模块)
cd /usr/local/src/
tar -zxvf nginx-1.10.0.tar.gz
cd nginx-1.10.0
./configure --add-module=/usr/local/src/fastdfs-nginx-module/src
make && make install
6、复制 fastdfs-nginx-module 源码中的配置文件到/etc/fdfs 目录,并修改
cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf.sample.bak
mv /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
vim /etc/fdfs/mod_fastdfs.conf
connect_timeout=10
base_path=/tmp
tracker_server=192.168.10.10:22122
storage_server_port=23000
group_name=group1
url_have_group_name = true
store_path0=/fastdfs/storage

   vim /etc/fdfs/client.conf     #改以下配置
      tracker_server=192.168.10.10:22122
      http.tracker_server_port=8888
      base_path=/fastdfs/tracker

7、复制 FastDFS 的部分配置文件到/etc/fdfs 目录
cd /usr/local/src/FastDFS/conf
cp http.conf mime.types anti-steal.jpg /etc/fdfs/
vim /etc/fdfs/http.conf #改以下配置
http.anti_steal.token_check_fail=/usr/local/src/FastDFS/conf/anti-steal.jpg
8、修改Nginx配置文件
vim /usr/local/nginx/conf/nginx.conf
user root;
worker_processes 1;
events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8888;
server_name localhost;
location /group1/M00/ { #这一行和下一行一定注意结尾的斜杠,有没有斜杠区别很大
root /fastdfs/storage/data;
ngx_fastdfs_module;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
9、启动Nginx服务,会产生fastdfs的PID
[root@localhost conf]# mkdir /fastdfs/storage/data/group1
[root@localhost conf]# ln -s /fastdfs/storage/data /fastdfs/storage/data/group1/M00
ln -s /fastdfs/storage/data/ /fastdfs/storage/data/M00
[root@localhost conf]# /usr/local/nginx/sbin/nginx
ngx_http_fastdfs_set pid=6745
/usr/local/nginx/sbin/nginx -s reload #nginx重启命令
10、测试:
vim /usr/bin/test.txt #创建一个普通文件写点内容
[root@localhost fdfs]# /usr/bin/fdfs_test /etc/fdfs/client.conf upload /usr/bin/test.txt
This is FastDFS client test program v5.08

example file url: http://192.168.10.10:8888/group1/M00/00/00/wKgKClsWTpeAcAeQAAAAEaFD8fU496_big.txt
用浏览器访问上面网址显示test.txt编辑内容即完成
优化:
storage:
accept_threads=2
work_threads=20
disk_reader_threads=5
disk_writer_threads=5

Tracker:
accept_threads=5
work_threads=25

你可能感兴趣的:(nginx,linux,运维)