centos的轻量应用服务器(centos7服务器)

FastDFS轻量分布式文件系统

FastDFS 是一款开源的轻量分布式文件系统 纯C实现,支持Linux及类Linux

不是通用的文件系统,需要通过专有的API接口访问。基于文件的key value pair存储系统,所以称为分布文件存储系统,适合4KB~500M的文件。

centos的轻量应用服务器(centos7服务器)

tracker server:跟踪服务器,主要做调度工作,在访问上起到负载均衡的作用。在内存中记录集群中group和storage server的状态信息,是连接client和storage server的枢纽。因为相关信息全部在内存中,tracker server的性能非常高,一个较大的集群(如上百个group)中有3台就足够了,storage server:在存储服务器 文件和文件属性 都保持在存储服务器上。

[root@db-slave ~]# git clone https://github.com/happyfish100/libfastcommon.git
[root@db-slave libfastcommon]# ./make.sh
[root@db-slave libfastcommon]# ./make.sh install
wget https://codeload.github.com/happyfish100/FastDFS/tar.gz/V5.05
[root@db-slave fastdfs-5.05]# tar xf fastdfs-5.05.tar.gz
[root@db-slave fastdfs-5.05]# cd fastdfs-5.05
[root@db-slave fastdfs-5.05]# ./make.sh
[root@db-slave fastdfs-5.05]# ./make.sh install
[root@db-slave fastdfs-5.05]# cd /etc/fdfs/
[root@db-slave fdfs]# ll
total 20
-rw-r--r-- 1 root root 1461 Jun 1 03:53 client.conf.sample
-rw-r--r-- 1 root root 7829 Jun 1 03:53 storage.conf.sample
-rw-r--r-- 1 root root 7102 Jun 1 03:53 tracker.conf.sample
[root@db-slave fdfs]#
[root@db-slave fdfs]# ll /usr/bin/fdfs_
fdfs_appender_test fdfs_crc32 fdfs_file_info fdfs_test fdfs_upload_appender
fdfs_appender_test1 fdfs_delete_file fdfs_monitor fdfs_test1 fdfs_upload_file
fdfs_append_file fdfs_download_file fdfs_storaged fdfs_trackerd
[root@db-slave fdfs]# ll /usr/bin/fdfs_

修改默认路径

[root@db-slave fdfs]# sed -i 's#/usr/local/bin/#/usr/bin/#g' /etc/init.d/fdfs_trackerd
[root@db-slave fdfs]# sed -i 's#/usr/local/bin/#/usr/bin/#g' /etc/init.d/fdfs_storaged
[root@db-slave fdfs]# grep usr /etc/init.d/fdfs_storaged
PRG=/usr/bin/fdfs_storaged
if [ ! -f /usr/bin/stop.sh ]; then
echo "file /usr/bin/stop.sh does not exist!"
if [ ! -f /usr/bin/restart.sh ]; then
echo "file /usr/bin/restart.sh does not exist!"
/usr/bin/stop.sh $CMD
/usr/bin/restart.sh $CMD &

配置文件

[root@db-slave fdfs]# pwd
/etc/fdfs
[root@db-slave fdfs]# ll
total 20
-rw-r--r-- 1 root root 1461 Jun 1 03:53 client.conf.sample
-rw-r--r-- 1 root root 7829 Jun 1 03:53 storage.conf.sample
-rw-r--r-- 1 root root 7102 Jun 1 03:53 tracker.conf.sample
[root@db-slave fdfs]#

[root@db-slave fdfs]# cp tracker.conf.sample tracker.conf
[root@db-slave fdfs]# ll
total 28
-rw-r--r-- 1 root root 1461 Jun 1 03:53 client.conf.sample
-rw-r--r-- 1 root root 7829 Jun 1 03:53 storage.conf.sample
-rw-r--r-- 1 root root 7102 Jun 1 04:03 tracker.conf
-rw-r--r-- 1 root root 7102 Jun 1 03:53 tracker.conf.sample
[root@db-slave fdfs]#

配置tracker.conf

分别创建如下目录

