当前位置:   article > 正文

CentOS 7.2搭建FastDFS 分布式文件系统,实现高可用集群_centos搭建fastdfs服务器

centos搭建fastdfs服务器

分布式集群搭建结构

  • 双Tracker
  • 2组Group
  • 轮询存储策略
  • Keepalived+Nginx高可用
  • Nginx缓存
  • 4个存储节点

一、 集群规划清单

1.安装清单

软件名称版本百度云盘存放名称
FastDFS5.11fastdfs-5.11.zip
FastDFS-Nginx-modulefastdfs-nginx-module-master.zip
LibFastCommon1.0.36libfastcommon-1.0.36.zip
nginx1.10.3nginx-1.10.3.tar.gz
nginx-pure-cache2.3ngx_cache_purge-2.3.tar.gz

安装所需文件均上传到百度云盘,位置:FastDFS百度云盘

2.集群规划

虚拟机IP说明
Keepalived+Nginx1[Master]192.168.43.101Nginx Server 01
Keeepalived+Nginx[Backup]192.168.43.102Nginx Server 02
VIP192.168.43.150虚拟漂移IP
Tracker01192.168.43.70Tracker01服务器
Tracker02192.168.43.71Tracker02服务器
Storage01192.168.43.72Storage01服务器【group1】
Storage02192.168.43.73Storage02服务器【group1】
Storage03192.168.43.74Storage03服务器【group2】
Storage04192.168.43.75Storage04服务器【group2】

整体架构图如下图所示:

 图片来源:CSDN作者 liuyazhuang

二、集群安装

以下操作均在关闭所有节点防火墙进行的,请根据个人情况开启相关端口或关闭防火墙

1.安装LibFastCommon/FastDFS模块

执行节点 Tracker01、Tracker02、Storage01、Storage03、Storage04

[root@localhost fastDFS]# unzip libfastcommon-1.0.36.zip 

解压后目录如下:

  1. [root@localhost fastdfs-5.11]# ll
  2. [root@localhost libfastcommon-1.0.36]# ll
  3. 总用量 32
  4. drwxr-xr-x. 2 root root 117 45 2017 doc
  5. -rw-r--r--. 1 root root 8005 45 2017 HISTORY
  6. -rw-r--r--. 1 root root 566 45 2017 INSTALL
  7. -rw-r--r--. 1 root root 1606 45 2017 libfastcommon.spec
  8. -rwxr-xr-x. 1 root root 3099 45 2017 make.sh
  9. drwxr-xr-x. 2 root root 191 45 2017 php-fastcommon
  10. -rw-r--r--. 1 root root 2763 45 2017 README
  11. drwxr-xr-x. 3 root root 4096 117 11:21 src

安装C编译工具 gcc

[root@localhost fastdfs-5.11]# yum -y install gcc-c++
  • 安装装LibFastCommon

编译libfastcommon软件并安装

[root@localhost fastdfs-5.11]# ./make.sh  && ./make.sh install

为libcommon 创建软链接到/usr/local/lib目录下

  1. [root@localhost fastdfs-5.11]# ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
  2. [root@localhost fastdfs-5.11]# ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so
  3. [root@localhost fastdfs-5.11]# ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
  4. [root@localhost fastdfs-5.11]# ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so
  • 安装FastDFS
    解压安装包

[root@localhost fastDFS]# unzip fastdfs-5.11.zip 

进入解压目录并进行编译和安装

  1. [root@localhost fastDFS]# cd fastdfs-5.11/
  2. [root@localhost fastdfs-5.11]# ./make.sh && ./make.sh install

安装成功后,FastDFS会安装在/etc/fdfs目录下:

  1. [root@localhost fastdfs-5.11]# ll /etc/fdfs/
  2. 总用量 76
  3. -rw-r--r--. 1 root root 316 117 11:47 client.conf
  4. -rw-r--r--. 1 root root 1461 117 11:25 client.conf.sample
  5. -rw-r--r--. 1 root root 955 117 13:20 http.conf
  6. -rw-r--r--. 1 root root 31172 117 13:21 mime.types
  7. -rw-r--r--. 1 root root 3716 117 12:57 mod_fastdfs.conf
  8. -rw-r--r--. 1 root root 1278 117 11:40 storage.conf
  9. -rw-r--r--. 1 root root 7927 117 11:25 storage.conf.sample
  10. -rw-r--r--. 1 root root 105 117 11:25 storage_ids.conf.sample
  11. -rw-r--r--. 1 root root 1356 117 11:34 tracker.conf
  12. -rw-r--r--. 1 root root 7389 117 11:25 tracker.conf.sample

我们需要把这三个示例文件复制一份,去掉.sample

  1. [root@localhost fdfs]# cp client.conf.sample client.conf
  2. [root@localhost fdfs]# cp storage.conf.sample storage.conf
  3. [root@localhost fdfs]# cp tracker.conf.sample tracker.conf

FastDFS安装结束

2.安装Tracker并实现节点信息配置

执行节点 Tracker01、Tracker02

  • 创建tracker工作目录

此目录用于保存tracker 的data和log

[root@localhost fdfs]# mkdir /opt/fastdfs_tracker
  • 配置tracker

配置 /etc/fdfs目录下tracker.conf
主要实现以下5个配置内容:

  1. 1.disabled=false
  2. 2.port=22122 #默认端口号
  3. 3.base_path=/opt/fastdfs_tracker #我刚刚创建的目录
  4. 4.http.server_port=8080 #默认端口是8080
  5. 5.store_lookup=0 #采用轮询策略进行存储,0 轮询 1:始终定向到某个group 2:负载进行存储文件

