FastDFS分布式文件系统的安装及配置-单服务器版

FastDFS分布式文件系统的安装及配置

  • 安装环境及其配置目录
    一台服务器集成一个Tracker Server + 两个Storage Server

    			环境IP:192.168.127.6
    			Tracker Server base_path:/home/fastdfs/tracker        端口:22122 	http端口:9090
    			storage Server base_path:/home/fastdfs/fdfs_storage   端口:23000	http端口:8887  group:group2
    			storage Server base_path:/home/fastdfs/fdfs_storage1  端口:23001	http端口:8889  group:group3
    			
  • 			#软件安装包存储:
    			/usr/local/src
    			/etc/fdfs/*     #tracker,storage ·· 配置文件
    
    			#基本目录列表:
    			/home/fastdfs/tracker	   #创建tracker目录保存运行日志
    			/home/fastdfs/fdfs_storage  #创建Storage目录保存运行日志及其data数据
    			/home/fastdfs/fdfs_storage1 #创建Storage1目录保存运行日志及其data数据
    
    			命令汇总:mkdir -p /home/fastdfs/tracker;mkdir -p /home/fastdfs/fdfs_storage;mkdir -p /home/fastdfs/fdfs_storage1;
    
    			为方便查找目录,设置变量
    			# vi .bashrc
    			alias  worksrc='cd /usr/local/src'
    			配置生效
    			# source .bashrc
    			
  1. 安装FastDFS

    • 首先安装libevent,FastDFS 内部绑定了 libevent 作为 http 服务器

      				##卸载系统自带libevent,自带版本过低,安装fastdfs会出错
      				rpm -qa|grep libevent;yum remove libevent*
      
      				worksrc;
      				wget http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.19-stable.tar.gz;
      				tar -zxvf libevent-2.0.19-stable.tar.gz;
      				cd libevent-2.0.19-stable;
      				make clean;
      				./configure --prefix=/usr/local/libevent
      				make && make install;
      
      				##为libevent创建软链接到/lib库下,64位系统对应/lib64
      				ln -s /usr/local/libevent/lib/libevent-2.0.so.5 /usr/lib/libevent-2.0.so.5
      				ln -s /usr/local/libevent/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5
      
      				命令汇总:worksrc;wget http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.19-stable.tar.gz;tar -zxvf libevent-2.0.19-stable.tar.gz;cd libevent-2.0.19-stable;make clean;./configure --prefix=/usr/local/libevent;make && make install;cd ../
      				
    • 安装FastDFS的步骤

      				wget http://fastdfs.googlecode.com/files/FastDFS_v3.08.tar.gz
      				tar -zxvf FastDFS_v3.08.tar.gz
      				cd FastDFS
      				vim make.sh
      				#将 #WITH_HTTPD=1 修改成WITH_HTTPD=1 以支持 http
      				./make.sh C_INCLUDE_PATH=/usr/local/libevent/include LIBRARY_PATH=/usr/local/libevent/lib
      				./make.sh install
      				
  2. FastDFS的配置

    • 配置及启动Tracker Server,采用9090端口,和常用的80、8080常用http端口分开

      			#修改tracker.conf配置
      			vim /etc/fdfs/tracker.conf
      			base_path=/home/yuqing/fastdfs -> base_path=/home/fastdfs/tracker #日志目录
      			http.server_port=8080 -> http.server_port=9090       #http端口
      			##include http.conf -> #include http.conf            #开启自带http服务
      			reserved_storage_space = 4GB -> reserved_storage_space = 1GB
      
      			#启动Tracker Server
      			/usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf
      			
      			#启动过程中出现的错误
      			#./fdfs_trackerd: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory
      			#解决办法
      			ln -s /usr/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5
      			
    • #检查tracker是否启动成功,可以查看如下文件

      			vim /home/fastdfs/tracker/logs/trackerd.log
      			#[2012-08-26 19:01:30] INFO - FastDFS v3.08, base_path=/home/fastdfs/tracker, run_by_group=, run_by_user=, connect_timeout=30s, network_timeout=60s, port=22122, bind_addr=, max_connections=256, work_threads=4, store_lookup=0, store_group=, store_server=0, store_path=0, reserved_storage_space=1024MB, download_server=0, allow_ip_count=-1, sync_log_buff_interval=10s, check_active_interval=120s, thread_stack_size=64 KB, storage_ip_changed_auto_adjust=1, storage_sync_file_max_delay=86400s, storage_sync_file_max_time=300s, use_trunk_file=0, slot_min_size=256, slot_max_size=16 MB, trunk_file_size=64 MB, trunk_create_file_advance=0, trunk_create_file_time_base=02:00, trunk_create_file_interval=86400, trunk_create_file_space_threshold=20 GB
      			
      			#启动成功,加入开机启动
      			# vim /etc/rc.d/rc.local
      			/usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf
      			
    • 配置及启动存储服务(Storage Server),采用8887端口

      			#修改storage.conf配置
      			vim /etc/fdfs/storage.conf
      			group_name=group1 -> group_name=group2
      			port=23000     #the storage server port存储服务端口
      			base_path=/home/yuqing/fastdfs -> /home/fastdfs/fdfs_storage #日志目录及data数据
      			store_path0=/home/yuqing/fastdfs -> store_path0=/home/fastdfs/fdfs_storage
      			tracker_server=192.168.209.121:22122 -> tracker_server=192.168.127.6:22122
      			http.server_port=8888 -> http.server_port=8887 #http端口
      			##include http.conf ->#include http.conf     #开启自带http服务
      
      			#启动storage Server
      			/usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf
      
      			#接下来会出现很多mkdir data path,这是系统在创建数据目录
      			data path: /home/fastdfs/fdfs_storage/data, mkdir sub dir...
      			mkdir data path: 00 ...
      			mkdir data path: 01 ...
      			mkdir data path: 02 ...
      			mkdir data path: 03 ...
      			.......................
      			data path: /home/fastdfs/fdfs_storage/data, mkdir sub dir done.
      			
      			#启动成功,加入开机启动
      			# vim /etc/rc.d/rc.local
      			/usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf
      			

      配置及启动存储服务(Storage1 Server),采用8889端口

      			重新复制storage.conf 为storage1.conf
      			cp storage.conf storage1.conf
      			#修改storage1.conf配置
      			vim /etc/fdfs/storage1.conf
      			group_name=group2 -> group_name=group3
      			port=23000 -> port=23001  #the storage server port存储服务端口
      			base_path=/home/yuqing/fastdfs -> /home/fastdfs/fdfs_storage1 #日志目录及data数据
      			store_path0=/home/yuqing/fastdfs -> store_path0=/home/fastdfs/fdfs_storage1
      			tracker_server=192.168.209.121:22122 -> tracker_server=192.168.127.6:22122
      			http.server_port=8888->http.server_port=8889 #http端口
      			##include http.conf ->#include http.conf     #开启自带http服务
      
      			#启动storage Server
      			/usr/local/bin/fdfs_storaged /etc/fdfs/storage1.conf
      
      			#接下来会出现很多mkdir data path,这是系统在创建数据目录
      			data path: /home/fastdfs/fdfs_storage1/data, mkdir sub dir...
      			mkdir data path: 00 ...
      			mkdir data path: 01 ...
      			mkdir data path: 02 ...
      			mkdir data path: 03 ...
      			.......................
      			data path: /home/fastdfs/fdfs_storage1/data, mkdir sub dir done.
      			
      			#启动成功,加入开机启动
      			# vim /etc/rc.d/rc.local
      			/usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf
      			
  3. 测试及使用FastDFS

    • FastDFS之配置client

      		vim /etc/fdfs/client.conf
      		base_path=/home/yuqing/fastdfs-> base_path=/home/fastdfs/tracker
      		tracker_server=192.168.209.121:22122 -> tracker_server=192.168.127.6:22122
      		http.tracker_server_port=8080 ->http.tracker_server_port=9090
      		##include http.conf ->#include http.conf
      		
    • 		cd /usr/local/bin
      		vim aa.txt 增加内容:展示aa.txt文本数据   :wq
      		./fdfs_test /etc/fdfs/client.conf upload aa.txt
      		

      执行成功后会出现如下提示:

      		# ./fdfs_test /etc/fdfs/client.conf upload aa.txt
      		[2012-08-25 02:08:26] INFO - base_path=/home/fastdfs/tracker, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0
      		tracker_query_storage_store_list_without_group:
              		server 1. group_name=group2, ip_addr=192.168.127.6, port=23000
      		group_name=group2, ip_addr=192.168.127.6, port=23000
      		storage_upload_by_filename
      		group_name=group2, remote_filename=M00/00/00/wKh_BlA3wxql4hTXAAAAB8v-VvY710.txt
      		source ip address: 192.168.127.6
      		file timestamp=2012-08-25 02:08:26
      		file size=7
      		file crc32=3422443254
      		file url: http://192.168.127.6:9090/group2/M00/00/00/wKh_BlA3wxql4hTXAAAAB8v-VvY710.txt
      		storage_upload_slave_by_filename
      		group_name=group2, remote_filename=M00/00/00/wKh_BlA3wxql4hTXAAAAB8v-VvY710_big.txt
      		source ip address: 192.168.127.6
      		file timestamp=2012-08-25 02:08:26
      		file size=7
      		file crc32=3422443254
      		file url: http://192.168.127.6:9090/group2/M00/00/00/wKh_BlA3wxql4hTXAAAAB8v-VvY710_big.txt
      		
      		执行过程中可能出现防火墙封口:
      		# ERROR - file: tracker_proto.c, line: 420, connect to 192.168.127.6:22122 fail, errno: 113, error info: No route to host
      		解决:
      		#iptables -L;iptables -F
      		service iptables stop
      		
    • 测试下载文件
      在浏览器中,输入上图中的url地址, tracker server会自动重定向到存储文件的storage server,文件下载成功。至此,已经成功搭建了FastDFS,编写你自己的client来进行访问吧:

      		展示aa.txt文本数据
      		
    • 常规命令范例:

      		#重启tracker、storaged
      		/usr/local/bin/restart.sh  /usr/local/bin/fdfs_trackerd  /etc/fdfs/tracker.conf
      		/usr/local/bin/restart.sh  /usr/local/bin/fdfs_storaged  /etc/fdfs/storage.conf
      		
      		#重启tracker、storaged
      		/usr/local/bin/stop.sh  /usr/local/bin/fdfs_trackerd  /etc/fdfs/tracker.conf
      		/usr/local/bin/stop.sh  /usr/local/bin/fdfs_storaged  /etc/fdfs/storage.conf
      		
      		#监控storage
      		/usr/local/bin/fdfs_monitor /etc/fdfs/storage.conf
      		#如果存在多个多个组,只需要监控其中一个组,就能调出所有组的状态
      		
    • 端口查看:
相关文章
  1. 对Web静态资源缓存自动更新的思考与实践的总结
  2. 单机多git帐号的访问详解案例
  3. CentOS 6.5安装部署SVN 1.8.13
  4. php-redis扩展
  5. Redis安装部署
  6. gearman应用-分布式图库系统设计
本站版权
1、本站所有主题由该文章作者发表,该文章作者与尘埃享有文章相关版权
2、其他单位或个人使用、转载或引用本文时必须同时征得该文章作者和尘埃的同意
3、本帖部分内容转载自其它媒体,但并不代表本站赞同其观点和对其真实性负责
4、如本帖侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意
5、原文链接:
二维码
Posted in Cache/File存储, FastDFS分布式文件系统
Comments are closed.