FastDFS 配置环境
安装C环境
yum install -y gcc gcc-c++
//查看服务器是否安装了:libevent
先用:ls -al /usr/lib | grep libevent 查看是否已安装,如果已安装且版本低于1.3
则先通过:rpm -e libevent —nodeps 进行卸载。
FastDFS 5.05版本不再依赖libevent,而依赖于libfastcommon,因此需要先安装libfastcommon。
软件包下载地址:https://pan.baidu.com/s/1K9p4zpMHyuAUcDPzfq8RRg 密码:m1h9
通过CRT软件上传至Linux服务器
因为下载的文件为zip压缩格式文件所以解压使用
unzip libfastcommon-master.zip
//放置个人习惯的安装目录
cp -r libfastcommon-master/ /usr/local/src/
cd /usr/local/src/libfastcommon-master/
./make.sh
./make.sh install
//建立软链接
ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so
安装FastDFS
//安装FastDFS
tar zxf FastDFS_v5.05.tar.gz
cd FastDFS
./make.sh
./make.sh install
安装成功后可以cd /etc/fdfs文件下查看3个配置文件
配置tracker节点
mkdir /data/fastdfs #创建tracker的数据文件和日志存储目录
cd /etc/fdfs
mv tracker.conf.sample tracker.conf
vim tracker.conf #修改的文件内容如下(基础配置,不考虑性能调优情况下):
base_path=/data/fastdfs #设置 tracker 的数据文件和日志目录(需预先创建)
http.server_port=6666 #设置http端口号,默认为8080
//建立关联
ln -s /usr/bin/fdfs_trackerd /usr/local/bin
ln -s /usr/bin/stop.sh /usr/local/bin
ln -s /usr/bin/restart.sh /usr/local/bin
service fdfs_trackerd start #启动tracker节点
cd /data/fastdfs #查看启动后文件夹下两个文件内容
netstat -anp|grep fdfs #查看端口号是否监听
配置storage节点
mkdir /data/fastdfs-storage #创建
cd /etc/fdfs/
mv storage.conf.sample storage.conf
vim storage.conf#修改的文件内容如下(基础配置,不考虑性能调优情况下):
group_name=group1 #组名,可根据实际情况修改
base_path=/data/fastdfs-storage #设置storage数据文件和日志目录,需预先创建
store_path_count=1 #存储路径个数,需要和 store_path 个数匹配、
store_path0=/data/fastdfs-storage #存储路径
tracker_server=服务器公网IP:22122 # #tracker 服务器的 IP地址和端口号,如果是单机搭建,IP不要写127.0.0.1,否则启动不成功。
http.server_port=8888 #设置 http 端口号
ln -s /usr/bin/fdfs_storaged /usr/local/bin
service fdfs_storaged start #启动storage,启动会根据配置文件的设置自动创建多级存储目录
效验
cat /data/fastdfs-storage/logs/storaged.log #查看日志如下
[2018-08-26 15:17:33] INFO - FastDFS v5.05, base_path=/data/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=1, 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
data path: /data/fastdfs-storage/data, mkdir sub dir...
mkdir data path: 00 ...
mkdir data path: 01 ...
mkdir data path: 02 ...
... ...
mkdir data path: FE ...
mkdir data path: FF ...
data path: /data/fastdfs-storage/data, mkdir sub dir done.
[2018-08-26 15:17:39] 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
[2018-08-26 15:17:39] INFO - file: storage_func.c, line: 254, tracker_client_ip: 172.21.0.7, my_server_id_str: 172.21.0.7, g_server_id_in_filename: 117446060
[2018-08-26 15:17:39] INFO - file: tracker_client_thread.c, line: 310, successfully connect to tracker server 140.142.190.248:22122, as a tracker client, my ip is 172.21.0.7
[2018-08-26 15:17:39] INFO - file: storage_sync.c, line: 2698, successfully connect to storage server 140.142.190.248:23000
//确认启动成功后,可以运行 fdfs_monitor 查看 storage服务器是否已经登记到 tracker服务器。
[2018-08-26 15:18:55] DEBUG - base_path=/data/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 140.143.193.248:22122
group count: 1
Group 1:
group name = group1
disk total space = 50395 MB
disk free space = 42721 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 = 140.143.193.248
ip_addr = 140.142.190.248 ACTIVE //表示成功
... ...
last_heart_beat_time = 2018-08-26 15:18:38
last_source_update = 1970-01-01 08:00:00
last_sync_update = 1970-01-01 08:00:00
last_synced_timestamp = 1970-01-01 08:00:00
给storage安装nginx并配置
主要目的是为了提供 http 的访问服务,同时解决 group 中 storage服务器的同步延迟问题。
nginx需要添加fastdfs-nginx-module模块
tar -zxvf fastdfs-nginx-module_v1.16.tar.gz -C /usr/local/src/
tar zxf nginx-1.8.0.tar.gz -C /usr/local/src/
cd /usr/local/src/nginx
//--prefix为指定安装路径
./configure --prefix=/data/nginx --add-module=/usr/local/src/fastdfs-nginx-module/src
ln -sv /usr/include/fastcommon /usr/local/include/fastcommon
ln -sv /usr/include/fastdfs /usr/local/include/fastdfs
make
make install
//拷贝配置文件(注意下面cp路径为安装软件路径)
cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
cp /download/fastDFS_All/FastDFS/conf/mime.types /etc/fdfs/
cp /download/fastDFS_All/FastDFS/conf/http.conf /etc/fdfs/
cp /download/fastDFS_All/FastDFS/conf/anti-steal.jpg /etc/fdfs/
//nginx添加配置
vim /data/nginx/conf/nginx.conf
//添加如下配置
listen 9999;
location ~/group[1-3]/M00 {
root /data/fastdfs-storage/data;
ngx_fastdfs_module;
}
vim /etc/fdfs/mod_fastdfs.conf 修改配置
base_path=/data/fastdfs-storage #保存日志目录
tracker_server=192.168.116.145:22122 #tracker 服务器的 IP 地址以及端口号
url_have_group_name = true #文件 url 中是否有 group 名
store_path0=/data/fastdfs-storage # 存储路径
http.need_find_content_type=true # 从文件扩展名查找文件类型 (nginx 时 为true)
group_count = 3 #设置组的个数,事实上这次只使用了group1
在文件末添加如下内容:
[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/data/fastdfs-storage
[group2]
group_name=group2
storage_server_port=23000
store_path_count=1
store_path0=/data/fastdfs-storage
[group3]
group_name=group3
storage_server_port=23000
store_path_count=1
store_path0=/data/fastdfs-storage
ln -s /data/fastdfs-storage/data /data/fastdfs-storage/data/M00
/data/nginx/sbin/nginx -s reload ##重启
/data/nginx/sbin/nginx ###启动
给tracker安装nginx并配置
./configure --prefix=/data/nginx2 --add-module=/usr/local/src/fastdfs-nginx-module/src
make
make install
nginx 配置文件
//添加至http{ 下
upstream fdfs_group1 {
server 127.0.0.1:9999;
}
//添加至server{下
location /group1/M00 {
proxy_pass http://fdfs_group1;
}
listen 80; 改为-> listen 88;//此处为个人习惯
/data/nginx2/sbin/nginx //启动nginx2
# cd /etc/fdfs/
# mv client.conf.sample client.conf #修改内容如下:
base_path=/data/fastdfs-storage #日志存放路径
tracker_server=140.142.190.248:22122 #tracker 服务器 IP 地址和端口号
http.tracker_server_port=6666 # tracker 服务器的 http 端口号,必须和tracker的设置对应起来
测试是否可以上传
/usr/bin/fdfs_upload_file /etc/fdfs/client.conf /download/Snip20180826_3.png
group1/M00/00/00/rBUAB1uCbEeAQKf-AADkTUguGH0393.png #此为上传成功后的图片地址
140.142.190.248/group1/M00/00/00/rBUAB1uCbEeAQKf-AADkTUguGH0393.png #使用网址查看