完整tracker.conf 文件信息如下:

  1. disabled=false
  2. bind_addr= 0.0.0.0
  3. port=22122
  4. connect_timeout=30
  5. network_timeout=60
  6. base_path=/opt/fastdfs_tracker
  7. max_connections=512
  8. accept_threads=1
  9. work_threads=4
  10. min_buff_size = 8KB
  11. max_buff_size = 128KB
  12. store_lookup=0
  13. store_group=group2
  14. store_server=0
  15. store_path=0
  16. download_server=0
  17. reserved_storage_space = 10%
  18. log_level=info
  19. run_by_group=
  20. run_by_user=
  21. allow_hosts=*
  22. sync_log_buff_interval = 10
  23. check_active_interval = 120
  24. thread_stack_size = 64KB
  25. storage_ip_changed_auto_adjust = true
  26. storage_sync_file_max_delay = 86400
  27. storage_sync_file_max_time = 300
  28. use_trunk_file = false
  29. slot_min_size = 256
  30. slot_max_size = 16MB
  31. trunk_file_size = 64MB
  32. trunk_create_file_advance = false
  33. trunk_create_file_time_base = 02:00
  34. trunk_create_file_interval = 86400
  35. trunk_create_file_space_threshold = 20G
  36. trunk_init_check_occupying = false
  37. trunk_init_reload_from_binlog = false
  38. trunk_compress_binlog_min_interval = 0
  39. use_storage_id = false
  40. storage_ids_filename = storage_ids.conf
  41. id_type_in_filename = ip
  42. store_slave_file_use_link = false
  43. rotate_error_log = false
  44. error_log_rotate_time=00:00
  45. rotate_error_log_size = 0
  46. log_file_keep_days = 0
  47. use_connection_pool = false
  48. connection_pool_max_idle_time = 3600
  49. http.server_port=8080
  50. http.check_alive_interval=30
  51. http.check_alive_type=tcp
  52. http.check_alive_uri=/status.html

修改保存后创建软引用

[root@localhost fdfs]# ln -s /usr/bin/fdfs_storaged /usr/local/bin
  • 启动tracker,并加入开机启动项

[root@localhost fdfs]# service fdfs_trackerd start

将tracker加入开机启动项

[root@localhost fdfs]# echo "service fdfs_trackerd start" |tee -a /etc/rc.d/rc.local

3.安装Storage模块并实现配置

执行节点 Storage01、Storage02、Storage03、Storage04

  • 建立存储目录

在存储各节点建了两个目录fastdfs_storage_data,fastdfs_storage

  1. [root@localhost opt]# mkdir fastdfs_storage
  2. [root@localhost opt]# mkdir fastdfs_storage_data
  3. [root@localhost opt]# ll
  4. 总用量 0
  5. drwxr-xr-x. 4 root root 30 117 11:45 fastdfs_storage
  6. drwxr-xr-x. 3 root root 18 117 11:45 fastdfs_storage_data
  7. drwxr-xr-x. 4 root root 30 117 11:35 fastdfs_tracker
  • 修改存储节点目录下/etc/fdfs/storage.conf配置信息,具体如下:

  1. disabled=false #启用配置文件
  2. group_name=group1 #组名(第一组为 group1, 第二组为 group2
  3. port=23000 #storage 的端口号,同一个组的 storage 端口号必须相同
  4. base_path=/opt/fastdfs_storage #设置storage数据文件和日志目录
  5. store_path0=/opt/fastdfs_storage_data #实际文件存储路径
  6. store_path_count=1 #存储路径个数,需要和 store_path 个数匹配
  7. tracker_server=192.168.43.70:22122 #tracker 服务器的 IP 地址和端口
  8. tracker_server=192.168.43.70:22122 #多个 tracker 直接添加多条配置
  9. http.server_port=8888 #设置 http 端口号

完整配置信息如下:

  1. disabled=false
  2. group_name=group1
  3. bind_addr=
  4. client_bind=true
  5. port=23000
  6. connect_timeout=30
  7. network_timeout=60
  8. heart_beat_interval=30
  9. stat_report_interval=60
  10. base_path=/opt/fastdfs_storage
  11. max_connections=256
  12. buff_size = 256KB
  13. accept_threads=1
  14. work_threads=4
  15. disk_rw_separated = true
  16. disk_reader_threads = 1
  17. disk_writer_threads = 1
  18. sync_wait_msec=50
  19. sync_interval=0
  20. sync_start_time=00:00
  21. sync_end_time=23:59
  22. write_mark_file_freq=500
  23. store_path_count=1
  24. store_path0=/opt/fastdfs_storage_data
  25. subdir_count_per_path=256
  26. tracker_server=192.168.43.70:22122
  27. tracker_server=192.168.43.71:22122
  28. log_level=info
  29. run_by_group=
  30. run_by_user=
  31. allow_hosts=*
  32. file_distribute_path_mode=0
  33. file_distribute_rotate_count=100
  34. fsync_after_written_bytes=0
  35. sync_log_buff_interval=10
  36. sync_binlog_buff_interval=10
  37. sync_stat_file_interval=300
  38. thread_stack_size=512KB
  39. upload_priority=10
  40. if_alias_prefix=
  41. check_file_duplicate=0
  42. file_signature_method=hash
  43. key_namespace=FastDFS
  44. keep_alive=0
  45. use_access_log = false
  46. rotate_access_log = false
  47. access_log_rotate_time=00:00
  48. rotate_error_log = false
  49. error_log_rotate_time=00:00
  50. rotate_access_log_size = 0
  51. rotate_error_log_size = 0
  52. log_file_keep_days = 0
  53. file_sync_skip_invalid_record=false
  54. use_connection_pool = false
  55. connection_pool_max_idle_time = 3600
  56. http.domain_name=
  57. http.server_port=8888
  • 启动Storage
    各节点配置好信息好之后,启动Storage

[root@localhost fdfs]# service fdfs_storaged start

