Article / 文章中心

需要搭建一个高性能的文件系统?我推荐你试试它.....(中)

发布时间:2022-02-21 点击数:471
  • storage.conf


#这个装备文件是否 不收效(这儿笔者个人认为,改成是否收效会比较好),true代表不收效,false代表收效 disabled = false #组名 group_name = group1 #是否绑定ip,假如不填就代表所有的ip都供给服务,常用于服务器有多个ip但只希望一个ip供给服务 bind_addr = # 当指定bind_addr 本参数才有用 # storage作为客户端链接其他服务器时,是否绑定bind_addr client_bind = true # 本storage服务器的端口号 port = 23000 # 衔接超时时刻 针对套接字socket函数connect connect_timeout = 5 # storage server的网络超时时刻,单位为秒。接纳或发送数据时,假如在超时时刻后还不能发送或接纳数据,则本次网络通信失利。 network_timeout = 60 # 心跳距离时刻 单位为秒 heart_beat_interval = 30 # storage server向tracker server报告磁盘剩余空间的时刻距离,单位为秒 stat_report_interval = 60 # base_path目录地址,该目录有必要存在 base_path = /home/yuqing/fastdfs # 最大衔接数 max_connections = 1024 # 设置行列结点的buffer巨细。作业行列耗费的内存巨细 = buff_size * max_connections # 设置得大一些,体系整体功用会有所进步。 # 耗费的内存请不要超越体系物理内存巨细。别的,对于32位体系,请留意运用到的内存不要超越3GB buff_size = 256KB # 接纳恳求的线程数 accept_threads = 1 # 作业线程数 通常设置为cpu数 work_threads = 4 # 磁盘读写是否别离 disk_rw_separated = true # disk reader thread count per store path # for mixed read / write, this parameter can be 0 # default value is 1 # since V2.00 # 磁盘 读 线程数量 disk_reader_threads = 1 # 磁盘 写 线程数量 disk_writer_threads = 1 # 同步文件时 假如从binlog中没有读到要同步的文件,则休眠N毫秒后重新读取,0表明不休眠。 # 同步等待时刻 单位ms sync_wait_msec = 50 # 同步距离:同步上一个文件后,再同步下一个文件的时刻距离 单位为秒 sync_interval = 0 # 同步开始时刻 sync_start_time = 00:00 # 同步结束时刻 sync_end_time = 23:59 # 同步完N个文件后,把storage的mark文件同步到磁盘 # 注:假如mark文件内容没有变化 则不会同步 write_mark_file_freq = 500 # 磁盘恢复线程 disk_recovery_threads = 3 # 寄存文件途径个数 寄存文件时storage server支撑多个途径(能够理解为windows的分区)。 store_path_count = 1 # store_path_count装备多少,这儿就写多少个途径,留意:途径有必要存在。 store_path0 = /home/yuqing/fastdfs #store_path1 = /home/yuqing/fastdfs2 # FastDFS存储文件时 选用256*256结构的二级目录,这儿装备寄存文件的目录个数 subdir_count_per_path = 256 # tracker server的列表 有几个trackers server 就写几个 tracker_server = 192.168.209.121:22122 tracker_server = 192.168.209.122:22122 # 规范日志等级从小到大顺次:debuglog_level = info # 操作体系运转FastDFS的用户组,不填默认便是发动FastDFS的用户组 run_by_group= # 操作体系运转FastDFS的用户,不填默认便是发动FastDFS的用户 run_by_user = # 能够衔接到此Tracker Server的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 = * # 文件在data目录下涣散存储的战略 # 0:轮流,再一个目录下存储设置的文件数后,运用下一个目录进行寄存 # 1:随机,依据文件名对应的hash_code进行涣散存储(推荐) file_distribute_path_mode = 1 # 文件寄存个数到达本参数值时,运用下一个目录进行寄存 # 留意:只要当file_distribute_path_mode设置为1时,这个参数才有用 file_distribute_rotate_count = 100 # 当写入大文件时 每写入N个字节,调用一次体系函数fsync将内容强行同步到硬盘。0表明不调用fsync fsync_after_written_bytes = 0 # 同步或刷新日志到硬盘的时刻距离,单位为秒 # 留意:storage server 的日志信息不是直接写硬盘的,而是先写内存再写硬盘 sync_log_buff_interval = 1 # 同步binlog日志到硬盘的时刻距离 单位为秒 sync_binlog_buff_interval = 1 # 把storage的stat文件同步到硬盘的时刻距离 单位为秒· sync_stat_file_interval = 300 # 线程栈的巨细 # 线程栈越大,一个线程占用的体系资源就越多,能够发动的线程就越少。 thread_stack_size = 512KB # 上传优先级 值越小 优先级越高 和tracker.conf的storage_server = 2时的装备相对应 upload_priority = 10 #NIC别号前缀,比方Linux中的eth,能够经过ifconfig-a看到 #用逗号分隔的多个别号。空值表明按操作体系类型主动设置 #默认值为空 if_alias_prefix = # 检查文件是否重复,假如设置为true,则运用FastDHT去存储文件的索引(需求先装置FastDHT) # 1或许yes 需求检查 # 0或许no 不需求检查 check_file_duplicate = 0 # 文件去重时,文件内容的签名方法 # hash:4个hashcode # MD5:MD5 file_signature_method = hash # 当上个参数设置为1或许yes时,本参数有用 # FastDHT中的命名空间 key_namespace = FastDFS # 与FastDHT server的衔接方法 是否为耐久衔接 # 0 短链接 1 长衔接 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 # 是否将文件操作记载到access_log use_access_log = false # 是否定期切割access_log rotate_access_log = false # access_log切割时刻 access_log_rotate_time = 00:00 # 是否紧缩旧的access_log compress_old_access_log = false # 紧缩多久之前的access_log compress_access_log_days_before = 7 # 是否切割error_log rotate_error_log = false # 切割error_log的时刻 error_log_rotate_time = 00:00 # 是否紧缩error_log compress_old_error_log = false # 紧缩多久之前的error_log compress_error_log_days_before = 7 # 当access_log到达必定巨细时切割  0表明不按巨细切割 rotate_access_log_size = 0 # 当error_log到达必定巨细时切割 0表明不按巨细切割 rotate_error_log_size = 0 # 日志文件保存天数 0表明不删去 log_file_keep_days = 0 # 日志同步是否忽略无效的binlog记载 file_sync_skip_invalid_record = false # 是否运用线程池 use_connection_pool = true # 最大空闲衔接时刻,只要运用线程池这个装备才有用 connection_pool_max_idle_time = 3600 # 是否紧缩binlog日志 compress_binlog = true # 紧缩binlog日志的时刻 compress_binlog_time = 01:30 # 是否检查存储途径符号 check_store_path_mark = true # storage server上web server域名,通常仅针对单独布置的web server。这样URL中就能够经过域名方法来访问storage server上的文件了 # 参数为空表明运用ip访问 http.domain_name = # storage服务器端口 http.server_port = 8888


  • 需求装备tracker.conf和storage.conf


