1. 程式人生 > >CentOS7搭建FastDFS V5.11分布式文件系統-第二篇

CentOS7搭建FastDFS V5.11分布式文件系統-第二篇

情況 netstat prior 修改 update -c his int 分布式

1.CentOS7 FastDFS搭建

前面已下載好了要用到的工具集,下面就可以開始安裝了:
如果安裝過程中出現問題,可以下載我提供的,當前測試可以通過的工具包:

點這裏點這裏

1.1 安裝libfastcommon

安裝成功後解壓libfastcommon-master.zip

unzip libfastcommon-master.zip
[root@sybmfw12-lnsy libfastcommon-1.0.36]# ll
drwxr-xr-x. 2 root root 4096 4月   5 2017 doc
-rw-r--r--. 1 root root 8005 4月   5 2017
HISTORY -rw-r--r--. 1 root root 566 4月 5 2017 INSTALL -rw-r--r--. 1 root root 1606 4月 5 2017 libfastcommon.spec -rwxr-xr-x. 1 root root 3099 4月 5 2017 make.sh drwxr-xr-x. 2 root root 4096 4月 5 2017 php-fastcommon -rw-r--r--. 1 root root 2763 4月 5 2017 README drwxr-xr-x. 3 root root 4096 11月 8 12
:30 src

當我們./make.sh的時候可能會提示,gcc命令沒有找到。

用yum安裝gcc:

yum -y install gcc-c++

這個時候分別執行./make.sh和./make.sh install,正常情況是可以成功的。
libfastcommon默認會被安裝到/usr/lib64/libfastcommon.so但是FastDFS的主程序卻在/usr/local/lib目錄下
這個時候我們就要建立一個軟鏈接了,實際上也相當於windows上的快捷方式。

ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so
ln 
-s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so

1.2安裝FastDFS

解壓FastDFS安裝包

unzip fastdfs-5.11.zip

解壓後看到:

[root@sybmfw12-lnsy fastdfs-5.11]# ll
總用量 136 drwxr-xr-x. 3 root root 4096 11月 8 12:32 client drwxr-xr-x. 2 root root 4096 11月 8 12:32 common drwxr-xr-x. 2 root root 4096 6月 3 21:09 conf -rw-r--r--. 1 root root 35067 6月 3 21:09 COPYING-3_0.txt -rw-r--r--. 1 root root 3171 6月 3 21:09 fastdfs.spec -rw-r--r--. 1 root root 33100 6月 3 21:09 HISTORY drwxr-xr-x. 2 root root 4096 6月 3 21:09 init.d -rw-r--r--. 1 root root 7755 6月 3 21:09 INSTALL -rwxr-xr-x. 1 root root 5548 6月 3 21:09 make.sh drwxr-xr-x. 2 root root 4096 6月 3 21:09 php_client -rw-r--r--. 1 root root 2380 6月 3 21:09 README.md -rwxr-xr-x. 1 root root 1768 6月 3 21:09 restart.sh -rwxr-xr-x. 1 root root 1680 6月 3 21:09 stop.sh drwxr-xr-x. 4 root root 4096 11月 8 12:32 storage drwxr-xr-x. 2 root root 4096 6月 3 21:09 test drwxr-xr-x. 2 root root 4096 11月 8 12:32 track

進到剛解壓的目錄:

cd fastdfs-5.11
./make.sh
./make.sh install

如果沒有報錯那麽就成功了。安裝log中會提示FastDFS安裝到了/etc/fdfs目錄下。

成功後查看安裝目錄:

[root@sybmfw12-lnsy fastdfs-5.11]# ll /etc/fdfs/-rw-r--r--. 1 root      root       1463 11月  8 12:52 client.conf.sample-rw-r--r--. 1 root      root       7938 11月  8 14:55 storage.conf.sample-rw-r--r--. 1 root      root       7397 11月  8 12:36 tracker.conf.sample

我們需要把這三個示例文件復制一份,去掉.sample

cp client.conf.sample client.conf
cp storage.conf.sample storage.conf
cp tracker.conf.sample tracker.conf

FastDFS安裝結束。

1.3安裝tracker

1.3.1創建tracker工作目錄

這個目錄可以自定義,用來保存tracker的data和log
根據個人習慣,我創建了下面的目錄:

mkdir /opt/fastdfs_tracker

1.3.2 配置tracker