启动后查看日志情况

  1. [root@localhost fdfs]# fdfs_monitor /etc/fdfs/storage.conf
  2. [2018-01-20 16:56:48] DEBUG - base_path=/opt/fastdfs_storage, 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
  3. server_count=2, server_index=0
  4. tracker server is 192.168.43.70:22122
  5. group count: 2
  6. Group 1:
  7. group name = group1
  8. disk total space = 47073 MB
  9. disk free space = 35162 MB
  10. trunk free space = 0 MB
  11. storage server count = 2
  12. active server count = 2
  13. storage server port = 23000
  14. storage HTTP port = 8888
  15. store path count = 1
  16. subdir count per path = 256
  17. current write server index = 0
  18. current trunk file id = 0
  19. Storage 1:
  20. id = 192.168.43.72
  21. ip_addr = 192.168.43.72 (localhost.localdomain) ACTIVE
  22. http domain =
  23. version = 5.11
  24. join time = 2018-01-19 13:59:30
  25. up time = 2018-01-20 12:37:18
  26. total storage = 47073 MB
  27. free storage = 35162 MB
  28. upload priority = 10
  29. store_path_count = 1
  30. subdir_count_per_path = 256
  31. storage_port = 23000
  32. storage_http_port = 8888
  33. current_write_path = 0
  34. source storage id =
  35. if_trunk_server = 0
  36. connection.alloc_count = 256
  37. connection.current_count = 1
  38. connection.max_count = 1
  39. total_upload_count = 3
  40. success_upload_count = 3
  41. total_append_count = 0
  42. success_append_count = 0
  43. total_modify_count = 0
  44. success_modify_count = 0
  45. total_truncate_count = 0
  46. success_truncate_count = 0
  47. total_set_meta_count = 0
  48. success_set_meta_count = 0
  49. total_delete_count = 0
  50. success_delete_count = 0
  51. total_download_count = 0
  52. success_download_count = 0
  53. total_get_meta_count = 0
  54. success_get_meta_count = 0
  55. total_create_link_count = 0
  56. success_create_link_count = 0
  57. total_delete_link_count = 0
  58. success_delete_link_count = 0
  59. total_upload_bytes = 791904
  60. success_upload_bytes = 791904
  61. total_append_bytes = 0
  62. success_append_bytes = 0
  63. total_modify_bytes = 0
  64. success_modify_bytes = 0
  65. stotal_download_bytes = 0
  66. success_download_bytes = 0
  67. total_sync_in_bytes = 775234
  68. success_sync_in_bytes = 775234
  69. total_sync_out_bytes = 0
  70. success_sync_out_bytes = 0
  71. total_file_open_count = 4
  72. success_file_open_count = 4
  73. total_file_read_count = 0
  74. success_file_read_count = 0
  75. total_file_write_count = 8
  76. success_file_write_count = 8
  77. last_heart_beat_time = 2018-01-20 16:56:18
  78. last_source_update = 2018-01-19 19:34:55
  79. last_sync_update = 2018-01-19 15:28:56
  80. last_synced_timestamp = 2018-01-19 15:28:48 (0s delay)
  81. Storage 2:
  82. id = 192.168.43.73
  83. ip_addr = 192.168.43.73 ACTIVE
  84. http domain =
  85. version = 5.11
  86. join time = 2018-01-19 14:00:21
  87. up time = 2018-01-20 12:37:42
  88. total storage = 47073 MB
  89. free storage = 35166 MB
  90. upload priority = 10
  91. store_path_count = 1
  92. subdir_count_per_path = 256
  93. storage_port = 23000
  94. storage_http_port = 8888
  95. current_write_path = 0
  96. source storage id = 192.168.43.72
  97. if_trunk_server = 0
  98. connection.alloc_count = 256
  99. connection.current_count = 1
  100. connection.max_count = 1
  101. total_upload_count = 1
  102. success_upload_count = 1
  103. total_append_count = 0
  104. success_append_count = 0
  105. total_modify_count = 0
  106. success_modify_count = 0
  107. total_truncate_count = 0
  108. success_truncate_count = 0
  109. total_set_meta_count = 0
  110. success_set_meta_count = 0
  111. total_delete_count = 0
  112. success_delete_count = 0
  113. total_download_count = 0
  114. success_download_count = 0
  115. total_get_meta_count = 0
  116. success_get_meta_count = 0
  117. total_create_link_count = 0
  118. success_create_link_count = 0
  119. total_delete_link_count = 0
  120. success_delete_link_count = 0
  121. total_upload_bytes = 775234
  122. success_upload_bytes = 775234
  123. total_append_bytes = 0
  124. success_append_bytes = 0
  125. total_modify_bytes = 0
  126. success_modify_bytes = 0
  127. stotal_download_bytes = 0
  128. success_download_bytes = 0
  129. total_sync_in_bytes = 791904
  130. success_sync_in_bytes = 791904
  131. total_sync_out_bytes = 0
  132. success_sync_out_bytes = 0
  133. total_file_open_count = 4
  134. success_file_open_count = 4
  135. total_file_read_count = 0
  136. success_file_read_count = 0
  137. total_file_write_count = 8
  138. success_file_write_count = 8
  139. last_heart_beat_time = 2018-01-20 16:56:42
  140. last_source_update = 2018-01-19 15:28:48
  141. last_sync_update = 2018-01-19 19:34:59
  142. last_synced_timestamp = 2018-01-19 19:34:55 (0s delay)
  143. Group 2:
  144. group name = group2
  145. disk total space = 47073 MB
  146. disk free space = 35165 MB
  147. trunk free space = 0 MB
  148. storage server count = 2
  149. active server count = 2
  150. storage server port = 23000
  151. storage HTTP port = 8888
  152. store path count = 1
  153. subdir count per path = 256
  154. current write server index = 0
  155. current trunk file id = 0
  156. Storage 1:
  157. id = 192.168.43.74
  158. ip_addr = 192.168.43.74 ACTIVE
  159. http domain =
  160. version = 5.11
  161. join time = 2018-01-19 14:01:05
  162. up time = 2018-01-20 12:38:00
  163. total storage = 47073 MB
  164. free storage = 35165 MB
  165. upload priority = 10
  166. store_path_count = 1
  167. subdir_count_per_path = 256
  168. storage_port = 23000
  169. storage_http_port = 8888
  170. current_write_path = 0
  171. source storage id =
  172. if_trunk_server = 0
  173. connection.alloc_count = 256
  174. connection.current_count = 1
  175. connection.max_count = 1
  176. total_upload_count = 4
  177. success_upload_count = 4
  178. total_append_count = 0
  179. success_append_count = 0
  180. total_modify_count = 0
  181. success_modify_count = 0
  182. total_truncate_count = 0
  183. success_truncate_count = 0
  184. total_set_meta_count = 0
  185. success_set_meta_count = 0
  186. total_delete_count = 0
  187. success_delete_count = 0
  188. total_download_count = 0
  189. success_download_count = 0
  190. total_get_meta_count = 0
  191. success_get_meta_count = 0
  192. total_create_link_count = 0
  193. success_create_link_count = 0
  194. total_delete_link_count = 0
  195. success_delete_link_count = 0
  196. total_upload_bytes = 2107770
  197. success_upload_bytes = 2107770
  198. total_append_bytes = 0
  199. success_append_bytes = 0
  200. total_modify_bytes = 0
  201. success_modify_bytes = 0
  202. stotal_download_bytes = 0
  203. success_download_bytes = 0
  204. total_sync_in_bytes = 1550468
  205. success_sync_in_bytes = 1550468
  206. total_sync_out_bytes = 0
  207. success_sync_out_bytes = 0
  208. total_file_open_count = 6
  209. success_file_open_count = 6
  210. total_file_read_count = 0
  211. success_file_read_count = 0
  212. total_file_write_count = 15
  213. success_file_write_count = 15
  214. last_heart_beat_time = 2018-01-20 16:56:38
  215. last_source_update = 2018-01-19 19:35:40
  216. last_sync_update = 2018-01-19 15:28:53
  217. last_synced_timestamp = 2018-01-19 15:28:50 (-1s delay)
  218. Storage 2:
  219. id = 192.168.43.75
  220. ip_addr = 192.168.43.75 ACTIVE
  221. http domain =
  222. version = 5.11
  223. join time = 2018-01-19 14:01:27
  224. up time = 2018-01-20 12:38:20
  225. total storage = 47073 MB
  226. free storage = 35165 MB
  227. upload priority = 10
  228. store_path_count = 1
  229. subdir_count_per_path = 256
  230. storage_port = 23000
  231. storage_http_port = 8888
  232. current_write_path = 0
  233. source storage id = 192.168.43.74
  234. if_trunk_server = 0
  235. connection.alloc_count = 256
  236. connection.current_count = 1
  237. connection.max_count = 1
  238. total_upload_count = 2
  239. success_upload_count = 2
  240. total_append_count = 0
  241. success_append_count = 0
  242. total_modify_count = 0
  243. success_modify_count = 0
  244. total_truncate_count = 0
  245. success_truncate_count = 0
  246. total_set_meta_count = 0
  247. success_set_meta_count = 0
  248. total_delete_count = 0
  249. success_delete_count = 0
  250. total_download_count = 0
  251. success_download_count = 0
  252. total_get_meta_count = 0
  253. success_get_meta_count = 0
  254. total_create_link_count = 0
  255. success_create_link_count = 0
  256. total_delete_link_count = 0
  257. success_delete_link_count = 0
  258. total_upload_bytes = 1550468
  259. success_upload_bytes = 1550468
  260. total_append_bytes = 0
  261. success_append_bytes = 0
  262. total_modify_bytes = 0
  263. success_modify_bytes = 0
  264. stotal_download_bytes = 0
  265. success_download_bytes = 0
  266. total_sync_in_bytes = 2107770
  267. success_sync_in_bytes = 2107770
  268. total_sync_out_bytes = 0
  269. success_sync_out_bytes = 0
  270. total_file_open_count = 6
  271. success_file_open_count = 6
  272. total_file_read_count = 0
  273. success_file_read_count = 0
  274. total_file_write_count = 15
  275. success_file_write_count = 15
  276. last_heart_beat_time = 2018-01-20 16:56:23
  277. last_source_update = 2018-01-19 15:28:49
  278. last_sync_update = 2018-01-19 19:35:46
  279. last_synced_timestamp = 2018-01-19 19:35:40 (0s delay)

