集群安装
1.FastDFS安装

  • Tracker,nginx

       192.168.56.113
       192.168.56.114

  • storage

       group1
      192.168.56.115
      192.168.56.116
      group1
      192.168.56.116
      192.168.56.117

FastDFS相关软件下载地址 https://sourceforge.net/projects/fastdfs/files/
* 安装gcc。命令:apt-get install make

apt-get install gcc 
apt-get install cmake
apt-get install gcc-c++

 

1.1  下载libfastcommon(项目通用函数库)

1)可以从git下载

git clone https://github.com/happyfish100/libfastcommon.git

 

2)编译安装

cd libfastcommon/
./make.sh
./make.sh install

 

libfastcommon默认安装到了/usr/lib64/目录下,而Fastdfs程序使用,/usr/local/lib/,所以创建文件链接

3)创建链接

mkdir /usr/local/lib/
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
1)编译安装FastDFS

cd /usr/local/src
wget http://nchc.dl.sourceforge.net/project/fastdfs/FastDFS%20Server%20Source%20Code/FastDFS%20Server%20with%20PHP%20Extension%20Source%20Code%20V5.08/FastDFS_v5.08.tar.gz
tar -zxvf FastDFS_v5.08.tar.gz
cd FastDFS
./make.sh
./make.sh install

* 服务脚本在:

/etc/init.d/fdfs_storaged
/etc/init.d/fdfs_trackerd

* 配置文件在:

/etc/fdfs/client.conf.sample
/etc/fdfs/storage.conf.sample
/etc/fdfs/tracker.conf.sampl

2)修改服务脚本
* 因为FastDFS服务脚本设置的bin目录为/usr/local/bin/下,但是实际我们安装在了/u
sr/bin/下面。所以我们需要修改FastDFS配置文件中的路径,也就是需要修改俩
个配置文件:

vim /etc/init.d/fdfs_storaged
%s+/usr/local/bin+/usr/bin ---替换服务脚本路径
vim /etc/init.d/fdfs_trackerd
%s+/usr/local/bin+/usr/bin ---替换服务脚本路径

 


3)修改Tracker配置文件

cd /etc/fdfs/
cp tracker.conf.sample tracker.conf
vim tracker.conf

 先修改base_path即可

 4)启动Tracker

/etc/init.d/fdfs_trackerd start
ps -ef |grep fdfs

 

5)四个storage节点修改Storage配置文件

cd /etc/fdfs/
cp storage.conf.sample storage.conf
vim storage.conf

 修改以下配置

disabled=false #启用配置文件
group_name=group1 #组名,根据实际情况修改
port=23000 #设置storage的端口号
base_path=/home/tuna/data/fastdfs/storage #设置storage的日志目录(需预先创建)
store_path_count=1 #存储路径个数,需要和store_path个数匹配
store_path0=/home/tuna/data/fastdfs/storage#存储路径
tracker_server=192.168.56.113:22122
tracker_server=192.168.56.114:22122
http.server_port=8888 #设置http端口号

创建对应的目录

sudo mkdir -p /home/tuna/data/fastdfs/storage

6)启动storage

/etc/init.d/fdfs_storaged start 

查看是否启动

ps -ef |grep fdfs

1.3 配置Client

cd /etc/fdfs/
cp client.conf.sample client.conf
vim client.conf


base_path/home/tuna/data/fastdfs/client
tracker_server=192.168.56.113:22122 
tracker_server=192.168.18.114:22122

 


* 上传文件

/usr/bin/fdfs_upload_file /etc/fdfs/client.conf ./redis.sh

 

在Storage节点上观察上传的文件

cd /home/tuna/data/fastdfs/storage/data/00/00

ls

 

启动storage

4. 在所有storage节点安装nginx
 在storage上安装的nginx主要为了提供http的访问服务,同时解决group中storage服务器的同步延迟问题

两台机器都要安装nginx
storage节点安装fastdfs-nginx-module_v1.16.tar.gz
1)安装nginx

sudo wget http://nginx.org/download/nginx-1.12.0.tar.gz
tar -zxvf nginx-1.12.0.tar.gz
cd nginx-1.12.0


加入模块命令:

./configure --add-module=/home/tuna/fastdfs-nginx-module/src
sudo make&&sudo make install

 