[root@db-slave ~]# mkdir /data/fdfs_tracker /data/fdfs_storage -p
[root@db-slave ~]# tree /data/
/data/
├── fdfs_storage
└── fdfs_tracker
2 directories, 0 files
[root@db-slave ~]#
[root@db-master /]# mkdir /data/fdfs_tracker /data/fdfs_storage -p
[root@db-master /]# tree /data/
/data/
├── fdfs_storage
└── fdfs_tracker
[root@db-slave fdfs]# vim tracker.conf
# the base path to store data and log files
#base_path=/home/yuqing/fastdfs
base_path=/data/fdfs_tracker #添加tracker目录
[root@db-slave fdfs]# /etc/init.d/fdfs_trackerd start
Starting FastDFS tracker server:
[root@db-slave fdfs]# netstat -tnl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22122 0.0.0.0:* LISTEN

安装另一台

[root@db-slave ~]# scp -r libfastcommon/ 192.168.157.62:~
[root@db-slave ~]# scp -r /home/jin/tools/fastdfs/fastdfs-5.05/ 192.168.157.62:~
分别进到libfastcommon和fastdfs目录执行./make.sh && ./make.sh install
修改路径
sed -i 's#/usr/local/bin/#/usr/bin/#g' /etc/init.d/fdfs_storaged
sed -i 's#/usr/local/bin/#/usr/bin/#g' /etc/init.d/fdfs_trackerd
cd /etc/fdfs
[root@db-master fdfs]# cp tracker.conf.sample tracker.conf
[root@db-master fdfs]# vim tracker.conf
# the base path to store data and log files
#base_path=/home/yuqing/fastdfs
base_path=/data/fdfs_tracker
[root@db-master fdfs]# /etc/init.d/fdfs_trackerd start
Starting FastDFS tracker server:
[root@db-master fdfs]# netstat -tnl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22122 0.0.0.0:* LI

ok了两个tracker服务器配置好了

配置storage服务器