如果看到有2组Storage信息,则表示配置信息配置成功,并注册到Tracker中,查看日志启动情况

  1. [root@localhost fdfs]# tail -f /opt/fastdfs_storage/logs/storaged.log
  2. [2018-01-20 12:37:18] INFO - FastDFS v5.11, base_path=/opt/fastdfs_storage, store_path_count=1, subdir_count_per_path=256, group_name=group1, run_by_group=, run_by_user=, connect_timeout=30s, network_timeout=60s, port=23000, bind_addr=, client_bind=1, max_connections=256, accept_threads=1, work_threads=4, disk_rw_separated=1, disk_reader_threads=1, disk_writer_threads=1, buff_size=256KB, heart_beat_interval=30s, stat_report_interval=60s, tracker_server_count=2, sync_wait_msec=50ms, sync_interval=0ms, sync_start_time=00:00, sync_end_time=23:59, write_mark_file_freq=500, allow_ip_count=-1, file_distribute_path_mode=0, file_distribute_rotate_count=100, fsync_after_written_bytes=0, sync_log_buff_interval=10s, sync_binlog_buff_interval=10s, sync_stat_file_interval=300s, thread_stack_size=512 KB, upload_priority=10, if_alias_prefix=, check_file_duplicate=0, file_signature_method=hash, FDHT group count=0, FDHT server count=0, FDHT key_namespace=, FDHT keep_alive=0, HTTP server port=8888, domain name=, use_access_log=0, rotate_access_log=0, access_log_rotate_time=00:00, rotate_error_log=0, 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=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s
  3. [2018-01-20 12:37:18] INFO - file: storage_param_getter.c, line: 191, use_storage_id=0, id_type_in_filename=ip, storage_ip_changed_auto_adjust=1, store_path=0, reserved_storage_space=10.00%, 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, trunk_init_check_occupying=0, trunk_init_reload_from_binlog=0, trunk_compress_binlog_min_interval=0, store_slave_file_use_link=0
  4. [2018-01-20 12:37:18] INFO - file: storage_func.c, line: 257, tracker_client_ip: 192.168.43.72, my_server_id_str: 192.168.43.72, g_server_id_in_filename: 1210820800
  5. [2018-01-20 12:37:18] INFO - file: tracker_client_thread.c, line: 310, successfully connect to tracker server 192.168.43.71:22122, as a tracker client, my ip is 192.168.43.72
  6. [2018-01-20 12:37:18] INFO - file: tracker_client_thread.c, line: 1947, tracker server: #0. 192.168.43.70:22122, my_report_status: -1
  7. [2018-01-20 12:37:18] INFO - file: tracker_client_thread.c, line: 310, successfully connect to tracker server 192.168.43.70:22122, as a tracker client, my ip is 192.168.43.72
  8. [2018-01-20 12:37:18] INFO - file: tracker_client_thread.c, line: 1947, tracker server: #0. 192.168.43.70:22122, my_report_status: -1
  9. [2018-01-20 12:37:48] INFO - file: tracker_client_thread.c, line: 1263, tracker server 192.168.43.71:22122, set tracker leader: 192.168.43.71:22122
  10. [2018-01-20 12:37:48] INFO - file: storage_sync.c, line: 2732, successfully connect to storage server 192.168.43.73:23000

