【FastDFS分布式文件系统】4.FastDFS部署案例(下)

接上一篇: https://blog.csdn.net/acmman/article/details/80869875
前面在三台虚拟机上分别下载和部署了FastDFS的依赖库以及安装包,本篇来介绍一下配置文件,并配置和启动追踪服务器和存储服务器。

打开“/etc/fdfs”查看配置文件:

其中分别放置了客户端配置文件、追踪服务器配置文件、存储服务器配置文件、自定义storage标识配置文件(以前用ip地址来标识storage server,V4开始可以自定义storage server Id)。我们分别就追踪服务器和存储服务器的配置来分别讲解这些配置文件。

一、追踪服务器配置文件以及启动
在追踪服务器192.168.195.129中,我们把tracker.conf.sample模板复制并重命名一下:

然后使用vim打开追踪服务器的配置文件“tracker.conf”,内容如下:
# 设置是否禁用该配置文件
# true为禁用,false为不禁用
disabled=false

# 设置绑定这个主机的ip地址
bind_addr=

# 追踪服务器的端口
port=22122

# 连接的超时时间,默认是30秒
connect_timeout=30

# 网络连接的超时时间,默认是60秒
network_timeout=60

# 存储数据或者日志的基本路径
base_path=/home/yuqing/fastdfs

# 支持的最大连接数
max_connections=256

# 可接受的线程数量
accept_threads=1

# 工作线程数量,要小于最大连接数,默认是4
work_threads=4

# 最小缓冲区大小,默认 8KB
min_buff_size = 8KB

# 最大缓冲区大小,默认 128KB
max_buff_size = 128KB

# 上传文件时卷组的选择方式
# 0: 轮循
# 1: 指定
# 2: 负载均衡, 会选择最大空闲的卷组去上传文件
store_lookup=2

# 如果上面的设置为 1, 就必须设置一个group组
store_group=group2

# 卷组中存储服务器的选择
# 0: 轮循 (默认)
# 1: 通过ip地址的排序进行选择
# 2: 通过ip地址的优先级进行选择 (最小的)
# 如果use_trunk_file设置为true, 必须选择1或2
store_server=0

# 存储服务器中存储路径的选择(如果设置了多个存储路径)
# 0: 轮循
# 2: 负载均衡, 选择最大的空闲路径去上传文件
store_path=0

# 选择存储服务器下载文件的选择
# 0: 轮循 (默认)
# 1: 哪一个为文件上传的源头存储服务器,就从哪里下载
download_server=0

# 用于设置系统或其他应用程序的存储空间。
# 当剩余的空间小于reserved_storage_space设置的空间
# 该group组就无法再上传其它文件
reserved_storage_space = 10%

#日志级别:
### emerg for emergency
### alert
### crit for critical
### error
### warn for warning
### notice
### info
### debug
log_level=info

#运行fastdfs的组,可以指定。
#如果不指定,谁启动了它,运行用户所在的组就是可运行组
run_by_group=

#运行fastdfs的用户,可以指定。
#如果不指定,谁启动了它,当前用户就是可运行用户
run_by_user=

# 设置允许连接的主机,设置可以连接到追踪服务器的ip连接范围
# 写法样例:
# allow_hosts=10.0.1.[1-15,20]
# allow_hosts=host[01-08,20-25].domain.com
# allow_hosts=192.168.5.64/26
allow_hosts=*

# log日志刷新到硬盘上的时间间隔,默认10秒
sync_log_buff_interval = 10

# 检查服务器存活的时间间隔,默认120秒
check_active_interval = 120

# 线程栈的大小,需要大于或等于64KB
thread_stack_size = 64KB

# 设置存储服务器的ip改变了,集群会不会自动去调整
storage_ip_changed_auto_adjust = true

# storage sync file max delay seconds
# default value is 86400 seconds (one day)
# since V2.00
storage_sync_file_max_delay = 86400

# the max time of storage sync a file
# default value is 300 seconds
# since V2.00
storage_sync_file_max_time = 300

# if use a trunk file to store several small files
# default value is false
# since V3.00
use_trunk_file = false 

# the min slot size, should <= 4KB
# default value is 256 bytes
# since V3.00
slot_min_size = 256

# the max slot size, should > slot_min_size
# store the upload file to trunk file when it's size <=  this value
# default value is 16MB
# since V3.00
slot_max_size = 16MB

# the trunk file size, should >= 4MB
# default value is 64MB
# since V3.00
trunk_file_size = 64MB

# if create trunk file advancely
# default value is false
# since V3.06
trunk_create_file_advance = false

# the time base to create trunk file
# the time format: HH:MM
# default value is 02:00
# since V3.06
trunk_create_file_time_base = 02:00