[root@db-slave fastdfs]# cd /etc/fdfs/
[root@db-slave fdfs]# ll
total 28
-rw-r--r-- 1 root root 1461 Jun 1 03:53 client.conf.sample
-rw-r--r-- 1 root root 7829 Jun 1 03:53 storage.conf.sample
-rw-r--r-- 1 root root 7132 Jun 1 04:22 tracker.conf
-rw-r--r-- 1 root root 7102 Jun 1 03:53 tracker.conf.sample
[root@db-slave fdfs]# cp storage.conf.sample storage.conf
[root@db-slave fdfs]#
[root@db-slave fdfs]# vim storage.conf
# the base path to store data and log files
#base_path=/home/yuqing/fastdfs
base_path=/data/fdfs_storage/base #多建个base目录
# store_path#, based 0, if store_path0 not exists, it's value is base_path
# the paths must be exist
store_path0=/data/fdfs_storage/store #多建个store目录
#store_path1=/home/yuqing/fastdfs2
#
#修改IP地址
# tracker_server can ocur more than once, and tracker_server format is
# "host:port", host can be hostname or ip address
#tracker_server=192.168.209.121:22122
tracker_server=192.168.157.62:22122
tracker_server=192.168.157.67:22122
[root@db-slave fdfs_storage]# tree /data/
/data/
|-- fdfs_storage
| |-- base
| `-- store
`-- fdfs_tracker
|-- data
| |-- fdfs_trackerd.pid
| `-- storage_changelog.dat
`-- logs
`-- trackerd.log

同理配置另一台的storage

把配置文件拷过去即可然后创建base和store目录

[root@db-slave fdfs]# scp -r storage.conf 192.168.157.62:~
[root@db-master ~]# cd /etc/fdfs/
[root@db-master fdfs]# ls
client.conf.sample storage.conf.sample tracker.conf tracker.conf.sample
[root@db-master fdfs]# ll
total 28
-rw-r--r-- 1 root root 1461 May 31 19:57 client.conf.sample
-rw-r--r-- 1 root root 7829 May 31 19:57 storage.conf.sample
-rw-r--r-- 1 root root 7132 May 31 20:04 tracker.conf
-rw-r--r-- 1 root root 7102 May 31 19:57 tracker.conf.sample
[root@db-master fdfs]# mv /root/storage.conf ./
[root@db-master fdfs]# ll
total 36
-rw-r--r-- 1 root root 1461 May 31 19:57 client.conf.sample
-rw-r--r-- 1 root root 7941 May 31 20:25 storage.conf
-rw-r--r-- 1 root root 7829 May 31 19:57 storage.conf.sample
-rw-r--r-- 1 root root 7132 May 31 20:04 tracker.conf
-rw-r--r-- 1 root root 7102 May 31 19:57 tracker.conf.sample
[root@db-master fdfs]#

启动/etc/init.d/fdfs_storaged start

[root@db-slave fdfs]# lsof -i:23000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
fdfs_stor 6734 root 5u IPv4 282772 0t0 TCP *:inovaport1 (LISTEN)
fdfs_stor 6734 root 19u IPv4 282794 0t0 TCP 192.168.157.67:inovaport1->192.168.157.62:40548 (ESTABLISHED)
[root@db-slave fdfs]#
@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@fastDFS-client @-----> @ Track Server1
@ jave client api @<----- @ 192.168.157.67
@ @ @ Track Server2
@ @ @ 192.168.157.62
@ php client api @ @ Track Server....
@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@
| | | |
| | | |
@@@@ Storage Group1 @@@@@@@@@@@@@@Storage Group2 @@@@@@@
@
@ Storage1 Storage server N
@ 192.168.157.67
@
@ Storage2 Storage server N
@ 192.168.157.62
@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

客户端配置

[root@db-slave fdfs]# cp client.conf.sample client.conf
[root@db-slave fdfs]# vim client.conf
# the base path to store log files
base_path=/tmp
# tracker_server can ocur more than once, and tracker_server format is
# "host:port", host can be hostname or ip address
#tracker_server=192.168.0.197:22122
tracker_server=192.168.157.67:22122
tracker_server=192.168.157.62:22122

同理拷到另一台

[root@db-slave fdfs]# scp -r client.conf 192.168.157.62:~
root@192.168.157.62's password:
client.conf

安装好FastDFS后可以敲fdfs+tab键调出命令

[root@db-slave fdfs_storage]# fdfs_
fdfs_appender_test fdfs_crc32 fdfs_file_info fdfs_test fdfs_upload_appender
fdfs_appender_test1 fdfs_delete_file fdfs_monitor fdfs_test1 fdfs_upload_file
fdfs_append_file fdfs_download_file fdfs_storaged fdfs_trackerd
[root@db-slave fdfs_storage]# fdfs_
[root@db-slave fdfs]# fdfs_upload_file
Usage: fdfs_upload_file <config_file> <local_filename> [storage_ip:port] [store_path_index]
[root@db-slave fdfs]#
[root@db-slave fdfs]# fdfs_upload_file /etc/fdfs/client.conf /root/rep.sql
group1/M00/00/00/wKidPldNjfuAHSvdAAgOwi3pXeg698.sql #返回的file_id
[root@db-slave ~]# cd /data/fdfs_storage/store/data/
[root@db-slave data]# ls
00 09 12 1B 24 2D 36 3F 48 51 5A 63 6C 75 7E 87 90 99 A2 AB B4 BD C6 CF D8 E1 EA F3 FC
01 0A 13 1C 25 2E 37 40 49 52 5B 64 6D 76 7F 88 91 9A A3 AC B5 BE C7 D0 D9 E2 EB F4 FD
02 0B 14 1D 26 2F 38 41 4A 53 5C 65 6E 77 80 89 92 9B A4 AD B6 BF C8 D1 DA E3 EC F5 FE
03 0C 15 1E 27 30 39 42 4B 54 5D 66 6F 78 81 8A 93 9C A5 AE B7 C0 C9 D2 DB E4 ED F6 FF
04 0D 16 1F 28 31 3A 43 4C 55 5E 67 70 79 82 8B 94 9D A6 AF B8 C1 CA D3 DC E5 EE F7
05 0E 17 20 29 32 3B 44 4D 56 5F 68 71 7A 83 8C 95 9E A7 B0 B9 C2 CB D4 DD E6 EF F8
06 0F 18 21 2A 33 3C 45 4E 57 60 69 72 7B 84 8D 96 9F A8 B1 BA C3 CC D5 DE E7 F0 F9
07 10 19 22 2B 34 3D 46 4F 58 61 6A 73 7C 85 8E 97 A0 A9 B2 BB C4 CD D6 DF E8 F1 FA
08 11 1A 23 2C 35 3E 47 50 59 62 6B 74 7D 86 8F 98 A1 AA B3 BC C5 CE D7 E0 E9 F2 FB
[root@db-slave data]# cd 00/
[root@db-slave 00]# ls
00 09 12 1B 24 2D 36 3F 48 51 5A 63 6C 75 7E 87 90 99 A2 AB B4 BD C6 CF D8 E1 EA F3 FC
01 0A 13 1C 25 2E 37 40 49 52 5B 64 6D 76 7F 88 91 9A A3 AC B5 BE C7 D0 D9 E2 EB F4 FD
02 0B 14 1D 26 2F 38 41 4A 53 5C 65 6E 77 80 89 92 9B A4 AD B6 BF C8 D1 DA E3 EC F5 FE
03 0C 15 1E 27 30 39 42 4B 54 5D 66 6F 78 81 8A 93 9C A5 AE B7 C0 C9 D2 DB E4 ED F6 FF
04 0D 16 1F 28 31 3A 43 4C 55 5E 67 70 79 82 8B 94 9D A6 AF B8 C1 CA D3 DC E5 EE F7
05 0E 17 20 29 32 3B 44 4D 56 5F 68 71 7A 83 8C 95 9E A7 B0 B9 C2 CB D4 DD E6 EF F8
06 0F 18 21 2A 33 3C 45 4E 57 60 69 72 7B 84 8D 96 9F A8 B1 BA C3 CC D5 DE E7 F0 F9
07 10 19 22 2B 34 3D 46 4F 58 61 6A 73 7C 85 8E 97 A0 A9 B2 BB C4 CD D6 DF E8 F1 FA
08 11 1A 23 2C 35 3E 47 50 59 62 6B 74 7D 86 8F 98 A1 AA B3 BC C5 CE D7 E0 E9 F2 FB
[root@db-slave 00]# cd 00/
[root@db-slave 00]# ls
wKidPldNjfuAHSvdAAgOwi3pXeg698.sql
[root@db-slave 00]# md5sum wKidPldNjfuAHSvdAAgOwi3pXeg698.sql
388c5abc69c079b76ebe5ddfccf874eb wKidPldNjfuAHSvdAAgOwi3pXeg698.sql

下载(记下file_id)
[root@db-slave ~]# fdfs_download_file /etc/fdfs/client.conf group1/M00/00/00/wKidPldNjfuAHSvdAAgOwi3pXeg698.sql
[root@db-slave ~]# ll wKidPldNjfuAHSvdAAgOwi3pXeg698.sql
-rw-r--r-- 1 root root 528066 Jun 1 06:08 wKidPldNjfuAHSvdAAgOwi3pXeg698.sql
[root@db-slave ~]#
[root@db-slave ~]# md5sum wKidPldNjfuAHSvdAAgOwi3pXeg698.sql
388c5abc69c079b76ebe5ddfccf874eb wKidPldNjfuAHSvdAAgOwi3pXeg698.sql

上传和下载的MD5值相同

查看文件信息

[root@db-slave ~]# fdfs_file_info /etc/fdfs/client.conf group1/M00/00/00/wKidPldNjfuAHSvdAAgOwi3pXeg698.sql
source storage id: 0
source ip address: 192.168.157.62
file create timestamp: 2016-05-31 21:13:31
file size: 528066
file crc32: 770268648 (0x2DE95DE8)
[root@db-slave ~]#

删除

[root@db-slave ~]# fdfs_delete_file /etc/fdfs/client.conf group1/M00/00/00/wKidPldNjfuAHSvdAAgOwi3pXeg698.sql

追加

[root@db-slave ~]# fdfs_upload_appender /etc/fdfs/client.conf binlog.txt
group1/M00/00/00/wKidQ1dOD9WER13eAAAAANpNzf4531.txt

下载

[root@db-slave ~]# fdfs_download_file /etc/fdfs/client.conf group1/M00/00/00/wKidQ1dOD9WER13eAAAAANpNzf4531.txt
[root@db-slave ~]# ll
-rw-r--r-- 1 root root 7440 Jun 1 06:28 wKidQ1dOD9WER13eAAAAANpNzf4531.txt

查看集群情况

[root@db-slave ~]# fdfs_monitor /etc/fdfs/client.conf
[2016-06-01 06:33:57] DEBUG - base_path=/tmp, connect_timeout=30, network_timeout=60, tracker_server_count=2, 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=2, server_index=1
tracker server is 192.168.157.67:22122
group count: 1
Group 1:
group name = group1
disk total space = 11897 MB
disk free space = 6628 MB
trunk free space = 0 MB
storage server count = 2
active server count = 2
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 = 192.168.157.62
ip_addr = 192.168.157.62 ACTIVE
http domain =
version = 5.05
join time = 2016-05-31 20:30:14
up time = 2016-05-31 20:30:14
total storage = 11897 MB
free storage = 6628 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 = 192.168.157.67
if_trunk_server = 0
connection.alloc_count = 256
connection.current_count = 1
connection.max_count = 2
total_upload_count = 1
success_upload_count = 1
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 = 1
success_download_count = 1
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 = 528066
success_upload_bytes = 528066
total_append_bytes = 0
success_append_bytes = 0
total_modify_bytes = 0
success_modify_bytes = 0
stotal_download_bytes = 528066
success_download_bytes = 528066
total_sync_in_bytes = 7440
success_sync_in_bytes = 7440
total_sync_out_bytes = 0
success_sync_out_bytes = 0
total_file_open_count = 3
success_file_open_count = 3
total_file_read_count = 3
success_file_read_count = 3
total_file_write_count = 4
success_file_write_count = 4
last_heart_beat_time = 2016-06-01 06:33:34
last_source_update = 2016-05-31 21:13:30
last_sync_update = 2016-05-31 21:44:24
last_synced_timestamp = 2016-06-01 06:27:33 (0s delay)
Storage 2:
id = 192.168.157.67
ip_addr = 192.168.157.67 ACTIVE
http domain =
version = 5.05
join time = 2016-06-01 05:13:29
up time = 2016-06-01 05:13:29
total storage = 11897 MB
free storage = 6628 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 = 1
connection.max_count = 2
total_upload_count = 1
success_upload_count = 1
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 = 1
success_download_count = 1
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 = 7440
success_upload_bytes = 7440
total_append_bytes = 0
success_append_bytes = 0
total_modify_bytes = 0
success_modify_bytes = 0
stotal_download_bytes = 7440
success_download_bytes = 7440
total_sync_in_bytes = 528066
success_sync_in_bytes = 528066
total_sync_out_bytes = 0
success_sync_out_bytes = 0
total_file_open_count = 3
success_file_open_count = 3
total_file_read_count = 1
success_file_read_count = 1
total_file_write_count = 4
success_file_write_count = 4
last_heart_beat_time = 2016-06-01 06:33:32
last_source_update = 2016-06-01 06:27:33
last_sync_update = 2016-06-01 05:56:52
last_synced_timestamp = 2016-05-31 21:13:31 (-1s delay)
[root@db-slave ~]#

删除节点

fdfs_monitor /etc/fdfs/client.conf delete group1 192.168.157.67

group1/M00/00/00/wKidQ1dOD9WER13eAAAAANpNzf4531.txt

组名 磁盘 目录 文件名

你学废了吗

centos的轻量应用服务器(centos7服务器)

    

使用无须实名的阿里云国际版,添加 微信:ksuyun  备注:快速云

本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 cloud@ksuyun.com 举报,一经查实,本站将立刻删除。
如若转载,请注明出处:https://www.hanjifoods.com/748.html