前言
大佬说要让技术部方便部署,前面的文档看不懂,所以只能整合成shell脚本了。
正文
1.tracker脚本
#!/bin/bash
echo -e "关闭防火墙"
systemctl stop firewalld.service
systemctl disable firewalld.service
echo -e "===================start install FastDFS=============================="
if [ -z $(rpm -qa | grep gcc-c++) ]
then
echo -e "start install gcc-c"
yum install -y make cmake gcc gcc-c++
fi
if [ -z $(rpm -qa | grep perl) ]
then
echo -e "安装perl"
yum install -y perl
fi
# FastDFS 相关base path
fastDFS_base_path="/home/fastdfs/"
# 软件所在目录
software_path="/usr/local/software/"
echo -e "\033[32m ==============================start install FastDFS============================== \033[0m"
# ----------------安装libfastcommon start----------------
# 解压libfastcommon-master.zip
echo "1.解压libfastcommon-master.zip ----start"
if [ -z $(rpm -qa | grep unzip) ]
then
echo -e "安装unzip"
yum install -y unzip zip
fi
if [ -d "/usr/local/fast/libfastcommon-master" ] ;then
rm -rf /usr/local/fast/libfastcommon-master
fi
unzip ${software_path}libfastcommon-master.zip -d /usr/local/fast/
cd /usr/local/fast/libfastcommon-master/
ls -l
# 编译libfastcommon
cd libfastcommon-master
./make.sh || exit 1
# 安装
./make.sh install || exit 1
echo "解压libfastcommon-master.zip ----end"
echo "---"
# ----------------安装libfastcommon end----------------
# ----------------安装FastDFS start----------------
# 解压FastDFS安装包
echo "2.解压FastDFS安装包 ----start"
if [ -d "/usr/local/fast/FastDFS" ] ;then
rm -rf /usr/local/fast/FastDFS
fi
cd ${software_path}
tar -zxvf ${software_path}FastDFS_v5.05.tar.gz -C /usr/local/fast/
cd /usr/local/fast/FastDFS/
ls -l
# 编译
./make.sh || exit 1
#安装
./make.sh install || exit 1
echo "解压FastDFS安装包 ----end"
echo "---"
# ----------------安装FastDFS end----------------
# ----------------配置Tracker服务 start----------------
echo "3.开始配置tracker_server属性"
cd /etc/fdfs/
echo "把tracker.conf文件进行cope一份"
cp ${software_path}tracker.conf /etc/fdfs/
# tracker目录是否存在,不存在则创建
if [ ! -d ${fastDFS_base_path}"tracker" ] ;then
mkdir -p ${fastDFS_base_path}"tracker"
fi
# ----------------配置Tracker服务 end----------------
echo -e "\033[32m ==============================install Nginx Start============================== \033[0m"
# ----------------安装和配置nginx start----------------
# 安装依赖
echo "安装依赖"
yum install -y pcre
yum install -y pcre-devel
yum install -y zlib
yum install -y zlib-devel
echo "解压fastdfs-nginx-module"
#解压fastdfs-nginx-module_v1.16.tar.gz
if [ -d "/usr/local/fast/fastdfs-nginx-module" ];then
echo "删除fastdfs-nginx-module"
rm -rf /usr/local/fast/fastdfs-nginx-module/
fi
cd ${software_path}
tar -zxvf ${software_path}fastdfs-nginx-module_v1.16.tar.gz -C /usr/local/fast/
echo "解压ngx_cache_purge"
#解压ngx_cache_purge-2.3.tar.gz
if [ -d "/usr/local/fast/ngx_cache_purge-2.3" ];then
echo "删除ngx_cache_purge-2.3"
rm -rf /usr/local/fast/ngx_cache_purge-2.3
fi
tar -zxvf ${software_path}ngx_cache_purge-2.3.tar.gz -C /usr/local/fast/
cd /usr/local/fast/
ls -l
echo "解压nginx"
#解压nginx
if [ -d "/usr/local/nginx-1.8.0" ];then
echo "删除nginx1.8.0"
rm -rf /usr/local/nginx-1.8.0/
fi
if [ -d "/usr/local/nginx" ];then
echo "删除nginx"
rm -rf /usr/local/nginx/
fi
tar -zxvf ${software_path}nginx-1.8.0.tar.gz -C /usr/local/
cd /usr/local/nginx-1.8.0/
ls -l
echo "nginx加入ngx_cache_purge模块"
# nginx加入ngx_cache_purge模块
./configure --add-module=/usr/local/fast/ngx_cache_purge-2.3
echo "编译安装nginx"
# 编译安装nginx
make || exit 1
make install || exit 1
echo "修改nginx配置"
rm -rf /usr/local/nginx/conf/nginx.conf
cp ${software_path}nginx_tracker.conf /usr/local/nginx/conf/nginx.conf
echo "创建文件夹"
# 判断/var/cache/nginx/proxy_cache/tmp目录是否存在,不存在则创建
if [ ! -d "/var/cache/nginx/proxy_cache/tmp" ] ;then
mkdir -p "/var/cache/nginx/proxy_cache/tmp"
fi
echo "启动tracker服务"
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
echo "打印tracker进程"
ps -el | grep fdfs
echo "启动nginx服务"
/usr/local/nginx/sbin/nginx
echo "打印nginx进程"
ps -ef | grep nginx
2.storage脚本
#!/bin/bash
echo -e "关闭防火墙"
systemctl stop firewalld.service
systemctl disable firewalld.service
if [ -z $(rpm -qa | grep gcc-c++) ]
then
echo -e "start install gcc-c"
yum install -y make cmake gcc gcc-c++
fi
if [ -z $(rpm -qa | grep perl) ]
then
echo -e "安装perl"
yum install -y perl
fi
if [ -z $(rpm -qa | grep unzip) ]
then
echo -e "安装unzip"
yum install -y unzip zip
fi
# FastDFS 相关base path
fastDFS_base_path="/home/fastdfs/"
# 软件所在目录
software_path="/usr/local/software/"
echo -e "\033[32m ==============================start install FastDFS============================== \033[0m"
# ----------------安装libfastcommon start----------------
# 解压libfastcommon-master.zip
echo "1.解压libfastcommon-master.zip ----start"
if [ -d "/usr/local/fast/libfastcommon-master/" ];then
echo "删除libfastcommon-master"
rm -rf /usr/local/fast/libfastcommon-master/
fi
unzip ${software_path}libfastcommon-master.zip -d /usr/local/fast/
cd /usr/local/fast/libfastcommon-master/
ls -l
# 编译libfastcommon
./make.sh || exit 1
# 安装
./make.sh install || exit 1
echo "解压libfastcommon-master.zip ----end"
echo "---"
# ----------------安装libfastcommon end----------------
# ----------------安装FastDFS start----------------
# 解压FastDFS安装包
echo "2.解压FastDFS安装包 ----start"
if [ -d "/usr/local/fast/FastDFS/" ];then
echo "删除FastDFS"
rm -rf /usr/local/fast/FastDFS/
fi
cd ${software_path}
tar -zxvf ${software_path}FastDFS_v5.05.tar.gz -C /usr/local/fast/
cd /usr/local/fast/FastDFS/
ls -l
# 编译
./make.sh || exit 1
#安装
./make.sh install || exit 1
echo "解压FastDFS安装包 ----end"
echo "---"
# ----------------安装FastDFS end----------------
# ----------------配置storage服务 start----------------
echo "3.开始配置storage_server属性"
cd /etc/fdfs/
cp ${software_path}storage.conf storage.conf
# storage目录是否存在,不存在则创建
if [ ! -d ${fastDFS_base_path}"storage" ] ;then
mkdir -p ${fastDFS_base_path}"storage"
fi
# ----------------配置storage服务 end----------------
echo -e "\033[32m ==============================install Nginx Start============================== \033[0m"
# ----------------安装和配置nginx start----------------
# 安装依赖
echo "安装依赖"
yum install -y pcre
yum install -y pcre-devel
yum install -y zlib
yum install -y zlib-devel
echo "解压fastdfs-nginx-module"
if [ -d "/usr/local/fast/fastdfs-nginx-module/" ];then
echo "删除fastdfs-nginx-module"
rm -rf /usr/local/fast/fastdfs-nginx-module/
fi
#解压fastdfs-nginx-module_v1.16.tar.gz
cd ${software_path}
tar -zxvf ${software_path}fastdfs-nginx-module_v1.16.tar.gz -C /usr/local/fast/
cd /usr/local/fast/fastdfs-nginx-module/src/
ls -l
sed -i "s|CORE_INCS=\"\$CORE_INCS /usr/local/include/fastdfs /usr/local/include/fastcommon/\"|CORE_INCS=\"\$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/\"|g" config
echo "解压nginx"
#解压nginx
if [ -d "/usr/local/nginx-1.8.0" ];then
echo "删除nginx1.8.0"
rm -rf /usr/local/nginx-1.8.0/
fi
if [ -d "/usr/local/nginx" ];then
echo "删除nginx"
rm -rf /usr/local/nginx/
fi
tar -zxvf ${software_path}nginx-1.8.0.tar.gz -C /usr/local/
cd /usr/local/nginx-1.8.0/
ls -l
echo "nginx加入ngx_cache_purge模块"
# nginx加入ngx_cache_purge模块
./configure --add-module=/usr/local/fast/fastdfs-nginx-module/src/
echo "编译安装nginx"
# 编译安装nginx
make || exit 1
make install || exit 1
echo "复制配置文件mod_fastdfs.conf"
cp ${software_path}mod_fastdfs.conf /etc/fdfs/
echo "复制http.conf和mime.types"
cd /usr/local/fast/FastDFS/conf/
cp http.conf mime.types /etc/fdfs/
echo "修改nginx配置"
rm -rf /usr/local/nginx/conf/nginx.conf
cp ${software_path}nginx_storage.conf /usr/local/nginx/conf/nginx.conf
echo "创建文件夹"
# 判断/var/cache/nginx/proxy_cache/tmp目录是否存在,不存在则创建
if [ ! -d "/var/cache/nginx/proxy_cache/tmp" ] ;then
mkdir -p "/var/cache/nginx/proxy_cache/tmp"
fi
echo "启动storage服务"
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf
echo "打印storage进程"
ps -el | grep fdfs
echo "启动nginx服务"
/usr/local/nginx/sbin/nginx
echo "打印nginx进程"
ps -ef | grep nginx