vim /etc/fdfs/tracker.conf
打開後重點關註下面4個配置: 
1.disabled=false 
2.port=22122 #默認端口號 
3.base_path=/opt/fastdfs_tracker #我剛剛創建的目錄 
4.http.server_port=8080 #默認端口是8080
5.bind_addr= 0.0.0.0 監聽地址

修改完的文件為:

技術分享
disabled=false

bind_addr= 0.0.0.0

port=22122

connect_timeout=30

network_timeout=60

base_path=/opt/fastdfs_tracker

max_connections=512

accept_threads=1

work_threads=4

min_buff_size = 8KB

max_buff_size = 128KB

store_lookup=2

store_group=group2

store_server=0

store_path=0

download_server=0

reserved_storage_space = 10%

log_level=info

run_by_group=

run_by_user=

allow_hosts=*

sync_log_buff_interval = 10

check_active_interval = 120

thread_stack_size = 64KB

storage_ip_changed_auto_adjust = true

storage_sync_file_max_delay = 86400

storage_sync_file_max_time = 300

use_trunk_file = false 

slot_min_size = 256

slot_max_size = 16MB

trunk_file_size = 64MB

trunk_create_file_advance = false

trunk_create_file_time_base = 02:00

trunk_create_file_interval = 86400

trunk_create_file_space_threshold = 20G

trunk_init_check_occupying = false

trunk_init_reload_from_binlog = false

trunk_compress_binlog_min_interval = 0

use_storage_id = false

storage_ids_filename = storage_ids.conf

id_type_in_filename = ip

store_slave_file_use_link = false

rotate_error_log = false

error_log_rotate_time=00:00

rotate_error_log_size = 0

log_file_keep_days = 0

use_connection_pool = false

connection_pool_max_idle_time = 3600

http.server_port=8080

http.check_alive_interval=30

http.check_alive_type=tcp

http.check_alive_uri=/status.html
View Code

1.3.3啟動tracker

保存配置後啟動tracker,命令如下:

service fdfs_trackerd start

成功後應該可以看到:


[root@sybmfw12-lnsy fastdfs-5.11]#service fdfs_trackerd start 
Starting fdfs_trackerd (via systemctl): [ OK ]

進行剛剛創建的tracker目錄,發現目錄中多了data和log兩個目錄

[root@sybmfw12-lnsy fastdfs-5.11]# ll /opt/fastdfs_tracker/
drwxr-xr-x. 2 root root 4096 11月  8 15:01 data
drwxr-xr-x. 2 root root 4096 11月  8 12:37 logs

最後我們需要給tracker加入開機啟動

echo "service fdfs_trackerd start" |tee -a /etc/rc.d/rc.local

查看一下tracker的端口監聽情況

[root@sybmfw12-lnsy fastdfs-5.11]# netstat -unltp|grep fdfs
tcp        0      0 0.0.0.0:22122           0.0.0.0:*               LISTEN      70382/fdfs_trackerd 

端口22122成功監聽。

1.4 安裝storage

storage的安裝與tracker很類似。

1.4.1 為storage配置工作目錄

與tracker不同的是,由於storage還需要一個目錄用來存儲數據,所以我另外多建了一個fastdfs_storage_data
下面是我的目錄結構:

[root@sybmfw12-lnsy fastdfs-5.11]# ll /opt/
drwxr-xr-x. 4 root root 4096 11月  8 12:48 fastdfs_storage
drwxr-xr-x. 3 root root 4096 11月  8 15:02 fastdfs_storage_data
drwxr-xr-x. 4 root root 4096 11月  8 12:37 fastdfs_tracker

1.4.2 修改storage配置文件

修改storage.conf

1.disabled=false 
2.group_name=group1 #組名,根據實際情況修改 
3.port=23000 #設置storage的端口號,默認是23000,同一個組的storage端口號必須一致 
4.base_path=/opt/fastdfs_storage #設置storage數據文件和日誌目錄 
5.store_path_count=1 #存儲路徑個數,需要和store_path個數匹配 
6.store_path0=/opt/fastdfs_storage_data #實際文件存儲路徑 
7.tracker_server=172.20.132.57:22122 #我CentOS7的ip地址 
8.http.server_port=8888 #設置 http 端口號

修改完的文件為:

