1. 程式人生 > >FastDFS叢集部署

FastDFS叢集部署

FastDFS之——叢集的安裝、 配置、 使用 

FastDFS 叢集規劃:
跟蹤伺服器 1:192.168.1.121     tracker-1
跟蹤伺服器 2:192.168.1.122     tracker-2
儲存伺服器 1:192.168.1.125     storage-group1-1
儲存伺服器 2:192.168.1.126     storage-group1-2
儲存伺服器 3:192.168.1.127     storage-group2-1
儲存伺服器 4:192.168.1.128     storage-group2-2

cd /usr/local/software/ && ls
put fastdfs-nginx-module_v1.16.tar.gz
put FastDFS_v5.05.tar.gz
put libfastcommon-master.zip
put nginx-1.6.2.tar.gz

scp -r /usr/local/software/ 192.168.1.122:/usr/local
scp -r /usr/local/software/ 192.168.1.125:/usr/local
scp -r /usr/local/software/ 192.168.1.126:/usr/local
scp -r /usr/local/software/ 192.168.1.127:/usr/local
scp -r /usr/local/software/ 192.168.1.128:/usr/local

下載地址:https://codeload.github.com/happyfish100/libfastcommon/zip/master
下載地址:https://codeload.github.com/happyfish100/fastdfs/zip/master
安裝 libfastcommon (https://github.com/happyfish100/libfastcommon)
yum install make cmake gcc gcc-c++
使用命令:unzip fastdfs-master.zip -d /usr/local/fast/

到/usr/local/fast/fastdfs-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
ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so
跟蹤伺服器 1:192.168.1.121     tracker-1
跟蹤伺服器 2:192.168.1.122     tracker-2
下載地址:https://codeload.github.com/happyfish100/fastdfs/zip/master
#cd /etc/fdfs/
cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
vim tracker.conf
base_path=/fastdfs/tracker
# the method of selecting group to upload files
# 0: round robin
# 1: specify group
# 2: load balance, select the max free space group to upload file
store_lookup=0

# which group to upload file
# when store_lookup set to 1, must set store_group to the group name
store_group=group2

scp tracker.conf 192.168.1.125:/etc/fdfs/
mkdir -p /fastdfs/tracker
cd /fastdfs/tracker/ && ll
cd /fastdfs/tracker/logs/ && ll
tail -f -n 50 /fastdfs/tracker/logs/trackerd.log 
ps -ef|grep fdfs
netstat -tunpl | grep fdfs

儲存伺服器 1:192.168.1.125     storage-group1-1
儲存伺服器 2:192.168.1.126     storage-group1-2
儲存伺服器 3:192.168.1.127     storage-group2-1
儲存伺服器 4:192.168.1.128     storage-group2-2
cd /etc/fdfs/ && ll
cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
vim storage.conf
disabled=false
group_name=group1
port=23000
base_path=/fastdfs/storage
store_path0=/fastdfs/storage
tracker_server=192.168.1.121:22122
tracker_server=192.168.1.122:22122
http.server_port=8888
store_path_count=1

scp /etc/fdfs/storage.conf 92.168.1.126:/etc/fdfs
scp /etc/fdfs/storage.conf 92.168.1.127:/etc/fdfs
scp /etc/fdfs/storage.conf 92.168.1.128:/etc/fdfs


儲存伺服器 3:192.168.1.127     storage-group2-1
儲存伺服器 4:192.168.1.128     storage-group2-2
vim /etc/fdfs/storage.conf
group_name=group2

mkdir -p /fastdfs/storage
/etc/init.d/fdfs_storaged start
cd /fastdfs/storage/ && ll
tail -f /fastdfs/storage/logs/storaged.log
/etc/init.d/fdfs_trackerd stop
tail -f /fastdfs/storage/logs/storaged.log
/etc/init.d/fdfs_trackerd start
/etc/init.d/fdfs_trackerd status



cd /usr/bin/ && ll | grep fdfs
/usr/bin/fdfs_monitor /etc/fdfs/storage.conf
cd /etc/fdfs/ && ll
cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
vim /etc/fdfs/client.conf
base_path=/fastdfs/tracker/
tracker_server=192.168.1.121:22122
tracker_server=192.168.1.122:22122
cd /fastdfs/storage/ && ll
cd /fastdfs/storage/data/ && ls
cd /fastdfs/storage/data/00/00/ && ll

/usr/bin/fdfs_upload_file /etc/fdfs/client.conf /usr/local/a.txt
group1/M00/00/00/rBH2Clw27MeAOtXWAAAVz0MFInw763.txt
cd /usr/local/software/ && ls
tar -xzvf fastdfs-nginx-module_v1.16.tar.gz
cd /usr/local/fast/fastdfs-nginx-module/src/ && ll
vim /usr/local/fast/fastdfs-nginx-module/src/config
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
cd /usr/local/software/ && ls
tar -zxvf nginx-1.6.2.tar.gz
cd /usr/local/nginx-1.6.2/ && ll
./configure --add-module=/usr/local/fast/fastdfs-nginx-module/src 
make && make install
cd /usr/local/fast/fastdfs-nginx-module/src/ && ll
cp /usr/local/fast/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
cd /etc/fdfs/ && ll
儲存伺服器 1:192.168.1.125     storage-group1-1
儲存伺服器 2:192.168.1.126     storage-group1-2
vim /etc/fdfs/mod_fastdfs.conf
connect_timeout=10
tracker_server=192.168.1.121:22122
tracker_server=192.168.1.122:22122
url_have_group_name = true
[group1]
group_name=group1
storage_server_port=23000
group_count = 1
store_path0=/fastdfs/storage
[group2]
group_name=group2
storage_server_port=23000
group_count = 1
store_path0=/fastdfs/storage

scp /etc/fdfs/mod_fastfds.conf 192.168.1.126:/etc/fdfs
scp /etc/fdfs/mod_fastfds.conf 192.168.1.127:/etc/fdfs
scp /etc/fdfs/mod_fastfds.conf 192.168.1.128:/etc/fdfs

cd /usr/local/fast/FastDFS/ && ll
cd /usr/local/fast/FastDFS/conf/ && ll
cp http.conf mime.types /etc/fdfs/
ln -s /fastdfs/storage/data/ /fastdfs/storage/data/M00
vim /usr/local/nginx/conf/nginx.conf
listen       8888;
        location ~/group([0-9])/M00 {
            ngx_fastdfs_module;
        }

scp /usr/local/nginx/conf/nginx.conf 192.168.1.126:/usr/local/nginx/conf/
scp /usr/local/nginx/conf/nginx.conf 192.168.1.127:/usr/local/nginx/conf/
scp /usr/local/nginx/conf/nginx.conf 192.168.1.128:/usr/local/nginx/conf/
/usr/local/nginx/sbin/nginx











配置 Nginx, 設定負載均衡以及快取

put ngx_cache_purge-2.3.tar.gz
tar -zxvf ngx_cache_purge-2.3.tar.gz -C /usr/local/fast/
cd /usr/local/fast/ && ll
cd /usr/local/nginx-1.6.2/ && ll
./configure --add-module=/usr/local/fast/ngx_cache_purge-2.3
make && make install
http {
	include mime.types;
	default_type application/octet-stream;
	#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
	# '$status $body_bytes_sent "$http_referer" '
	# '"$http_user_agent" "$http_x_forwarded_for"';
	#access_log logs/access.log main;
	sendfile on;
	tcp_nopush on;
	#keepalive_timeout 0;
	keepalive_timeout 65;
	#gzip on;
	#設定快取
	server_names_hash_bucket_size 128;
	client_header_buffer_size 32k;
	large_client_header_buffers 4 32k;
	client_max_body_size 300m;
	proxy_redirect off;
	proxy_set_header Host $http_host;
	proxy_set_header X-Real-IP $remote_addr;
	proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	proxy_connect_timeout 90;
	proxy_send_timeout 90;
	proxy_read_timeout 90;
	proxy_buffer_size 16k;
	proxy_buffers 4 64k;
	proxy_busy_buffers_size 128k;
	proxy_temp_file_write_size 128k;
	#設定快取儲存路徑、儲存方式、分配記憶體大小、磁碟最大空間、快取期限
	proxy_cache_path /fastdfs/cache/nginx/proxy_cache levels=1:2
	keys_zone=http-cache:200m max_size=1g inactive=30d;
	proxy_temp_path /fastdfs/cache/nginx/proxy_cache/tmp;
	#設定 group1 的伺服器
	upstream fdfs_group1 {
		server 192.168.50.137:8888 weight=1 max_fails=2 fail_timeout=30s;
		server 192.168.50.138:8888 weight=1 max_fails=2 fail_timeout=30s;
	} #
	設定 group2 的伺服器
	upstream fdfs_group2 {
		server 192.168.50.139:8888 weight=1 max_fails=2 fail_timeout=30s;
		server 192.168.50.140:8888 weight=1 max_fails=2 fail_timeout=30s;
	}
	server {
		listen 8000;
		server_name localhost;
		#charset koi8-r;
		#access_log logs/host.access.log main;
		#設定 group 的負載均衡引數
		location /group1/M00 {
			proxy_next_upstream http_502 http_504 error timeout invalid_header;
			proxy_cache http-cache;
			proxy_cache_valid 200 304 12h;
			proxy_cache_key $uri$is_args$args;
			proxy_pass http://fdfs_group1;
			expires 30d;
		}
		location /group2/M00 {
			proxy_next_upstream http_502 http_504 error timeout invalid_header;
			proxy_cache http-cache;
			proxy_cache_valid 200 304 12h;
			proxy_cache_key $uri$is_args$args;
			proxy_pass http://fdfs_group2;
			expires 30d;
		} 
		#設定清除快取的訪問許可權
		location ~/purge(/.*) {
			allow 127.0.0.1;
			allow 192.168.1.0/24;
			deny all;
			proxy_cache_purge http-cache $1$is_args$args;
		}
		#error_page 404 /404.html;
		# redirect server error pages to the static page /50x.html
		#
		error_page 500 502 503 504 /50x.html;
			location = /50x.html {
			root html;
		}
	}
}