1.CentOS7 FastDFS搭建
前面已下载好了要用到的工具集,下面就可以开始安装了:
如果安装过程中出现问题,可以下载我提供的,当前测试可以通过的工具包:
1.1 安装libfastcommon
安装成功后解压libfastcommon-master.zip
[root@sybmfw12-lnsy ]#unzip libfastcommon-master.zip
[root@sybmfw12-lnsy libfastcommon-1.0.36]# ll
drwxr-xr-x. 2 root root 4096 4月 5 2017 doc
-rw-r--r--. 1 root root 8005 4月 5 2017 HISTORY
-rw-r--r--. 1 root root 566 4月 5 2017 INSTALL
-rw-r--r--. 1 root root 1606 4月 5 2017 libfastcommon.spec
-rwxr-xr-x. 1 root root 3099 4月 5 2017 make.sh
drwxr-xr-x. 2 root root 4096 4月 5 2017 php-fastcommon
-rw-r--r--. 1 root root 2763 4月 5 2017 README
drwxr-xr-x. 3 root root 4096 11月 8 12:30 src
当我们./make.sh的时候可能会提示,gcc命令没有找到。
用yum安装gcc:
yum -y install gcc-c++
这个时候分别执行./make.sh和./make.sh install,正常情况是可以成功的。
libfastcommon默认会被安装到/usr/lib64/libfastcommon.so但是FastDFS的主程序却在/usr/local/lib目录下
这个时候我们就要建立一个软链接了,实际上也相当于windows上的快捷方式。
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
1.2安装FastDFS
解压FastDFS安装包
unzip fastdfs-5.11.zip
解压后看到:
[root@sybmfw12-lnsy fastdfs-5.11]# ll
总用量 136
drwxr-xr-x. 3 root root 4096 11月 8 12:32 client
drwxr-xr-x. 2 root root 4096 11月 8 12:32 common
drwxr-xr-x. 2 root root 4096 6月 3 21:09 conf
-rw-r--r--. 1 root root 35067 6月 3 21:09 COPYING-3_0.txt
-rw-r--r--. 1 root root 3171 6月 3 21:09 fastdfs.spec
-rw-r--r--. 1 root root 33100 6月 3 21:09 HISTORY
drwxr-xr-x. 2 root root 4096 6月 3 21:09 init.d
-rw-r--r--. 1 root root 7755 6月 3 21:09 INSTALL
-rwxr-xr-x. 1 root root 5548 6月 3 21:09 make.sh
drwxr-xr-x. 2 root root 4096 6月 3 21:09 php_client
-rw-r--r--. 1 root root 2380 6月 3 21:09 README.md
-rwxr-xr-x. 1 root root 1768 6月 3 21:09 restart.sh
-rwxr-xr-x. 1 root root 1680 6月 3 21:09 stop.sh
drwxr-xr-x. 4 root root 4096 11月 8 12:32 storage
drwxr-xr-x. 2 root root 4096 6月 3 21:09 test
drwxr-xr-x. 2 root root 4096 11月 8 12:32 track
进到刚解压的目录:`
cd fastdfs-5.11
./make.sh
./make.sh install
如果没有报错那么就成功了。安装log中会提示FastDFS安装到了/etc/fdfs目录下。
成功后查看安装目录:
[root@sybmfw12-lnsy fastdfs-5.11]# ll /etc/fdfs/
-rw-r--r--. 1 root root 1463 11月 8 12:52 client.conf.sample
-rw-r--r--. 1 root root 7938 11月 8 14:55 storage.conf.sample
-rw-r--r--. 1 root root 7397 11月 8 12:36 tracker.conf.sample
我们需要把这三个示例文件复制一份,去掉.sample
cp client.conf.sample client.conf
cp storage.conf.sample storage.conf
cp tracker.conf.sample tracker.conf
FastDFS安装结束。
1.3安装tracker
1.3.1创建tracker工作目录
这个目录可以自定义,用来保存tracker的data和log
根据个人习惯,我创建了下面的目录:
mkdir /opt/fastdfs_tracker
1.3.2 配置tracker
vim /etc/fdfs/tracker.conf
打开后重点关注下面4个配置:
1.disabled=false
2.port=22122 #默认端口号
3.base_path=/opt/fastdfs_tracker #我刚刚创建的目录
4.http.server_port=8080 #默认端口是8080
5.bind_addr= 0.0.0.0 监听地址
修改完的文件为:
disabled=false
bind_addr= 0.0.0.0
port=22122
connect_timeout=30
network_timeout=60
base_path=/opt/fastdfs_tracker
max_connections=512
accept_threads=1
work_threads=4
min_buff_size = 8KB
max_buff_size = 128KB
store_lookup=2
store_group=group2
store_server=0
store_path=0
download_server=0
reserved_storage_space = 10%
log_level=info
run_by_group=
run_by_user=
allow_hosts=*
sync_log_buff_interval = 10
check_active_interval = 120
thread_stack_size = 64KB
storage_ip_changed_auto_adjust = true
storage_sync_file_max_delay = 86400
storage_sync_file_max_time = 300
use_trunk_file = false
slot_min_size = 256
slot_max_size = 16MB
trunk_file_size = 64MB
trunk_create_file_advance = false
trunk_create_file_time_base = 02:00
trunk_create_file_interval = 86400
trunk_create_file_space_threshold = 20G
trunk_init_check_occupying = false
trunk_init_reload_from_binlog = false
trunk_compress_binlog_min_interval = 0
use_storage_id = false
storage_ids_filename = storage_ids.conf
id_type_in_filename = ip
store_slave_file_use_link = false
rotate_error_log = false
error_log_rotate_time=00:00
rotate_error_log_size = 0
log_file_keep_days = 0
use_connection_pool = false
connection_pool_max_idle_time = 3600
http.server_port=8080
http.check_alive_interval=30
http.check_alive_type=tcp
http.check_alive_uri=/status.html
1.3.3启动tracker
保存配置后启动tracker,命令如下:
service fdfs_trackerd start
成功后应该可以看到:
[root@sybmfw12-lnsy fastdfs-5.11]#service fdfs_trackerd start
Starting fdfs_trackerd (via systemctl): [ OK ]
进行刚刚创建的tracker目录,发现目录中多了data和log两个目录
[root@sybmfw12-lnsy fastdfs-5.11]# ll /opt/fastdfs_tracker/
drwxr-xr-x. 2 root root 4096 11月 8 15:01 data
drwxr-xr-x. 2 root root 4096 11月 8 12:37 logs
最后我们需要给tracker加入开机启动
echo "service fdfs_trackerd start" |tee -a /etc/rc.d/rc.local
查看一下tracker的端口监听情况
[root@sybmfw12-lnsy fastdfs-5.11]# ll /opt/
drwxr-xr-x. 4 root root 4096 11月 8 12:48 fastdfs_storage
drwxr-xr-x. 3 root root 4096 11月 8 15:02 fastdfs_storage_data
drwxr-xr-x. 4 root root 4096 11月 8 12:37 fastdfs_tracker
端口22122成功监听。
1.4 安装storage
storage的安装与tracker很类似。
1.4.1 为storage配置工作目录
与tracker不同的是,由于storage还需要一个目录用来存储数据,所以我另外多建了两个目录fastdfs_storage_data,fastdfs_storage
下面是我的目录结构:
[root@sybmfw12-lnsy fastdfs-5.11]# ll /opt/
drwxr-xr-x. 4 root root 4096 11月 8 12:48 fastdfs_storage
drwxr-xr-x. 3 root root 4096 11月 8 15:02 fastdfs_storage_data
drwxr-xr-x. 4 root root 4096 11月 8 12:37 fastdfs_tracker
1.4.2 修改storage配置文件
修改storage.conf
1.disabled=false
2.group_name=group1 #组名,根据实际情况修改
3.port=23000 #设置storage的端口号,默认是23000,同一个组的storage端口号必须一致
4.base_path=/opt/fastdfs_storage #设置storage数据文件和日志目录
5.store_path_count=1 #存储路径个数,需要和store_path个数匹配
6.store_path0=/opt/fastdfs_storage_data #实际文件存储路径
7.tracker_server=172.20.132.57:22122 #我CentOS7的ip地址
8.http.server_port=8888 #设置 http 端口号
修改完的文件为:
disabled=false
group_name=group1
bind_addr= 0.0.0.0
client_bind=true
port=23000
connect_timeout=30
network_timeout=60
heart_beat_interval=30
stat_report_interval=60
base_path=/opt/fastdfs_storage
max_connections=256
buff_size = 256KB
accept_threads=1
work_threads=4
disk_rw_separated = true
disk_reader_threads = 1
disk_writer_threads = 1
sync_wait_msec=50
sync_interval=0
sync_start_time=00:00
sync_end_time=23:59
write_mark_file_freq=500
store_path_count=1
store_path0=/opt/fastdfs_storage_data
subdir_count_per_path=256
tracker_server=172.20.132.57:22122
log_level=info
run_by_group=
run_by_user=
allow_hosts=*
file_distribute_path_mode=0
file_distribute_rotate_count=100
fsync_after_written_bytes=0
sync_log_buff_interval=10
sync_binlog_buff_interval=10
sync_stat_file_interval=300
thread_stack_size=512KB
upload_priority=10
if_alias_prefix=
check_file_duplicate=0
file_signature_method=hash
key_namespace=FastDFS
keep_alive=0
use_access_log = false
rotate_access_log = false
access_log_rotate_time=00:00
rotate_error_log = false
error_log_rotate_time=00:00
rotate_access_log_size = 0
rotate_error_log_size = 0
log_file_keep_days = 0
file_sync_skip_invalid_record=false
use_connection_pool = false
connection_pool_max_idle_time = 3600
http.domain_name=
http.server_port=8888
修改保存后创建软引用
ln -s /usr/bin/fdfs_storaged /usr/local/bin
1.4.3 启动storage
service fdfs_storaged start
Starting fdfs_storaged (via systemctl): [ OK ]
同样的,设置开机启动:
修改rc.local
echo "service fdfs_storaged start" |tee -a /etc/rc.d/rc.local
查看一下服务是否启动
[root@sybmfw12-lnsy fastdfs-5.11]#netstat -unltp | grep fdfs
tcp 0 0 0.0.0.0:22122 0.0.0.0:* LISTEN 2231/fdfs_trackerd
tcp 0 0 0.0.0.0:23000 0.0.0.0:* LISTEN 2323/fdfs_storaged
服务已正常启动。
1.4.4 校验整合
到这里,fastdfs的东西都已安装完成,最后我们还要确定一下,storage是否注册到了tracker中去。
查看命令:
/usr/bin/fdfs_monitor /etc/fdfs/storage.conf
成功后可以看到:
ip_addr = 172.20.132.57 (localhost.localdomain) ACTIVE
[root@sybmfw12-lnsy fastdfs-5.11]# /usr/bin/fdfs_monitor /etc/fdfs/storage.conf
[2017-11-08 18:05:55] DEBUG - base_path=/opt/fastdfs_storage, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0
server_count=1, server_index=0
tracker server is 172.20.132.57:22122
group count: 1
Group 1:
group name = group1
disk total space = 34140 MB
disk free space = 29282 MB
trunk free space = 0 MB
storage server count = 1
active server count = 1
storage server port = 23000
storage HTTP port = 8888
store path count = 1
subdir count per path = 256
current write server index = 0
current trunk file id = 0
Storage 1:
id = 172.20.132.57
ip_addr = 172.20.132.57 (sybmfw12-lnsy) ACTIVE
http domain =
version = 5.11
join time = 2017-11-08 12:48:05
up time = 2017-11-08 15:02:04
total storage = 34140 MB
free storage = 29282 MB
upload priority = 10
store_path_count = 1
subdir_count_per_path = 256
storage_port = 23000
storage_http_port = 8888
current_write_path = 0
source storage id =
if_trunk_server = 0
connection.alloc_count = 256
connection.current_count = 0
connection.max_count = 1
total_upload_count = 2
success_upload_count = 2
total_append_count = 0
success_append_count = 0
total_modify_count = 0
success_modify_count = 0
total_truncate_count = 0
success_truncate_count = 0
total_set_meta_count = 0
success_set_meta_count = 0
total_delete_count = 0
success_delete_count = 0
total_download_count = 0
success_download_count = 0
total_get_meta_count = 0
success_get_meta_count = 0
total_create_link_count = 0
success_create_link_count = 0
total_delete_link_count = 0
success_delete_link_count = 0
total_upload_bytes = 179368
success_upload_bytes = 179368
total_append_bytes = 0
success_append_bytes = 0
total_modify_bytes = 0
success_modify_bytes = 0
stotal_download_bytes = 0
success_download_bytes = 0
total_sync_in_bytes = 0
success_sync_in_bytes = 0
total_sync_out_bytes = 0
success_sync_out_bytes = 0
total_file_open_count = 2
success_file_open_count = 2
total_file_read_count = 0
success_file_read_count = 0
total_file_write_count = 2
success_file_write_count = 2
last_heart_beat_time = 2017-11-08 18:05:37
last_source_update = 2017-11-08 15:24:21
last_sync_update = 1970-01-01 08:00:00
last_synced_timestamp = 1970-01-01 08:00:00
网友评论