技術分享
disabled=false
group_name=group1
bind_addr= 0.0.0.0
client_bind=true
port=23000
connect_timeout=30
network_timeout=60
heart_beat_interval=30
stat_report_interval=60
base_path=/opt/fastdfs_storage
max_connections=256
buff_size = 256KB
accept_threads=1
work_threads=4
disk_rw_separated = true
disk_reader_threads = 1
disk_writer_threads = 1
sync_wait_msec=50
sync_interval=0
sync_start_time=00:00
sync_end_time=23:59
write_mark_file_freq=500
store_path_count=1
store_path0=/opt/fastdfs_storage_data
subdir_count_per_path=256
tracker_server=172.20.132.57:22122
log_level=info
run_by_group=
run_by_user=
allow_hosts=*
file_distribute_path_mode=0
file_distribute_rotate_count=100
fsync_after_written_bytes=0
sync_log_buff_interval=10
sync_binlog_buff_interval=10
sync_stat_file_interval=300
thread_stack_size=512KB
upload_priority=10
if_alias_prefix=
check_file_duplicate=0
file_signature_method=hash
key_namespace=FastDFS
keep_alive=0
use_access_log = false
rotate_access_log = false
access_log_rotate_time=00:00
rotate_error_log = false
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=false
use_connection_pool = false
connection_pool_max_idle_time = 3600
http.domain_name=
http.server_port=8888
View Code

修改保存後創建軟引用

ln -s /usr/bin/fdfs_storaged /usr/local/bin

1.4.3 啟動storage

service fdfs_storaged start
Starting fdfs_storaged (via systemctl): [ OK ]

同樣的,設置開機啟動:
修改rc.local

echo "service fdfs_storaged start" |tee -a /etc/rc.d/rc.local

查看一下服務是否啟動

[root@sybmfw12-lnsy fastdfs-5.11]#netstat -unltp | grep fdfs 
tcp
0 0 0.0.0.0:22122 0.0.0.0:* LISTEN 2231/fdfs_trackerd
tcp
0 0 0.0.0.0:23000 0.0.0.0:* LISTEN 2323/fdfs_storaged

服務已正常啟動。

1.4.4 校驗整合

到這裏,fastdfs的東西都已安裝完成,最後我們還要確定一下,storage是否註冊到了tracker中去。
查看命令:

/usr/bin/fdfs_monitor /etc/fdfs/storage.conf

成功後可以看到:
ip_addr = 172.20.132.57 (localhost.localdomain) ACTIVE

技術分享
[root@sybmfw12-lnsy fastdfs-5.11]# /usr/bin/fdfs_monitor /etc/fdfs/storage.conf
[2017-11-08 18:05:55] DEBUG - base_path=/opt/fastdfs_storage, connect_timeout=30, 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

server_count=1, server_index=0

tracker server is 172.20.132.57:22122

group count: 1

Group 1:
group name = group1
disk total space = 34140 MB
disk free space = 29282 MB
trunk free space = 0 MB
storage server count = 1
active server count = 1
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 = 172.20.132.57
        ip_addr = 172.20.132.57 (sybmfw12-lnsy)  ACTIVE
        http domain = 
        version = 5.11
        join time = 2017-11-08 12:48:05
        up time = 2017-11-08 15:02:04
        total storage = 34140 MB
        free storage = 29282 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 = 0
        connection.max_count = 1
        total_upload_count = 2
        success_upload_count = 2
        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 = 0
        success_download_count = 0
        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 = 179368
        success_upload_bytes = 179368
        total_append_bytes = 0
        success_append_bytes = 0
        total_modify_bytes = 0
        success_modify_bytes = 0
        stotal_download_bytes = 0
        success_download_bytes = 0
        total_sync_in_bytes = 0
        success_sync_in_bytes = 0
        total_sync_out_bytes = 0
        success_sync_out_bytes = 0
        total_file_open_count = 2
        success_file_open_count = 2
        total_file_read_count = 0
        success_file_read_count = 0
        total_file_write_count = 2
        success_file_write_count = 2
        last_heart_beat_time = 2017-11-08 18:05:37
        last_source_update = 2017-11-08 15:24:21
        last_sync_update = 1970-01-01 08:00:00
        last_synced_timestamp = 1970-01-01 08:00:00 
View Code

點這裏看第三篇

CentOS7搭建FastDFS V5.11分布式文件系統-第二篇