FastDFS双节点集群搭建
2021-09-02 本文已影响0人
JasonGofen
环境准备
- 服务器准备 Linux
IP | 组件说明 | 软件目录 | 数据目录 |
---|---|---|---|
192.168.13.48 | FastDFS_v6.07(Tracker)、libfastcommon-1.0.47 | /opt/fastdfs | /home/fastdfs |
192.168.13.49 | FastDFS_v6.07(Tracker)、libfastcommon-1.0.47 | /opt/fastdfs | /home/fastdfs |
192.168.13.50 | FastDFS_v6.07(Storage)、libfastcommon-1.0.47、Nginx1.16.1、Keepalived | /opt/fastdfs | /home/fastdfs |
192.168.13.51 | FastDFS_v6.07(Storage)、libfastcommon-1.0.47、Nginx1.16.1、Keepalived | /opt/fastdfs | /home/fastdfs |
2.安装包准备
链接: https://pan.baidu.com/s/18q6e52qpn0aXe09cUQBd8Q 密码: 71tu
部署安装
1、安装编译环境,四台服务器都要做
yum groups install Development Tools -y
yum install perl -y
mkdir -p /opt/fastdfs /home/fastdfs
mkdir -p /home/fastdfs
cd /opt/fastdfs #为下一步下载源码做准备
2、安装libfastcommon,四台服务器都要做
#下载文件,如果下载不下来,上面的网盘链接都准备好了
wget https://github.com/happyfish100/libfastcommon/archive/V1.0.47.tar.gz
tar -zxvf libfastcommon-1.0.47.tar.gz
cd libfastcommon-1.0.47/
./make.sh
./make.sh install
3、安装FastDFS,四台服务器都要做
$ wget https://github.com/happyfish100/fastdfs/archive/V6.07.tar.gz
tar -zxvf fastdfs-6.07.tar.gz
cd fastdfs-6.07/
./make.sh
./make.sh install
#配置文件准备
cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf #tracker节点
cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf #storage节点
cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf #客户端文件,测试用
cp /opt/fastdfs/fastdfs-6.07/conf/http.conf /etc/fdfs/ #供nginx访问使用
cp /opt/fastdfs/fastdfs-6.07/conf/mime.types /etc/fdfs/ #供nginx访问使用
4、tracker server配置:192.168.13.48,192.168.13.49
$ vim /etc/fdfs/tracker.conf
#需要修改的内容如下
port=22122 # tracker服务器端口(默认22122,一般不修改)
base_path=/data/fastdfs # 存储日志和数据的根目录
#编辑启动文件
$ vim /usr/lib/systemd/system/fastdfs-tracker.service
[Unit]
Description=The FastDFS File server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
ExecStop=/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf stop
ExecRestart=/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
[Install]
WantedBy=multi-user.target
$ systemctl daemon-reload
$ systemctl enable fastdfs-tracker.service
$ systemctl start fastdfs-tracker.service
$ netstat -tulnp #查看服务是否启动,端口是否打开
5.storage server配置:192.168.13.50,192.168.13.51
$ vim /etc/fdfs/storage.conf
#需要修改的内容如下
port=23000 # storage服务端口(默认23000,一般不修改)
base_path=/home/fastdfs # 数据和日志文件存储根目录
store_path0=/home/fastdfs # 第一个存储目录
tracker_server=192.168.13.48:22122 # tracker服务器IP和端口
tracker_server=192.168.13.49:22122 # tracker服务器IP和端口
http.server_port=8888 # http访问文件的端口(默认8888,看情况修改,和nginx中保持一致)
#编辑启动文件
$ vim /usr/lib/systemd/system/fastdfs-storage.service
[Unit]
Description=The FastDFS File server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/bin/fdfs_storaged /etc/fdfs/storage.conf start
ExecStop=/usr/bin/fdfs_storaged /etc/fdfs/storage.conf stop
ExecRestart=/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable fastdfs-storage.service
systemctl start fastdfs-storage.service
netstat -tulnp #查看服务是否启动,端口是否打开
#查看集群状态
$ fdfs_monitor /etc/fdfs/storage.conf list
[2018-11-06 00:00:00] DEBUG - base_path=/data/fastdfs/storage, connect_timeout=30, network_timeout=60, tracker_server_count=2, 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=2, server_index=0
tracker server is 192.168.0.1:22122
group count: 1
Group 1:
...
6.Client配置:192.168.13.50,192.168.13.51
$ vim /etc/fdfs/client.conf
#需要修改的内容如下
base_path=/data/fastdfs
tracker_server=192.168.13.48:22122 # tracker服务器IP和端口
tracker_server=192.168.13.49:22122 # tracker服务器IP和端口
#保存后测试,返回ID表示成功 如:group1/M00/00/00/xx.tar.gz
$ fdfs_upload_file /etc/fdfs/client.conf testfile
7.安装nginx和fastdfs-nginx-module:192.168.13.50,192.168.13.51
#安装 fastdfs-nginx-module V1.22
wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.22.tar.gz
cp /opt/fastdfs/fastdfs-nginx-module-1.22/src/mod_fastdfs.conf /etc/fdfs
#在两台storage节点上安装nginx1.16.1
useradd -s /sbin/nologin -M nginx
id nginx
mkdir -p /var/lib/nginx/tmp/client_body
#修改fastdfs-nginx-module-1.20/src/config文件,修改如下:
ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/"
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
#安装OpenSSL https://www.openssl.org/source/ (版本号可能不对,改成百度网盘中的包的版本号就行)
[root@localhost wcw]# tar -zxvf openssl-fips-2.0.2.tar.gz
[root@localhost wcw]# cd openssl-fips-2.0.2
[root@localhost openssl-fips-2.0.2]# ./config
[root@localhost openssl-fips-2.0.2]# make
[root@localhost openssl-fips-2.0.2]# make install
#安装zlib http://www.zlib.net/(版本号可能不对,改成百度网盘中的包的版本号就行)
[root@localhost wcw]# tar -zxvf zlib-1.2.7.tar.gz
[root@localhost wcw]# cd zlib-1.2.7
[root@localhost zlib-1.2.7]# ./configure
[root@localhost zlib-1.2.7]# make
[root@localhost zlib-1.2.7]# make install
#安装pcre https://sourceforge.net/projects/pcre/files/pcre/(版本号可能不对,改成百度网盘中的包的版本号就行)
[root@localhost wcw]# tar -zxvf pcre-8.21.tar.gz
[root@localhost wcw]# cd pcre-8.21
[root@localhost pcre-8.21]# ./configure
[root@localhost pcre-8.21]# make
[root@localhost pcre-8.21]# make install
yum -y install openssl openssl-devel
yum -y install libxml2 libxml2-dev
yum -y install libxslt-devel
yum install gd gd-devel
yum -y install perl-devel perl-ExtUtils-Embed
yum install -y GeoIP-devel.x86_64
yum -y install gperftools
wget http://nginx.org/download/nginx-1.16.1.tar.gz
tar -zxvf nginx-1.16.1.tar.gz
cd nginx-1.16.1
./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_auth_request_module --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E' --add-module=/opt/fastdfs/fastdfs-nginx-module-1.22/src/
make
make install
$ vim /etc/fdfs/mod_fastdfs.conf
#需要修改的内容如下
base_path=/data/fastdfs
tracker_server=192.168.0.1:22122 # tracker服务器IP和端口
tracker_server=192.168.0.2:22122 # tracker服务器IP和端口
url_have_group_name=true
store_path0=/data/fastdfs
#配置nginx.config
$ vim /etc/nginx/nginx.conf
upstream fdfs_group01 {
server 192.168.13.50:8888 weight=1 max_fails=2 fail_timeout=30s;
server 192.168.13.51:8888 weight=1 max_fails=2 fail_timeout=30s;
}
server {
listen 80;
server_name localhost;
location /group01{
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_pass http://fdfs_group01;
expires 30d;
}
}
server {
listen 8888; ## 该端口为storage.conf中的http.server_port相同
server_name localhost;
location ~/group[0-9]/ {
root /data/fastdfs;
ngx_fastdfs_module;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
nginx -t
nginx -s reload
8.在两台storage节点上安装keepalive:192.168.13.50,192.168.13.51
yum install -y nginx keepalived
#更改 192.168.13.50 主节点keepalived的配置
vim /etc/keepalived/keepalived.conf
global_defs {
# 要改,主从机必须不同
router_id FDFS_AP1
}
vrrp_script chk_ngx {
script "/etc/keepalived/check_nginx.sh"
interval 2
weight -5
fall 3
rise 2
}
vrrp_instance VI_1 {
# 要改成当前机器的网卡名称,可以用ifconfig看到
interface eth0
# 要改,主节点MASTER
state MASTER
priority 100
virtual_router_id 11
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
# 要改,本机Storage的IP
unicast_src_ip 192.168.13.50
# 要改, 另一个Storage节点的IP
unicast_peer {
192.168.13.51
}
# 虚拟IP
virtual_ipaddress {
192.168.13.100
}
track_script {
chk_ngx
}
notify_master "/etc/keepalived/notify.sh master"
notify_backup "/etc/keepalived/notify.sh backup"
notify_fault "/etc/keepalived/notify.sh fault"
}
#更改 192.168.13.51 从节点keepalived的配置
vim /etc/keepalived/keepalived.conf
global_defs {
# 要改,主从机必须不同
router_id FDFS_AP2
}
vrrp_script chk_ngx {
script "/etc/keepalived/check_nginx.sh"
interval 2
weight -5
fall 3
rise 2
}
vrrp_instance VI_1 {
# 要改成当前机器的网卡名称,可以用ifconfig看到
interface eth0
# 要改,备节点BACKUP
state BACKUP
priority 100
virtual_router_id 11
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
# 要改,本机Storage的IP
unicast_src_ip 192.168.13.51
# 要改, 另一个Storage节点的IP
unicast_peer {
192.168.13.50
}
# 虚拟IP
virtual_ipaddress {
192.168.13.100
}
track_script {
chk_ngx
}
notify_master "/etc/keepalived/notify.sh master"
notify_backup "/etc/keepalived/notify.sh backup"
notify_fault "/etc/keepalived/notify.sh fault"
}
# 更改50、51两台服务器的check_nginx.sh
vim /etc/keepalived/check_nginx.sh
#往check_nginx.sh中添加如下内容
#!/bin/bash
counter=$(ps -C nginx --no-heading|wc -l)
if [ "${counter}" = "0" ]; then
exit 1
else
exit 0
fi
#启动两台keepalived
systemctl start keepalived.service
大功告成,可以用虚拟IP访问下载文件
http://192.168.13.100:8888/group1/M00/00/00/wKgNMmEvOKyAZT-TAAAAJQKu5xQ379.txt
参考:https://www.cnblogs.com/sunnydou/p/49b92d511047f4f9da6cd727cfd415d5.html