# the interval of create trunk file, unit: second
# default value is 38400 (one day)
# since V3.06
trunk_create_file_interval = 86400

# the threshold to create trunk file
# when the free trunk file size less than the threshold, will create 
# the trunk files
# default value is 0
# since V3.06
trunk_create_file_space_threshold = 20G

# if check trunk space occupying when loading trunk free spaces
# the occupied spaces will be ignored
# default value is false
# since V3.09
# NOTICE: set this parameter to true will slow the loading of trunk spaces 
# when startup. you should set this parameter to true when neccessary.
trunk_init_check_occupying = false

# if ignore storage_trunk.dat, reload from trunk binlog
# default value is false
# since V3.10
# set to true once for version upgrade when your version less than V3.10
trunk_init_reload_from_binlog = false

# the min interval for compressing the trunk binlog file
# unit: second
# default value is 0, 0 means never compress
# FastDFS compress the trunk binlog when trunk init and trunk destroy
# recommand to set this parameter to 86400 (one day)
# since V5.01
trunk_compress_binlog_min_interval = 0

# 设置是否使用storage id 来代替ip地址
# 默认是false
# 从 V4.00 开始
use_storage_id = false

# 设置storage ids的文件名称, 可以设置为相对或绝对路径
# 从 V4.00 开始
storage_ids_filename = storage_ids.conf

# 设置存储服务器的id类型, 
# 可以是以下值:
## ip: 存储服务器的i地址
## id: 存储服务器的server id
# 该参数仅在设置了使用storage id 来代替ip地址时生效
# 默认配置是ip
# 从 V4.03 开始
id_type_in_filename = ip

# if store slave file use symbol link
# default value is false
# since V4.01
store_slave_file_use_link = false

# if rotate the error log every day
# default value is false
# since V4.02
rotate_error_log = false

# rotate error log time base, time format: Hour:Minute
# Hour from 0 to 23, Minute from 0 to 59
# default value is 00:00
# since V4.02
error_log_rotate_time=00:00

# rotate error log when the log file exceeds this size
# 0 means never rotates log file by log file size
# default value is 0
# since V4.02
rotate_error_log_size = 0

# 设置日志保存天数
# 0 标识不删除旧日志
log_file_keep_days = 0

# if use connection pool
# default value is false
# since V4.05
use_connection_pool = false

# connections whose the idle time exceeds this time will be closed
# unit: second
# default value is 3600
# since V4.05
connection_pool_max_idle_time = 3600

# HTTP port on this tracker server
http.server_port=8080

# check storage HTTP server alive interval seconds
# <= 0 for never check
# default value is 30
http.check_alive_interval=30

# check storage HTTP server alive type, values are:
#   tcp : connect to the storge server with HTTP port only, 
#        do not request and get response
#   http: storage check alive url must return http status 200
# default value is tcp
http.check_alive_type=tcp

# check storage HTTP server alive uri/url
# NOTE: storage embed HTTP server support uri: /status.html
http.check_alive_uri=/status.html
其中比较重要的,将原本的英文注释改成中文注释进行了标识。
这里我们要修改一下“存储数据或者日志的基本路径”,将base_path=/home/yuqing/fastdfs改为base_path=/home/jack/fastdfs,然后保存:

之后在home/jack下创建名为fastdfs的文件夹:


完成追踪服务器的准备工作后,我们就要启动追踪服务器,启动追踪服务器的文件就在之前安装好的的/usr/bin目录下的“fdfs_trackerd”,附带start指令就可以启动追踪服务器。
即使用/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start来启动 Tracker服务,如果想简便一些,可以使用ln -s 建立软链接:
ln -s /usr/bin/fdfs_trackerd /usr/local/bin
ln -s /usr/bin/stop.sh /usr/local/bin
ln -s /usr/bin/restart.sh /usr/local/bin
这时候我们就可以使用service fdfs_trackerd start来启动 Tracker服务了:

启动之后,我们使用netstat -unltp|grep fdfs或者lsof -i:22122来观察Tracker服务是不是在22122端口启动了:

出现上面的22122端口被正常监听后, Tracker服务就算安装和启动成功了!


二、存储服务器配置文件以及启动
在存储服务器192.168.195.130/131中,我们把storage.conf.sample模板复制并重命名一下:

在配置之前我们应该可以想到,对于存储服务器来说,最总要的两个配置无外乎是文件存储的位置,和配对的追踪服务器的信息。
然后使用vim打开追踪服务器的配置文件“storage.conf”,内容如下:
# 设置是否禁用该配置
# false是不禁用,true是禁用
disabled=false

# 设置该存储服务器所属的组的名称
group_name=group1