#tracker.conf需求装备如下几个当地 # Tracker端口号 port = 22122 # 根底目录 恳求后生成日志文件 这个目录需求手动创立 有必要保证存在 base_path = /home/fdfs/log/tracker


#storage.conf需求装备如下几个当地 # 组名 暂时保持默认 group_name = group1 # 存储节点端口号 port = 23000# 寄存存储节点日志的根底目录 这个目录需求手动创立 保证存在 base_path = /home/fdfs/log/storage # 文件需求寄存到哪个目录下 store_path0 = /home/fdfs/file/storage # 追寻器地址 tracker_server = 192.168.137.17:22122


  • 发动



咱们需求进行一些最小装备,来支撑FastDFS的发动。


首先是tracker.conf



# 1.绑定ip bind_addr = 192.168.137.3 # 2.设置端口 port = 22122 # 3.base目录 该目录需求手动创立,有必要保证存在 base_path = /WorkSpace/SoftwareData/fdfs/log/tracker


  • 然后是storage.conf


# 1.设置group_name group_name = group1 # 2.绑定ip bind_addr = 192.168.137.3 # 3.设置端口号 port = 23000 # bast_path 该途径有必要手动创立 base_path = /WorkSpace/SoftwareData/fdfs/log/storage # 装备storage存储文件的途径 store_path0 = /WorkSpace/SoftwareData/fdfs/data/storage0 # Tracker Server的ip tracker_server = 192.168.137.3


  • 装备好而且检查装备文件中的目录都存在之后,将装备文件拷贝到/etc/fdfs目录下,然后发动tracker和storage即可。