发现此时192.168.43.71作为Tracker的Leader。

  • 设置Storage开机自启动

[root@localhost fdfs]#  echo "service fdfs_storaged start" |tee -a /etc/rc.d/rc.local
  • 安装fastdfs-nginx-module、Nginx模块

安装Nginx模块所需的依赖环境

  1. [root@localhost fdfs]# yum -y install pcre pcre-devel
  2. [root@localhost fdfs]# yum -y install zlib zlib-devel
  3. [root@localhost fdfs]# yum -y install openssl openssl-devel

解压nginx和fastdfs-nginx-module

  1. [root@localhost fdfs]# tar -zxvf nginx-1.10.3.tar.gz
  2. [root@localhost fdfs]# unzip fastdfs-nginx-module-master.zip

进入Nginx解压目录进行编译安装

[root@localhost nginx-1.10.3]# ./configure --prefix=/usr/local/nginx --add-module=/home/zhangyongliang/apps/fastdfs-nginx-module-master/src #解压后fastdfs-nginx-module所在的位置

安装成功后,nginx会安装在/usr/local/nginx,安装后查看

  1. [root@localhost src]# ll /usr/local/nginx/
  2. 总用量 8
  3. drwx------. 2 nobody root 6 117 13:23 client_body_temp
  4. drwxr-xr-x. 2 root root 4096 117 13:17 conf
  5. drwx------. 2 nobody root 6 117 13:23 fastcgi_temp
  6. drwxr-xr-x. 2 root root 40 117 13:17 html
  7. drwxr-xr-x. 2 root root 58 117 13:49 logs
  8. -rw-r--r--. 1 root root 1156 117 13:29 nginx.conf
  9. drwx------. 2 nobody root 6 117 13:23 proxy_temp
  10. drwxr-xr-x. 2 root root 19 117 13:17 sbin
  11. drwx------. 2 nobody root 6 117 13:23 scgi_temp
  12. drwx------. 2 nobody root 6 117 13:23 uwsgi_temp

安装成功后,nginx尚未运行时,nginx文件夹没有临时文件夹,例如fastcgi_temp这些文件。


复制 fastdfs-nginx-module 源码中的配置文件到/etc/fdfs 目录, 并修改

  1. [root@localhost src]# cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
  2. [root@localhost src]# vi /etc/fdfs/mod_fastdfs.conf

  1. (1)第1组 Storage 的 mod_fastdfs.conf 配置如下:
  2. connect_timeout=10
  3. base_path=/opt/fastdfs_storage
  4. tracker_server=192.168.1.131:22122
  5. tracker_server=192.168.1.132:22122
  6. storage_server_port=23000
  7. group_name=group1
  8. url_have_group_name = true
  9. store_path0=/opt/fastdfs_storage_data
  10. group_count = 2
  11. [group1]
  12. group_name=group1
  13. storage_server_port=23000
  14. store_path_count=1
  15. store_path0=/opt/fastdfs_storage_data
  16. [group2]
  17. group_name=group2
  18. storage_server_port=23000
  19. store_path_count=1
  20. store_path0=/opt/fastdfs_storage_data
  21. (2)第2组 Storage 的 mod_fastdfs.conf 配置与第一组配置只有 group_name 不同:
  22. group_name=group2

完整信息如下:

  1. # connect timeout in seconds
  2. # default value is 30s
  3. connect_timeout=2
  4. # network recv and send timeout in seconds
  5. # default value is 30s
  6. network_timeout=30
  7. # the base path to store log files
  8. base_path=/opt/fastdfs_storage
  9. # if load FastDFS parameters from tracker server
  10. # since V1.12
  11. # default value is false
  12. load_fdfs_parameters_from_tracker=true
  13. # storage sync file max delay seconds
  14. # same as tracker.conf
  15. # valid only when load_fdfs_parameters_from_tracker is false
  16. # since V1.12
  17. # default value is 86400 seconds (one day)
  18. storage_sync_file_max_delay = 86400
  19. # if use storage ID instead of IP address
  20. # same as tracker.conf
  21. # valid only when load_fdfs_parameters_from_tracker is false
  22. # default value is false
  23. # since V1.13
  24. use_storage_id = false
  25. # specify storage ids filename, can use relative or absolute path
  26. # same as tracker.conf
  27. # valid only when load_fdfs_parameters_from_tracker is false
  28. # since V1.13
  29. storage_ids_filename = storage_ids.conf
  30. # FastDFS tracker_server can ocur more than once, and tracker_server format is
  31. # "host:port", host can be hostname or ip address
  32. # valid only when load_fdfs_parameters_from_tracker is true
  33. tracker_server=192.168.43.70:22122
  34. tracker_server=192.168.43.71:22122
  35. # the port of the local storage server
  36. # the default value is 23000
  37. storage_server_port=23000
  38. # the group name of the local storage server
  39. group_name=group1
  40. # if the url / uri including the group name
  41. # set to false when uri like /M00/00/00/xxx
  42. # set to true when uri like ${group_name}/M00/00/00/xxx, such as group1/M00/xxx
  43. # default value is false
  44. url_have_group_name = true
  45. # path(disk or mount point) count, default value is 1
  46. # must same as storage.conf
  47. store_path_count=1
  48. # store_path#, based 0, if store_path0 not exists, it's value is base_path
  49. # the paths must be exist
  50. # must same as storage.conf
  51. store_path0=/opt/fastdfs_storage_data
  52. #store_path1=/home/yuqing/fastdfs1
  53. # standard log level as syslog, case insensitive, value list:
  54. ### emerg for emergency
  55. ### alert
  56. ### crit for critical
  57. ### error
  58. ### warn for warning
  59. ### notice
  60. ### info
  61. ### debug
  62. log_level=info
  63. # set the log filename, such as /usr/local/apache2/logs/mod_fastdfs.log
  64. # empty for output to stderr (apache and nginx error_log file)
  65. log_filename=
  66. # response mode when the file not exist in the local file system
  67. ## proxy: get the content from other storage server, then send to client
  68. ## redirect: redirect to the original storage server (HTTP Header is Location)
  69. response_mode=proxy
  70. # the NIC alias prefix, such as eth in Linux, you can see it by ifconfig -a
  71. # multi aliases split by comma. empty value means auto set by OS type
  72. # this paramter used to get all ip address of the local host
  73. # default values is empty
  74. if_alias_prefix=
  75. # use "#include" directive to include HTTP config file
  76. # NOTE: #include is an include directive, do NOT remove the # before include
  77. #include http.conf
  78. # if support flv
  79. # default value is false
  80. # since v1.15
  81. flv_support = true
  82. # flv file extension name
  83. # default value is flv
  84. # since v1.15
  85. flv_extension = flv
  86. # set the group count
  87. # set to none zero to support multi-group on this storage server
  88. # set to 0 for single group only
  89. # groups settings section as [group1], [group2], ..., [groupN]
  90. # default value is 0
  91. # since v1.14
  92. group_count = 2
  93. # group settings for group #1
  94. # since v1.14
  95. # when support multi-group on this storage server, uncomment following section
  96. [group1]
  97. group_name=group1
  98. storage_server_port=23000
  99. store_path_count=1
  100. store_path0=/opt/fastdfs_storage_data
  101. [group2]
  102. group_name=group2
  103. storage_server_port=23000
  104. store_path_count=1
  105. store_path0=/opt/fastdfs_storage_data
  106. # group settings for group #2
  107. # since v1.14
  108. # when support multi-group, uncomment following section as neccessary
  109. #[group2]
  110. #group_name=group2
  111. #storage_server_port=23000
  112. #store_path_count=1
  113. #store_path0=/home/yuqing/fastdfs