复制fastdfs-ngin-module中的配置文件,到/etc/fdfs目录中

sudo cp /home/tuna/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/

 

/etc/fdfs/ 目录下,我们刚刚copy过来的mod_fastdfs.conf 文件。

vim /etc/fdfs/mod_fastdfs.conf

 

修改一下配置

base_path=/home/fastdfs #保存日志目录
tracker_server=192.168.56.113:22122
tracker_server=192.168.56.114:22122
storage_server_port=23000#storage服务器的端口号
group_name=group1#当前服务器的group名
url_have_group_name = true #文件url中是否有group名
store_path_count=1 #存储路径个数,需要和store_path个数匹配
store_path0=/home/fastdfs #存储路径
http.need_find_content_type=true#从文件扩展名查找文件类型(nginx时为true)
group_count = 2 #设置组的个数
在末尾增加2个组的具体信息:
[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/home/fastdfs

[group2]
group_name=group2
storage_server_port=23000
store_path_count=1
store_path0=/home/fastdfs

 

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

ln -s /home/fastdfs/data /home/fastdfs/data/M00

 

3) 复制FastDFS里的2个文件,到/etc/fdfs目录中

sudo cp http.conf mime.types /etc/fdfs/

 4)

创建一个软连接,在/fastdfs/storage文件存储目录下创建软连接,将其链接到实际存放数据的目录

sudo ln -s /home/tuna/data/fastdfs/storage/data /home/tuna/data/fastdfs/storage/data/M00

 

5)修改Nginx配置文件

cd /usr/local/nginx/conf
vim nginx.conf

 

做以下配置

server {
listen 8888;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location ~/group([0-9])/M00 {

ngx_fastdfs_module;
}

6)开启Nginx

/usr/local/nginx/sbin/nginx

* * * * *


5. 两个tracker和nginx整合

* 需要ngx_cache_purge-2.3.tar.gz 包
sudo apt-get update
sudo apt-get install libpcre3 libpcre3-dev
sudo apt-get install openssl libssl-dev
1)

tar -zxvf nginx-1.12.0.tar.gz 
tar -zxvf ngx_cache_purge-2.3.tar.gz 
cd nginx-1.12.0
./configure --prefix=/usr/local/nginx --add-module=/root/ngx_cache_purge-2.3
make 
make install

2)

user root; 
worker_processes 1; 

#error_log logs/error.log; 
#error_log logs/error.log notice; 
error_log logs/error.log info; 

#pid logs/nginx.pid; 


events { 
worker_connections 1024; 
} 


http { 
include mime.types; 
default_type application/octet-stream; 
#设置缓存参数 
server_names_hash_bucket_size 128; 
client_header_buffer_size 32k; 
large_client_header_buffers 4 32k; 
client_max_body_size 300m; 
sendfile on; 
tcp_nopush on; 
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 /var/cache/nginx/proxy_cache levels=1:2 keys_zone=http-cache:500m max_size=10g inactive=30d; 

proxy_temp_path /var/cache/nginx/proxy_cache/tmp; 

keepalive_timeout 65; 

#设置group服务器 
upstream fdfs_group1 { 
server 192.168.56.114:8888 weight=1 max_fails=2 fail_timeout=30s; 
server 192.168.56.115:8888 weight=1 max_fails=2 fail_timeout=30s; 
} 
upstream fdfs_group2 { 
server 192.168.56.116:8888 weight=1 max_fails=2 fail_timeout=30s; 
server 192.168.56.117:8888 weight=1 max_fails=2 fail_timeout=30s; 
} 

server { 
listen 80; 
server_name localhost; 
charset utf-8; 
#access_log /usr/local/nginx/logs/localhost.access.log main; 

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 172.16.1.0/24; 
deny all; 
proxy_cache_purge http-cache $1$is_args$args; 
} 
} 

} 

 

创建缓存目录:

sudo mkdir -p /var/cache/nginx/proxy_cache/tmp

 

3) 启动nginx

/usr/local/nginx/sbin/nginx 

 

通过nginx做个反向代理,实现一台机器控制多个节点

 

欢迎批评指正,我的看云地址:https://www.kancloud.cn/tuna_dai_/day01/347597,qq:931309012

posted on 2017-06-07 09:34  tuna-daily  阅读(318)  评论(0编辑  收藏  举报