Fastdfs安裝指令碼

2020-08-09 11:29:57

安裝環境:Centos7.3

安裝包:fastdfs-5.05.tar.gz、libfastcommon-1.0.7.tar.gz

用法:

1)將安裝包上傳至伺服器的/data/software目錄

2)執行指令碼:sh FastDFS_single_install.sh

廢話不多說,直接上指令碼:vim FastDFS_single_install.sh

#!/bin/bash
#by Luis
######################################自定義變數##############################################
#安裝包上傳路徑
pkg_dir="/data/software"

#組態檔所在目錄(預設,不可自定義)
conf_dir="/etc/fdfs"

#tracker目錄
tracker_dir="/data/software/data/fastdfs/tracker"

#storage目錄
storage_dir="/data/software/data/fastdfs/storage"
storagefile_dir="/data/software/data/fastdfs/storage/files"

#本機IP
IP=`hostname -I|awk -F" " '{print $1}'`
###############################################################################################

#刪除之前安裝的fdfs組態檔目錄
rm -rf /etc/fdfs

#安裝依賴
yum install gcc libevent libevent-devel -y

#解壓上傳的安裝包libfastcommon-1.0.7.tar.gz和fastdfs-5.05.tar.gz
tar -zxvf libfastcommon-1.0.7.tar.gz
tar -zxvf fastdfs-5.05.tar.gz

#安裝libfastcommon
cd ${pkg_dir}/libfastcommon-1.0.7 
sh make.sh && sh make.sh install

#安裝fastdfs
cd ${pkg_dir}/fastdfs-5.05
sh make.sh && sh make.sh install

#拷貝組態檔http.conf和mime.types至/etc/fdfs
cp ${pkg_dir}/fastdfs-5.05/conf/http.conf ${conf_dir}/
cp ${pkg_dir}/fastdfs-5.05/conf/mime.types ${conf_dir}/

#建立組態檔tracker.conf和storage.conf
cp ${conf_dir}/tracker.conf.sample ${conf_dir}/tracker.conf
cp ${conf_dir}/storage.conf.sample ${conf_dir}/storage.conf

#提前建立相關目錄
mkdir -p ${tracker_dir}
mkdir -p ${storagefile_dir}

#修改組態檔/etc/fdfs/tracker.conf
sed -i 's@base_path=/home/yuqing/fastdfs@base_path='${tracker_dir}'@' /etc/fdfs/tracker.conf

#修改組態檔/etc/fdfs/storage.conf
sed -i 's@base_path=/home/yuqing/fastdfs@base_path='${storage_dir}'@' /etc/fdfs/storage.conf
sed -i 's@store_path0=/home/yuqing/fastdfs@store_path0='${storagefile_dir}'@' /etc/fdfs/storage.conf
sed -i 's@tracker_server=192.168.209.121:22122@tracker_server='${IP}':22122@' /etc/fdfs/storage.conf

#啓動tracker
fdfs_trackerd /etc/fdfs/tracker.conf

#啓動storage
fdfs_storaged /etc/fdfs/storage.conf

#檢查啓動情況
ps -ef |grep fdfs

#輸出結果
if [ `ps -ef |grep fdfs |grep -v grep|wc -l` -eq 2 ];then
	echo -e "\e[1;32m FastDFS Installed and Started Successfully\e[0m"
	echo "設定的本機IP:${IP}"
	echo "安裝包上傳路徑:${pkg_dir}"
	echo "組態檔所在目錄:${conf_dir}"
	echo "Tracker目錄:${tracker_dir}"
	echo "Storage目錄:${storage_dir}"
	echo "Storage檔案目錄:${storagefile_dir}"
else
	echo -e "\e[1;31m FastDFS Installed Faild\e[0m"
fi

以下是Fastdfs的啓停命令:

tracker啓停命令:
啓動:fdfs_trackerd /etc/fdfs/tracker.conf start
停:fdfs_trackerd /etc/fdfs/tracker.conf stop
重新啓動:fdfs_trackerd /etc/fdfs/tracker.conf restart

storage啓停命令:
啓動:fdfs_storaged /etc/fdfs/storage.conf start
停:fdfs_storaged /etc/fdfs/storage.conf stop
重新啓動:fdfs_storaged /etc/fdfs/storage.conf restart

以下是叢集的設定:

叢集部署:
1、在多個節點上安裝好單機模式(執行FastDFS_single_install.sh指令碼)
2、修改每個節點上的storage組態檔(/etc/fdfs/storage.conf)中"tracker_server="部分設定:
tracker_server=xxx.xxx.xxx.xxx:22122
tracker_server=xxx.xxx.xxx.xxx:22122
tracker_server=xxx.xxx.xxx.xxx:22122
...
##星號代表安裝了tracker的ip,裝了多少台tracker就設定多少條tracker_server
3、每個節點重新啓動storage:fdfs_storaged /etc/fdfs/storage.conf restart