#发动指令:fdfs_trackerd/fdfs_storaged 装备文件 start #关闭指令:fdfs_trackerd/fdfs_storaged 装备文件 stop #重启指令:fdfs_trackerd/fdfs_storaged 装备文件 restart #最好不要运用kill -9 强制杀进程,这样会导致文件不同步 [root@localhost /]# fdfs_trackerd /etc/fdfs/tracker.conf start [root@localhost /]# fdfs_storaged /etc/fdfs/storage.conf start [root@localhost /]# ps -ef|grep fdfs root      1652     1  0 22:58 ?        00:00:00 fdfs_trackerd /etc/fdfs/tracker.conf start root      1661     1  0 22:58 ?        00:00:00 fdfs_storaged /etc/fdfs/storage.conf start root      1671  1515  0 22:58 pts/0    00:00:00 grep --color=auto fdfs


  • FastDFS的文件存储方法


发动FastDFS后,能够去到咱们刚才在storage.conf中装备的storage_path目录下,能够看到FastDFS在这个目录下创立了一个data目录,在data目录中创立了256*256个文件夹,用于涣散存储数据,这样能够进步查找文件的功率。这个便是上文中所说的,FastDFS解决IO功率的一种手段,将文件散布到每个目录下,类似于Java中的HashMap,经过文件的HashCode,敏捷判别文件的方位然后找到文件。


image.png


    • 至此咱们的FastDFS现已成功发动。
    1. 检查Linux上是否装置了GCC、libevent、libevent-devel


yum list installed|grep gcc yum list installed|grep libevent yum list installed|grep libevent-devel


    1. 假如没有装置,则需进行装置


yum install gcc libevent libevent-devel -y


  • 功用测验
    上文中咱们现已将FastDFS成功发动,而且能够看到发动后数据目录的变化。现在咱们就能够运用客户端来测验一下FastDFS的功用了。
    首先咱们需求装备一下客户端,在/etc/fdfs目录下找到client.conf装备文件,进行如下的最小装备:


#client.conf 需求改如下两个当地的装备 # 日志根底途径  必定要手动创立 不然无法运用client测验 base_path = /home/fdfs/log/client # 追寻器地址 tracker_server = 192.168.137.17:22122


  • 装备完毕后,需求在任意目录下,创立一个用于测验的文件。


[root@localhost /]# touch fdfstest [root@localhost /]# echo "A fdfs test file">>fdfstest [root@localhost /]# cat fdfstest A fdfs test file


  • 创立好文件并写入内容后,就能够对已布置的fdfs进行各种方法的测验了。
    首先是文件上传,FastDFS自带的客户端经过fdfs_test 装备文件 upload 需求上传的文件途径进行文件的上传,示例如下:


[root@localhost /]# fdfs_test /etc/fdfs/client.conf upload /fdfstest This is FastDFS client test program v6.06 Copyright (C) 2008, Happy Fish / YuQing FastDFS may be copied only under the terms of the GNU General Public License V3, which may be found in the FastDFS source kit. Please visit the FastDFS Home Page http://www.fastken.com/ for more detail. [2020-09-18 22:15:54] DEBUG - base_path=/WorkSpace/SoftwareData/fdfs/client, connect_timeout=5, 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 tracker_query_storage_store_list_without_group:  server 1. group_name=, ip_addr=192.168.137.3, port=23000 # storage信息 group_name=group1, ip_addr=192.168.137.3, port=23000 storage_upload_by_filename # group_name:文件上传到的组 # remote_filename:文件上传到的长途途径 M00代表第一个storage 也便是刚才装备的storage0,能够理解为分区,总的一个文件目录结构便是:组名/磁盘/目录/文件名 group_name=group1, remote_filename=M00/ED/49/wKiJA19kwRqAI_g6AAAAEbcXlKw7921454 source ip address: 192.168.137.3 file timestamp=2020-09-18 22:15:54 file size=17 file crc32=3071775916 # 在后期进行一些装备后,能够经过这个url直接访问文件 example file url: http://192.168.137.3/group1 storage_upload_slave_by_filename group_name=group1, remote_filename=M00/ED/49/wKiJA19kwRqAI_g6AAAAEbcXlKw7921454_big source ip address: 192.168.137.3 file timestamp=2020-09-18 22:15:54 file size=17 file crc32=3071775916 example file url: http://192.168.137.3/group1/M00/ED/49/wKiJA19kwRqAI_g6AAAAEbcXlKw7921454_big


  • 当执行完这条指令之后,咱们能够看到文件上传到的storage server的一些信息,例如group_name,ip,端口等,还能够看到咱们的文件上传到那个group,存在这个group的哪个途径下。
    本次咱们上传的文件经过返回信息,能够看到上传到group1下(由于咱们只要一个storage而且只设置了一个group),上传到的途径为M00/ED/49/wKiJA19kwRqAI_g6AAAAEbcXlKw7921454,那么就能够到这个目录下检查一下这个文件是否现已上传成功了。