# 设置绑定这个主机的ip地址
bind_addr=

# 如果在连接到其他服务器时绑定此主机的地址
#(这个存储服务器作为客户端)
# true 代表使用上面的 "bind_addr" 配置地址
# false 代表对该主机的任何地址进行绑定
client_bind=true

# 存储服务器的端口
port=23000

# 连接的超时时间,默认是30秒
connect_timeout=30

# 网络连接的超时时间,默认是60秒
network_timeout=60

# 心跳检测时间,默认30秒,即每30秒向追踪服务器发送一次心跳,证明该服务运行状态正常
heart_beat_interval=30

# 每隔多少秒向追踪服务器汇报磁盘使用率
stat_report_interval=60

# 存储数据和日志的基本路径
base_path=/home/jack/fastdfs

# 支持的最大连接数
max_connections=256

# 文件上传和读取的buff数据存储区的大小
# 该参数最小不能低于 8KB
# 默认值为 64KB
# 从 V2.00 开始
buff_size = 256KB

# 可接受的线程数量
accept_threads=1

# 工作线程数量,要小于最大连接数,默认是4
work_threads=4

# if disk read / write separated
##  false for mixed read and write
##  true for separated read and write
# default value is true
# since V2.00
disk_rw_separated = true

# disk reader thread count per store base path
# for mixed read / write, this parameter can be 0
# default value is 1
# since V2.00
disk_reader_threads = 1

# disk writer thread count per store base path
# for mixed read / write, this parameter can be 0
# default value is 1
# since V2.00
disk_writer_threads = 1

# when no entry to sync, try read binlog again after X milliseconds
# must > 0, default value is 200ms
sync_wait_msec=50

# after sync a file, usleep milliseconds
# 0 for sync successively (never call usleep)
sync_interval=0

# storage sync start time of a day, time format: Hour:Minute
# Hour from 0 to 23, Minute from 0 to 59
sync_start_time=00:00

# storage sync end time of a day, time format: Hour:Minute
# Hour from 0 to 23, Minute from 0 to 59
sync_end_time=23:59

# write to the mark file after sync N files
# default value is 500
write_mark_file_freq=500

# 存储的路径统计, 默认值是 1
store_path_count=1

# 存储路径, 从0开始, 如果store_path0 不存在, 那么路径就为base_path
# 该路径一定是一个存在的路径
store_path0=/data/fdfs_storage/store
#store_path1=/home/yuqing/fastdfs2

# 设置多级目录下,每一个目录下可以有有多少子目录
# 可以设置1到256,默认值是256
subdir_count_per_path=256

# 追踪服务器的ip和端口,有多个时配置多个,存储服务器会主动连接追踪服务器
tracker_server=192.168.195.129:22122

#standard log level as syslog, case insensitive, value list:
### emerg for emergency
### alert
### crit for critical
### error
### warn for warning
### notice
### info
### debug
log_level=info

#unix group name to run this program, 
#not set (empty) means run by the group of current user
run_by_group=

#unix username to run this program,
#not set (empty) means run by current user
run_by_user=

# allow_hosts can ocur more than once, host can be hostname or ip address,
# "*" (only one asterisk) means match all ip addresses
# we can use CIDR ips like 192.168.5.64/26
# and also use range like these: 10.0.1.[0-254] and host[01-08,20-25].domain.com
# for example:
# allow_hosts=10.0.1.[1-15,20]
# allow_hosts=host[01-08,20-25].domain.com
# allow_hosts=192.168.5.64/26
allow_hosts=*

# the mode of the files distributed to the data path
# 0: round robin(default)
# 1: random, distributted by hash code
file_distribute_path_mode=0

# valid when file_distribute_to_path is set to 0 (round robin), 
# when the written file count reaches this number, then rotate to next path
# default value is 100
file_distribute_rotate_count=100

# call fsync to disk when write big file
# 0: never call fsync
# other: call fsync when written bytes >= this bytes
# default value is 0 (never call fsync)
fsync_after_written_bytes=0

# sync log buff to disk every interval seconds
# must > 0, default value is 10 seconds
sync_log_buff_interval=10

# sync binlog buff / cache to disk every interval seconds
# default value is 60 seconds
sync_binlog_buff_interval=10

# sync storage stat info to disk every interval seconds
# default value is 300 seconds
sync_stat_file_interval=300

# thread stack size, should >= 512KB
# default value is 512KB
thread_stack_size=512KB

# the priority as a source server for uploading file.
# the lower this value, the higher its uploading priority.
# default value is 10
upload_priority=10

# the NIC alias prefix, such as eth in Linux, you can see it by ifconfig -a
# multi aliases split by comma. empty value means auto set by OS type
# default values is empty
if_alias_prefix=