复制 FastDFS 安装目录的部分配置文件到/etc/fdfs 目录

  1. [root@localhost conf]# pwd
  2. /home/zhangyongliang/apps/fastdfs-5.11/conf
  3. [root@localhost conf]# cp http.conf mime.types /etc/fdfs/

创建M00至storage存储目录的符号连接:

ln  -s  /opt/fastdfs_storage_data/data/ /opt/fastdfs_storage_data/data/M00

配置 Nginx, 简洁版 nginx 配置样例

  1. # vi /usr/local/nginx/conf/nginx.conf
  2. user root;
  3. worker_processes 1;
  4. events {
  5. worker_connections 1024;
  6. }
  7. http {
  8. include mime.types;
  9. default_type application/octet-stream;
  10. sendfile on;
  11. keepalive_timeout 65;
  12. server {
  13. listen 8888;
  14. server_name localhost;
  15. location ~/group([0-9])/M00 {
  16. #alias /fastdfs/storage/data;
  17. ngx_fastdfs_module;
  18. }
  19. error_page 500 502 503 504 /50x.html;
  20. location = /50x.html {
  21. root html;
  22. }
  23. }
  24. }

注意、 说明:

8888 端口值是要与/etc/fdfs/storage.conf 中的 http.server_port=8888 相对应,因为 http.server_port 默认为 8888,如果想改成 80,则要对应修改过来。

重新启动各节点的Nginx服务

[root@localhost conf]#/usr/local/nginx/sbin/nginx -s reload

4.文件上传测试

执行节点Tracker01、Tracker02

修改 Tracker 服务器中的客户端配置文件

  1. # vi /etc/fdfs/client.conf
  2. base_path=/fastdfs/tracker
  3. tracker_server=192.168.43.70:22122
  4. tracker_server=192.168.43.71:22122

执行如下文件上传命令

  1. [root@localhost zhangyongliang]# fdfs_upload_file /etc/fdfs/client.conf P71022-205803.jpg
  2. group1/M00/00/00/wKgrSFpjC26AH1g2AAvUQrxXbkA557.jpg
  3. [root@localhost zhangyongliang]# fdfs_upload_file /etc/fdfs/client.conf P71022-205803.jpg
  4. group2/M00/00/00/wKgrSlpjC3aAARrXAAvUQrxXbkA048.jpg

进行2次上传后,发现文件被均衡分到2个group。

5.Tracker安装Nginx、 ngx_cache_purge 模块

  • 安装编译 Nginx 所需的依赖包

[root@localhost zhangyongliang]# yum install gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl openssl-devel  

解压Nginx和ngx_cache_pure模块

  1. [root@localhost apps]# tar ngx_cache_purge-2.3.tar.gz
  2. [root@localhost apps]# tar nginx-1.10.3.tar.gz

