|
| 1 | +# FastDFS�ܹ�ͼ: |
| 2 | + |
| 3 | +# FastDFS����ͼ: |
| 4 | + |
| 5 | + |
| 6 | +```test |
| 7 | +1.FastDFS��������: |
| 8 | + [1]���ٷ�����(Tracker Server): ���ٷ�����,��Ҫ�����ȹ���,���������;����������е�storage server; |
| 9 | + [2]�洢������(Storage Server): �洢������,��Ҫ�ṩ�����ͱ��ݷ���;��groupΪ��λ,ÿ��group �ڿ����ж�̨ |
| 10 | + storage server,���ݻ�Ϊ����; |
| 11 | + [3]�ͻ���(Client): �ͻ���,�ϴ��������ݵķ�����;����Ŀ�������ڵķ�����; |
| 12 | +2.�ϴ�����˵��: |
| 13 | + [1]�ͻ��˷����ϴ�����Tracker Server������,����Tracker Server��������һ���������group��Storage Server; |
| 14 | + [2]Storage Server����������һ��file_id: ����storage server ip,�ļ�����ʱ��,�ļ���С,�ļ� CRC32 У����������; |
| 15 | + [3]Storage Server�ᰴ�ļ�file_id�������� hash ��·�ɵ��洢Ŀ¼������һ����Ŀ¼,Ȼ���ļ��洢������Ŀ¼��, |
| 16 | + ��������ļ�·��: group����,�������·��,��������Ŀ¼,file_id���ļ�������һ���������ļ���ַ; |
| 17 | +3.FastDFS��CentOS7�����ð�װ����: |
| 18 | + [1]������: |
| 19 | + yum -y install gcc-c++ |
| 20 | + yum -y install pcre pcre-devel |
| 21 | + yum -y install zlib zlib-devel |
| 22 | + yum -y install openssl openssl-devel |
| 23 | + [2]��װlibfastcommon: |
| 24 | + (1)���ذ�װ libfastcommon: (�鿴�汾: https://github.com/happyfish100/libfastcommon/releases) |
| 25 | + wget https://github.com/happyfish100/libfastcommon/archive/V1.0.43.tar.gz |
| 26 | + (2)��ѹlibfastcommon: tar -zxvf V1.0.43.tar.gz |
| 27 | + (3)�ƶ���ѹĿ¼��/usr/local��: mv libfastcommon-1.0.43 /usr/local/ |
| 28 | + (4)����libfastcommon-1.0.43Ŀ¼,ִ�б�������: |
| 29 | + cd /usr/local/libfastcommon-1.0.43 |
| 30 | + ./make.sh |
| 31 | + (5)ִ�а�װ����: ./make.sh install |
| 32 | + [3]��װFastDFS: |
| 33 | + (1)���ذ�װFastDFS: (�鿴�汾: https://github.com/happyfish100/fastdfs/releases) |
| 34 | + wget https://github.com/happyfish100/fastdfs/archive/V6.06.tar.gz |
| 35 | + (2)��ѹFastDFS: tar -zxvf V6.06.tar.gz |
| 36 | + (3)�ƶ���ѹĿ¼��/usr/local��: mv fastdfs-6.06/ /usr/local/ |
| 37 | + (4)����fastfds-6.06Ŀ¼,ִ�б�������: |
| 38 | + cd /usr/local/fastdfs-6.06 |
| 39 | + ./make.sh |
| 40 | + (5)ִ�а�װ����: ./make.sh install |
| 41 | + [3]����Tracker����: |
| 42 | + (1)��װ�ɹ���,����/etc/fdfsĿ¼,��tracker.conf.sample�ļ���Ϊtracker.conf�����ļ�������: |
| 43 | + cd /etc/fdfs/ |
| 44 | + cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf |
| 45 | + vim /etc/fdfs/tracker.conf //����Ҫ�ĵIJ��� |
| 46 | + 1)disabled=false //���������ļ� |
| 47 | + 1)port=22122 //����tracker�Ķ˿ں�,ͨ������22122���Ĭ�϶˿� |
| 48 | + 1)base_path=/opt/fastdfs //����tracker�������ļ�����־Ŀ¼ |
| 49 | + 2)http.server_port=6666 //tracker������http�˿� |
| 50 | + (2)����ɺ�������Ҫ����tracker�Ĺ���Ŀ¼: (������base_path��Ӧ��ֵ) |
| 51 | + mkdir -p /opt/fastdfs |
| 52 | + (3)����tracker����: (����Ϊstart,ֹͣΪstop) |
| 53 | + /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start |
| 54 | + (4)�鿴����: (���ܲ鿴��fdfs�Ľ�����Tracker����װ�ɹ�) |
| 55 | + ps -ef|grep fdfs �� netstat -lnpt|grep fdfs |
| 56 | + [4]����Storage����: (Storage ����Ҳ�ɷ��ڶ�̨������,���� Group(��)�ĸ���,ͬһ���ڷ���������ͬ��;�˴�ֻ���õ���;) |
| 57 | + (1)����/etc/fdfs/Ŀ¼,��storage.conf.sample�ļ���Ϊstorage.conf�����ļ�������: |
| 58 | + cd /etc/fdfs/ |
| 59 | + cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf |
| 60 | + vim /etc/fdfs/storage.conf |
| 61 | + (2)��storage.conf�ļ���,�ҵ��������������: |
| 62 | + 1)disabled=false |
| 63 | + 2)group_name=group1 |
| 64 | + 3)port=23000 |
| 65 | + 4)base_path=/opt/fastdfs |
| 66 | + 5)store_path_count=1 |
| 67 | + 6)store_path0=/opt/fastdfs/fdfs_storage |
| 68 | + 7)tracker_server=192.168.8.120:22122 |
| 69 | + 8)http.server_port=8888 |
| 70 | + (3)����ɺ�,��Ҫ����storage�����ݴ洢Ŀ¼: |
| 71 | + mkdir -p /opt/fastdfs/fdfs_storage |
| 72 | + (4)����storage����: (����Ϊstart,ֹͣΪstop) |
| 73 | + /usr/bin/fdfs_storaged /etc/fdfs/storage.conf start |
| 74 | + (5)�鿴����: |
| 75 | + ps -ef|grep fdfs �� netstat -lnpt|grep fdfs |
| 76 | + (����ʱtracker��storage��������,��/opt/fastdfs�ļ����»����һ����ļ������ڴ���ļ���) |
| 77 | + (6)��װ���ò�������Tracker��Storage����,��������֮���ͨ��: |
| 78 | + /usr/bin/fdfs_monitor /etc/fdfs/storage.conf |
| 79 | + (����Storage�µ�ip_addr����ʾACTIVE,��˵��ok) |
| 80 | + [5]����fdfs_upload_file�ϴ��ļ�: |
| 81 | + (1)����/etc/fdfsĿ¼,��client.conf.sample�ļ���Ϊclient.conf�����ļ�������: |
| 82 | + /etc/fdfs/client.conf,��Ū��Ŀ¼,�ϴ�ʱ�ᱨ��) |
| 83 | + cd /etc/fdfs/ |
| 84 | + cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf |
| 85 | + vim client.conf |
| 86 | + (2)�ҵ��������������: |
| 87 | + 1)base_path=/opt/fastdfs |
| 88 | + 2)tracker_server=192.168.8.120:22122 |
| 89 | + 3)http.tracker_server_port=6666 |
| 90 | + (cp /etc/fdfs/client.conf /usr/etc/fdfs/client.conf) |
| 91 | + (3)����ɺ�Ϳ�ͨ��/usr/bin/fdfs_upload_file�����ϴ��ļ�,/usr/bin/fdfs_upload_file �����÷�: |
| 92 | + /usr/bin/fdfs_upload_file <config_file> <local_filename> [storage_ip:port] [store_path_index] |
| 93 | + (���� �����ļ� �ϴ����ļ� storage_ip�Ͷ˿� store_path�DZ�) |
| 94 | + (�ļ��ϴ���᷵���ļ�����·��,ֻҪ����·����������,��������Nginx�Ϳɷ��ʵ��ϴ����ļ���) |
| 95 | + /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /home/sherry/Downloads/wechat.jpg |
| 96 | + [6]tracker.conf��storage.conf�ľ�������ע��: |
| 97 | + (1)tracker.conf: |
| 98 | + //���ø������ļ��Ƿ��Ƿ�����,��Ϊ������fastdfs����˽���ʱ��Ҫָ�������ļ�, |
| 99 | + //������Ҫʹ�������ļ���Ч;false����Ч,true������; |
| 100 | + disabled=false |
| 101 | + //����ļ�����ַ,������趨��������е�ַ |
| 102 | + bind_addr= |
| 103 | + //tracker�����Ķ˿� |
| 104 | + port=22122 |
| 105 | + //���ӳ�ʱ�趨 |
| 106 | + connect_timeout=30 |
| 107 | + //tracker��ͨ�����緢�ͽ������ݵij�ʱʱ�� |
| 108 | + network_timeout=60 |
| 109 | + //���ݺ���־�Ĵ�ŵص� |
| 110 | + base_path=/opt/fdfs |
| 111 | + //������֧�ֵ���������� |
| 112 | + max_connections=256 |
| 113 | + //�����߳���һ��Ϊcpu���� |
| 114 | + work_threads=4 |
| 115 | + //�ڴ洢�ļ�ʱѡ��group�IJ���: |
| 116 | + // 0:��ѵ���� |
| 117 | + // 1:ָ��ijһ���� |
| 118 | + // 2:���ؾ���,ѡ����пռ�����group |
| 119 | + store_lookup=2 |
| 120 | + //��������store_lookupѡ����1,��������Ҫָ��һ��group |
| 121 | + //store_group=group2 |
| 122 | + // group�е���̨storage����storage,��һ���ļ��ϴ�����storage��, |
| 123 | + //������̨����ͬ���ļ���group�ڵ�����storage��, |
| 124 | + // 0:��ѵ���� |
| 125 | + // 1:����ip��ַ����,��һ�� |
| 126 | + // 2:�������ȼ�����,��һ�� |
| 127 | + store_server=0 |
| 128 | + //ѡ���Ǹ�storage��Ϊ�����ط�����: |
| 129 | + // 0:��ѵ���� |
| 130 | + // 1:���ϴ�storage��Ϊ�����ط����� |
| 131 | + download_server=0 |
| 132 | + //ѡ���ļ��ϴ���storage�е��ĸ�(Ŀ¼/���ص�),storage�����ж������ļ���base path |
| 133 | + // 0:��ѵ���� |
| 134 | + // 2:���ؾ���,ѡ����пռ����� |
| 135 | + store_path=0 |
| 136 | + //ϵͳԤ���ռ�,��һ��group�е��κ�storage��ʣ��ռ�С�ڶ����ֵ,����group�Ͳ����ϴ��ļ��� |
| 137 | + reserved_storage_space = 4GB |
| 138 | + //��־��Ϣ���� |
| 139 | + log_level=info |
| 140 | + //�������Ǹ��û�/�û�������,��ָ��Ĭ���ǵ�ǰ�û� |
| 141 | + run_by_group= |
| 142 | + run_by_user= |
| 143 | + //������Щ��������trackerĬ�������л��� |
| 144 | + allow_hosts=* |
| 145 | + //������־��Ϣˢ�µ�disk��Ƶ��,Ĭ��10s |
| 146 | + sync_log_buff_interval = 10 |
| 147 | + //���storage�������ļ��ʱ��,storage����������tracker��������, |
| 148 | + //�����ָ����ʱ��û�յ��ź�,tracker��Ϊstorage����,Ĭ��120s |
| 149 | + check_active_interval = 120 |
| 150 | + //�߳�ջ�Ĵ�С,��С64K |
| 151 | + thread_stack_size = 64KB |
| 152 | + //storage��ip�ı�������Ƿ��Զ�����,storage��������ʱ���Զ����� |
| 153 | + storage_ip_changed_auto_adjust = true |
| 154 | + //storage֮��ͬ���ļ�������ӳ�,Ĭ��1�� |
| 155 | + storage_sync_file_max_delay = 86400 |
| 156 | + //ͬ��һ���ļ������ѵ����ʱ�� |
| 157 | + storage_sync_file_max_time = 300 |
| 158 | + //�Ƿ���һ��trunk�ļ��洢���С�ļ� |
| 159 | + use_trunk_file = false |
| 160 | + //��С��solt��С,Ӧ��С��4KB,Ĭ��256bytes |
| 161 | + slot_min_size = 256 |
| 162 | + //����solt��С,����ϴ����ļ�С��Ĭ��ֵ,���ϴ��ļ�������trunk�ļ��� |
| 163 | + slot_max_size = 16MB |
| 164 | + //trunk�ļ���Ĭ�ϴ�С,Ӧ�ô���4M |
| 165 | + trunk_file_size = 64MB |
| 166 | + //http�����Ƿ���Ч,Ĭ�ϲ���Ч |
| 167 | + http.disabled=false |
| 168 | + //http����˿� |
| 169 | + http.server_port=8080 |
| 170 | + //���storage��http�����ʱ������<=0��ʾ����� |
| 171 | + http.check_alive_interval=30 |
| 172 | + //���storage��http����ʱ�������������,tcpֻ����Ƿ��������,http���뷵��200 |
| 173 | + http.check_alive_type=tcp |
| 174 | + //ͨ��url���storage http����״̬ |
| 175 | + http.check_alive_uri=/status.html |
| 176 | + //if need find content type from file extension name |
| 177 | + http.need_find_content_type=true |
| 178 | + // ��include������http���������� |
| 179 | + // include http.conf |
| 180 | + (1)storage.conf: |
| 181 | + //ͬtracker.conf |
| 182 | + disabled=false |
| 183 | + //���storage�����������Ǹ�group |
| 184 | + group_name=group1 |
| 185 | + //ͬtracker.conf |
| 186 | + bind_addr= |
| 187 | + //��������������ʱ�Ƿ��ַ,bind_addr����ʱ����������Ч |
| 188 | + client_bind=true |
| 189 | + //ͬtracker.conf |
| 190 | + port=23000 |
| 191 | + connect_timeout=30 |
| 192 | + network_timeout=60 |
| 193 | + //������tracker������������ʱ���� |
| 194 | + heart_beat_interval=30 |
| 195 | + //������tracker���ʹ���ʹ���ʵ�ʱ���� |
| 196 | + stat_report_interval=60 |
| 197 | + //ͬtracker.conf |
| 198 | + base_path=/opt/fdfs |
| 199 | + max_connections=256 |
| 200 | + //����/�������ݵ�buff��С,�������8KB |
| 201 | + buff_size = 256KB |
| 202 | + //ͬtracker.conf |
| 203 | + work_threads=4 |
| 204 | + //����IO�Ƿ��д���� |
| 205 | + disk_rw_separated = true |
| 206 | + //�Ƿ�ֱ�Ӷ�д�ļ�,Ĭ�Ϲر� |
| 207 | + disk_rw_direct = false |
| 208 | + //��϶�дʱ�Ķ�д�߳��� |
| 209 | + disk_reader_threads = 1 |
| 210 | + disk_writer_threads = 1 |
| 211 | + //ͬ���ļ�ʱ���binlogû��Ҫͬ�����ļ�,���ӳٶ��ٺ�������¶�ȡ,0��ʾ���ӳ� |
| 212 | + sync_wait_msec=50 |
| 213 | + //ͬ����һ���ļ��������ٺ���ͬ����һ���ļ�,0��ʾ����Ϣֱ��ͬ�� |
| 214 | + sync_interval=0 |
| 215 | + //��ʾ���ʱ����ͬ���ļ� |
| 216 | + sync_start_time=00:00 |
| 217 | + sync_end_time=23:59 |
| 218 | + //ͬ��������ļ���дmark��� |
| 219 | + write_mark_file_freq=500 |
| 220 | + //storage�ڴ洢�ļ�ʱ֧�ֶ�·��,Ĭ��ֻ����һ�� |
| 221 | + store_path_count=1 |
| 222 | + //���ö��store_path·��,��0��ʼ,���store_path0������,��base_path������� |
| 223 | + store_path0=/opt/fdfs |
| 224 | + //store_path1=/opt/fastdfs2 |
| 225 | + //subdir_count * subdir_count��Ŀ¼����store_path�´���,���������洢 |
| 226 | + subdir_count_per_path=256 |
| 227 | + //����tracker_server |
| 228 | + tracker_server=x.x.x.x:22122 |
| 229 | + //ͬtracker.conf |
| 230 | + log_level=info |
| 231 | + run_by_group= |
| 232 | + run_by_user= |
| 233 | + allow_hosts=* |
| 234 | + //�ļ�������Ŀ¼�µĴ�Ų���,0:��ѵ 1:��� |
| 235 | + file_distribute_path_mode=0 |
| 236 | + //���ʼ�����ѵ���ʱ,һ��Ŀ¼�¿ɴ�ŵ��ļ���Ŀ |
| 237 | + file_distribute_rotate_count=100 |
| 238 | + //д������ֽں�Ϳ�ʼͬ��,0��ʾ��ͬ�� |
| 239 | + fsync_after_written_bytes=0 |
| 240 | + //ˢ����־��Ϣ��disk�ļ�� |
| 241 | + sync_log_buff_interval=10 |
| 242 | + //ͬ��storage��״̬��Ϣ��disk�ļ�� |
| 243 | + sync_stat_file_interval=300 |
| 244 | + //�߳�ջ��С |
| 245 | + thread_stack_size=512KB |
| 246 | + //�����ļ��ϴ������������ȼ�,ֵԽСԽ�� |
| 247 | + upload_priority=10 |
| 248 | + //�Ƿ����ļ��ظ�����,1:��� 0:����� |
| 249 | + check_file_duplicate=0 |
| 250 | + //��check_file_duplicate����Ϊ1ʱ,��ֵ�������� |
| 251 | + key_namespace=FastDFS |
| 252 | + //��FastDHT�������ӵķ�ʽ 0:������ 1:������ |
| 253 | + keep_alive=0 |
| 254 | + //ͬtracker.conf |
| 255 | + http.disabled=false |
| 256 | + http.domain_name= |
| 257 | + http.server_port=8888 |
| 258 | + http.trunk_size=256KB |
| 259 | + http.need_find_content_type=true |
| 260 | + //include http.conf |
| 261 | +4.FastDFS����Nginxģ�鼰���ʲ���: |
| 262 | + [1]����fastdfs-nginx-module���: |
| 263 | + (1)����fastdfs-nginx-module: (�鿴�汾:https://github.com/happyfish100/fastdfs-nginx-module/releases) |
| 264 | + wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.22.tar.gz |
| 265 | + (2)��ѹfastdfs-nginx-module: |
| 266 | + tar -zxvf V1.22.tar.gz |
| 267 | + (3)����ѹ����ļ����ƶ���nginxԴ���ļ�����: |
| 268 | + mv fastdfs-nginx-module-1.22 /usr/local/ |
| 269 | + (4)����mod-fastdfs.conf��/etc/fdfs/�ļ�Ŀ¼��,����mod-fastdfs.conf: |
| 270 | + cp /usr/local/fastdfs-nginx-module-1.22/src/mod_fastdfs.conf /etc/fdfs/ |
| 271 | + vim /etc/fdfs/mod_fastdfs.conf |
| 272 | + 1)base_path=/opt/fastdfs |
| 273 | + 2)tracker_server=192.168.8.120:22122 |
| 274 | + 3)url_have_group_name = true |
| 275 | + 4)store_path0=/opt/fastdfs/fdfs_storage |
| 276 | + [2]��װNginx: |
| 277 | + (1)����nginx: (�鿴�汾:https://github.com/nginx/nginx/releases) |
| 278 | + wget http://nginx.org/download/nginx-1.17.8.tar.gz |
| 279 | + (2)��ѹnginx: |
| 280 | + tar -zxvf nginx-1.17.8.tar.gz |
| 281 | + (3)�ƶ���ѹĿ¼��/usr/local��: |
| 282 | + mv nginx-1.17.8 /usr/local/ |
| 283 | + (4)����nginx-1.17.8Ŀ¼,ִ�б��밲װ����: |
| 284 | + cd /usr/local/nginx-1.17.8 |
| 285 | + //����fastdfs-nginx����ģ��(��ģ��Ҳ����Nginx��װ������) |
| 286 | + ./configure --add-module=/usr/local/fastdfs-nginx-module-1.22/src/ |
| 287 | + make |
| 288 | + make install |
| 289 | + (5)�鿴�Ѿ���װ��nginxģ��: (configure arguments: �����ʾ��ǰ�Ѿ���װ��nginxģ��) |
| 290 | + /usr/local/nginx/sbin/nginx -V |
| 291 | + (5)����nginx: (./configure��ָ��Ŀ¼��װ�Ļ��ǰ�װ��/usr/local/nginx) |
| 292 | + /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf |
| 293 | + (6)����nginx�ɹ�����֤: ���������localhost:80 |
| 294 | + (7)��fastdfs-6.06����������л�û�д���/etc/fdfs�еĿ�����ȥ: |
| 295 | + cd /usr/local/fastdfs-6.06/conf/ |
| 296 | + cp anti-steal.jpg http.conf mime.types /etc/fdfs/ |
| 297 | + cd /etc/fdfs/ |
| 298 | + (8)����Nginx,�༭nginx.conf�ļ�,������������: |
| 299 | + vim /usr/local/nginx/conf/nginx.conf |
| 300 | + server { |
| 301 | + listen 80; |
| 302 | + server_name 192.168.8.120; |
| 303 | + location ~/(group[0-9])/M00 { |
| 304 | + ngx_fastdfs_module; |
| 305 | + } |
| 306 | + } |
| 307 | + |
| 308 | + (9)����Nginx,���ӡ��fastdfsģ���pid,������־�Ƿ�,�������ᱨ����; |
| 309 | + /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf |
| 310 | + (10)�ϴ��ļ�: |
| 311 | + /usr/bin/fdfs_upload_file <config_file> <local_filename> [storage_ip:port] [store_path_index] |
| 312 | + ��: /usr/bin/fdfs_upload_file /usr/etc/fdfs/client.conf /home/conan/Downloads/wechat.jpg |
| 313 | + (11)���з��ʲ���: 192.168.8.120:80/�ϴ�ʱ���صĵ�ַ |
| 314 | +``` |
0 commit comments