# if check file duplicate, when set to true, use FastDHT to store file indexes
# 1 or yes: need check
# 0 or no: do not check
# default value is 0
check_file_duplicate=0

# file signature method for check file duplicate
## hash: four 32 bits hash code
## md5: MD5 signature
# default value is hash
# since V4.01
file_signature_method=hash

# namespace for storing file indexes (key-value pairs)
# this item must be set when check_file_duplicate is true / on
key_namespace=FastDFS

# set keep_alive to 1 to enable persistent connection with FastDHT servers
# default value is 0 (short connection)
keep_alive=0

# you can use "#include filename" (not include double quotes) directive to 
# load FastDHT server list, when the filename is a relative path such as 
# pure filename, the base path is the base path of current/this config file.
# must set FastDHT server list when check_file_duplicate is true / on
# please see INSTALL of FastDHT for detail
##include /home/yuqing/fastdht/conf/fdht_servers.conf

# if log to access log
# default value is false
# since V4.00
use_access_log = false

# if rotate the access log every day
# default value is false
# since V4.00
rotate_access_log = false

# rotate access log time base, time format: Hour:Minute
# Hour from 0 to 23, Minute from 0 to 59
# default value is 00:00
# since V4.00
access_log_rotate_time=00:00

# if rotate the error log every day
# default value is false
# since V4.02
rotate_error_log = false

# rotate error log time base, time format: Hour:Minute
# Hour from 0 to 23, Minute from 0 to 59
# default value is 00:00
# since V4.02
error_log_rotate_time=00:00

# rotate access log when the log file exceeds this size
# 0 means never rotates log file by log file size
# default value is 0
# since V4.02
rotate_access_log_size = 0

# rotate error log when the log file exceeds this size
# 0 means never rotates log file by log file size
# default value is 0
# since V4.02
rotate_error_log_size = 0

# keep days of the log files
# 0 means do not delete old log files
# default value is 0
log_file_keep_days = 0

# if skip the invalid record when sync file
# default value is false
# since V4.02
file_sync_skip_invalid_record=false

# if use connection pool
# default value is false
# since V4.05
use_connection_pool = false

# connections whose the idle time exceeds this time will be closed
# unit: second
# default value is 3600
# since V4.05
connection_pool_max_idle_time = 3600

# use the ip address of this storage server if domain_name is empty,
# else this domain name will ocur in the url redirected by the tracker server
http.domain_name=

# the port of the web server on this storage server
http.server_port=8888


其中比较重要的,将原本的英文注释改成中文注释进行了标识。

这里我们要修改一下“存储数据和日志的基本路径”,将base_path=/home/yuqing/fastdfs和store_path0=/home/yuqing/fastdfs改为base_path=/data/fdfs_storage/base和store_path0=/data/fdfs_storage/store,追踪服务器设置为我们的追踪服务器的虚拟机ip和端口tracker_server=192.168.195.129:22122。然后130机器的group_name=group1,131机器的group_name=group2,然后保存。

之后在/目录下创建/data/fdfs_storage/base和/data/fdfs_storage/store文件夹:


使用/usr/bin/fdfs_storaged /etc/fdfs/storage.conf start来启动Storage服务,或使用ln -s 建立启动程序软链接:
ln -s /usr/bin/fdfs_storaged /usr/local/bin
ln -s /usr/bin/stop.sh /usr/local/bin
ln -s /usr/bin/restart.sh /usr/local/bin
这时候我们就可以使用service fdfs_storaged start来启动Storage服务了:

这里两种启动方式都没有反应,我们去/data/fdfs_storage/base下查看日志,看看有什么问题:

vim打开日志文件:

可以看到报了“No route to host”的错,解决方法是关闭两端的防火墙:
CentOS 6:
# servcie iptables stop                    -- 临时关闭防火墙
# chkconfig iptables off                    -- 永久关闭防火墙
CentOS 7:
# systemctl stop firewalld.service      -- 停止firewall
# systemctl disable firewalld.service    -- 禁止firewall开机启动

关闭防火墙后再次启动。
启动之后,我们使用netstat -unltp|grep fdfs或者lsof -i:23000来观察Storage服务是不是在23000端口启动了:

出现上面的23000端口被正常监听后,Storage服务就算安装和启动成功了!

至此,我们的追踪服务器和两个存储服务器搭建成功,符合了之前我们的架构预想:

下一篇将配置并使用客户端,来进行文件的上传和下载。
转载请注明出处:https://blog.csdn.net/acmman/article/details/80869948

猜你喜欢

转载自blog.csdn.net/u013517797/article/details/80869948