编译安装 Nginx(添加 ngx_cache_purge 模块)

  1. [root@localhost apps]# cd nginx-1.13.0
  2. [root@localhost nginx-1.13.0# ./configure --prefix=/usr/local/nginx --add-module=/usr/local/src/ngx_cache_purge-2.3
  3. [root@localhost nginx-1.13.0]# make && make install

配置 Nginx, 设置负载均衡以及缓存

  1. # vi /usr/local/nginx/conf/nginx.conf
  2. #user nobody;
  3. worker_processes 1;
  4. #error_log logs/error.log;
  5. #error_log logs/error.log notice;
  6. #error_log logs/error.log info;
  7. #pid logs/nginx.pid;
  8. events {
  9. worker_connections 1024;
  10. }
  11. http {
  12. include mime.types;
  13. default_type application/octet-stream;
  14. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  15. # '$status $body_bytes_sent "$http_referer" '
  16. # '"$http_user_agent" "$http_x_forwarded_for"';
  17. #access_log logs/access.log main;
  18. sendfile on;
  19. tcp_nopush on;
  20. #tcp_nopush on;
  21. #keepalive_timeout 0;
  22. keepalive_timeout 65;
  23. #gzip on;
  24. #设置缓存
  25. server_names_hash_bucket_size 128;
  26. client_header_buffer_size 32k;
  27. large_client_header_buffers 4 32k;
  28. client_max_body_size 300m;
  29. proxy_redirect off;
  30. proxy_set_header Host $http_host;
  31. proxy_set_header X-Real-IP $remote_addr;
  32. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  33. proxy_connect_timeout 90;
  34. proxy_send_timeout 90;
  35. proxy_read_timeout 90;
  36. proxy_buffer_size 16k;
  37. proxy_buffers 4 64k;
  38. proxy_busy_buffers_size 128k;
  39. proxy_temp_file_write_size 128k;
  40. #设置缓存存储路径,存储方式,分别内存大小,磁盘最大空间,缓存期限
  41. proxy_cache_path /opt/fastdfs_tracker/proxy_cache levels=1:2
  42. keys_zone=http-cache:200m max_size=1g inactive=30d;
  43. proxy_temp_path /opt/fastdfs_tracker/tmp;
  44. #group1的服务设置
  45. upstream fdfs_group1 {
  46. server 192.168.43.72:8888 weight=1 max_fails=2 fail_timeout=30s;
  47. server 192.168.43.73:8888 weight=1 max_fails=2 fail_timeout=30s;
  48. }
  49. #group2的服务设置
  50. upstream fdfs_group2 {
  51. server 192.168.43.74:8888 weight=1 max_fails=2 fail_timeout=30s;
  52. server 192.168.43.75:8888 weight=1 max_fails=2 fail_timeout=30s;
  53. }
  54. server {
  55. listen 8000;
  56. server_name localhost;
  57. #charset koi8-r;
  58. #access_log logs/host.access.log main;
  59. #group1的负载均衡配置
  60. location /group1/M00 {
  61. proxy_next_upstream http_502 http_504 error timeout invalid_header;
  62. proxy_cache http-cache;
  63. proxy_cache_valid 200 304 12h;
  64. proxy_cache_key $uri$is_args$args;
  65. #对应group1的服务设置
  66. proxy_pass http://fdfs_group1;
  67. expires 30d;
  68. }
  69. location /group2/M00 {
  70. proxy_next_upstream http_502 http_504 error timeout invalid_header;
  71. proxy_cache http-cache;
  72. proxy_cache_valid 200 304 12h;
  73. proxy_cache_key $uri$is_args$args;
  74. #对应group2的服务设置
  75. proxy_pass http://fdfs_group2;
  76. expires 30d;
  77. }
  78. location ~/purge(/.*) {
  79. allow 127.0.0.1;
  80. allow 192.168.43.0/24;
  81. deny all;
  82. proxy_cache_purge http-cache $1$is_args$args;
  83. }
  84. location / {
  85. root html;
  86. index index.html index.htm;
  87. }
  88. #error_page 404 /404.html;
  89. # redirect server error pages to the static page /50x.html
  90. #
  91. error_page 500 502 503 504 /50x.html;
  92. location = /50x.html {
  93. root html;
  94. }
  95. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  96. #
  97. #location ~ \.php$ {
  98. # proxy_pass http://127.0.0.1;
  99. #}
  100. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  101. #
  102. #location ~ \.php$ {
  103. # root html;
  104. # fastcgi_pass 127.0.0.1:9000;
  105. # fastcgi_index index.php;
  106. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  107. # include fastcgi_params;
  108. #}
  109. # deny access to .htaccess files, if Apache's document root
  110. # concurs with nginx's one
  111. #
  112. #location ~ /\.ht {
  113. # deny all;
  114. #}
  115. }
  116. # another virtual host using mix of IP-, name-, and port-based configuration
  117. #
  118. #server {
  119. # listen 8000;
  120. # listen somename:8080;
  121. # server_name somename alias another.alias;
  122. # location / {
  123. # root html;
  124. # index index.html index.htm;
  125. # }
  126. #}
  127. # HTTPS server
  128. #
  129. #server {
  130. # listen 443 ssl;
  131. # server_name localhost;
  132. # ssl_certificate cert.pem;
  133. # ssl_certificate_key cert.key;
  134. # ssl_session_cache shared:SSL:1m;
  135. # ssl_session_timeout 5m;
  136. # ssl_ciphers HIGH:!aNULL:!MD5;
  137. # ssl_prefer_server_ciphers on;
  138. # location / {
  139. # root html;
  140. # index index.html index.htm;
  141. # }
  142. #}
  143. }

根据Nginx配置,创建对应目录下的文件夹

  1. [root@localhost fastdfs_tracker]# mkdir proxy_cache tmp
  2. [root@localhost fastdfs_tracker]# ll
  3. 总用量 0
  4. drwxr-xr-x. 2 root root 178 120 12:37 data
  5. drwxr-xr-x. 2 root root 26 119 12:01 logs
  6. drwxr-xr-x. 7 nobody root 51 119 19:35 proxy_cache
  7. drwxr-xr-x. 2 nobody root 6 119 19:35 tmp

重启Nginx进行访问测试

  1. 重启 Nginx
  2. [root@localhost fastdfs_tracker]# /usr/local/nginx/sbin/nginx -s reload

前面直接通过访问 Storage 节点中的 Nginx 的文件

http://192.168.43.72:8888/group1/M00/00/00/wKgrSFpjC26AH1g2AAvUQrxXbkA557.jpg]

http://192.168.43.74:8888/group2/M00/00/00/wKgrSlpjC3aAARrXAAvUQrxXbkA048.jpg

现在可以通过 Tracker 中的 Nginx 来进行访问

(1)通过 Tracker1 中的 Nginx 来访问

http://192.168.43.70:8000/group1/M00/00/00/wKgrSFpjC26AH1g2AAvUQrxXbkA557.jpg

http://192.168.43.70:8000/group2/M00/00/00/wKgrSlpjC3aAARrXAAvUQrxXbkA048.jpg

(2)通过 Tracker2 中的 Nginx 来访问

http://192.168.43.71:8000/group1/M00/00/00/wKgrSFpjC26AH1g2AAvUQrxXbkA557.jpg

http://192.168.50.71:8000/group2/M00/00/00/wKgrSlpjC3aAARrXAAvUQrxXbkA048.jpg

6.构建Keepalive+Nginx 实现虚拟IP的代理

关于使用Keepalive+Nginx进行代理的环境安装,请参考本人简书此文:Keepalived+Nginx+Tomcat 实现高可用Web集群

本文不再做赘述说明

  • 启动Keepalvie+nginx Master主节点【192.168.43.101】
  • 启动Keepalvie+nginx BackUp备节点【192.168.43.102】


    修改2个节点Nginx下目录的nginx.conf的配置文件信息,添加如下内容

    主要内容为2个Tracker加入到Keepalive+nginx代理当中

  1. upstream fastdfs_tracker {
  2. server 192.168.43.70:8000 weight=1 max_fails=2 fail_timeout=30s;
  3. server 192.168.43.71:8000 weight=1 max_fails=2 fail_timeout=30s;
  4. }

第二处修改是添加了一个location并且匹配规则是路径当中有fastdfs

  1. location /fastdfs {
  2. root html;
  3. index index.html index.htm;
  4. proxy_pass http://fastdfs_tracker/;
  5. proxy_set_header Host $http_host;
  6. proxy_set_header Cookie $http_cookie;
  7. proxy_set_header X-Real-IP $remote_addr;
  8. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  9. proxy_set_header X-Forwarded-Proto $scheme;
  10. client_max_body_size 300m;
  11. }

完整配置代码如下:

  1. #user nobody;
  2. worker_processes 1;
  3. #error_log logs/error.log;
  4. #error_log logs/error.log notice;
  5. #error_log logs/error.log info;
  6. #pid logs/nginx.pid;
  7. events {
  8. worker_connections 1024;
  9. }
  10. http {
  11. include mime.types;
  12. default_type application/octet-stream;
  13. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  14. # '$status $body_bytes_sent "$http_referer" '
  15. # '"$http_user_agent" "$http_x_forwarded_for"';
  16. #access_log logs/access.log main;
  17. sendfile on;
  18. #tcp_nopush on;
  19. #keepalive_timeout 0;
  20. keepalive_timeout 65;
  21. #gzip on;
  22. upstream fastdfs_tracker {
  23. server 192.168.43.70:8000 weight=1 max_fails=2 fail_timeout=30s;
  24. server 192.168.43.71:8000 weight=1 max_fails=2 fail_timeout=30s;
  25. }
  26. upstream tomcat{
  27. server 192.168.43.103:8080 weight=1;
  28. server 192.168.43.104:8080 weight=1;
  29. }
  30. server {
  31. listen 80;
  32. server_name localhost;
  33. #charset koi8-r;
  34. #access_log logs/host.access.log main;
  35. location / {
  36. proxy_pass http://tomcat;
  37. proxy_set_header X-NGINX "NGINX-1";
  38. root html;
  39. index index.html index.htm;
  40. }
  41. #error_page 404 /404.html;
  42. # redirect server error pages to the static page /50x.html
  43. #
  44. error_page 500 502 503 504 /50x.html;
  45. location = /50x.html {
  46. root html;
  47. }
  48. location /fastdfs {
  49. root html;
  50. index index.html index.htm;
  51. proxy_pass http://fastdfs_tracker/;
  52. proxy_set_header Host $http_host;
  53. proxy_set_header Cookie $http_cookie;
  54. proxy_set_header X-Real-IP $remote_addr;
  55. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  56. proxy_set_header X-Forwarded-Proto $scheme;
  57. client_max_body_size 300m;
  58. }
  59. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  60. #
  61. #location ~ \.php$ {
  62. # proxy_pass http://127.0.0.1;
  63. #}
  64. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  65. #
  66. #location ~ \.php$ {
  67. # root html;
  68. # fastcgi_pass 127.0.0.1:9000;
  69. # fastcgi_index index.php;
  70. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  71. # include fastcgi_params;
  72. #}
  73. # deny access to .htaccess files, if Apache's document root
  74. # concurs with nginx's one
  75. #
  76. #location ~ /\.ht {
  77. # deny all;
  78. #}
  79. }
  80. # another virtual host using mix of IP-, name-, and port-based configuration
  81. #
  82. #server {
  83. # listen 8000;
  84. # listen somename:8080;
  85. # server_name somename alias another.alias;
  86. # location / {
  87. # root html;
  88. # index index.html index.htm;
  89. # }
  90. #}
  91. # HTTPS server
  92. #
  93. #server {
  94. # listen 443 ssl;
  95. # server_name localhost;
  96. # ssl_certificate cert.pem;
  97. # ssl_certificate_key cert.key;
  98. # ssl_session_cache shared:SSL:1m;
  99. # ssl_session_timeout 5m;
  100. # ssl_ciphers HIGH:!aNULL:!MD5;
  101. # ssl_prefer_server_ciphers on;
  102. # location / {
  103. # root html;
  104. # index index.html index.htm;
  105. # }
  106. #}
  107. }

修改之后,重新启动Keepalive+Nginx2台主备节点。

[root@nginx1 conf]#  /usr/local/nginx/sbin/nginx -s reload  

我们现在就用虚拟IP192.168.43.150来访问我们刚才上传的图片,只是注意在地址栏中要记得输入fastdfs(这是我们nginx.conf文件中location /fastdfs{}规则规定的)。如下图所示,发现,我们通过虚拟IP便可以访问我们上传的图片了。这样的好处是,对用户来说,只需要访问这个虚拟IP就可以了,不用关心FastDFS集群内部的转发机制。

 

集群VIP访问截图.png

至此,分布式文件系统就搭建完成了,在通过Java访问时,只要在配置文件配置所有的Tracker节点IP信息就可以啦!

补充说明:

如果Tracker 服务、Storage服务、Nginx服务开机后没有自启动,请执行一下操作并进行重启

  1. [root@localhost ~]# chkconfig --add fdfs_trackerd
  2. [root@localhost ~]# chkconfig --add fdfs_storaged

编辑目录下的/etc/rc.d/rc.local,内容如下:

  1. #!/bin/bash
  2. # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
  3. #
  4. # It is highly advisable to create own systemd services or udev rules
  5. # to run scripts during boot instead of using this file.
  6. #
  7. # In contrast to previous versions due to parallel execution during boot
  8. # this script will NOT be run after all other services.
  9. #
  10. # Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
  11. # that this script will be executed during boot.
  12. touch /var/lock/subsys/local
  13. /usr/local/nginx/sbin/nginx

主要增加了Nginx的启动,之后进行文件授权,生效文件,重新启动系统

  1. [root@localhost ~]# chmod +x /etc/rc.d/rc.local
  2. [root@localhost ~]# source /etc/rc.d/rc.local
  3. [root@localhost ~]# reboot



作者:溯水心生
链接:https://www.jianshu.com/p/88ccae4cbd82
来源:简书

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/923292
推荐阅读
相关标签
  

闽ICP备14008679号