fastdfs单机部署脚本,两种版本的部署脚本
fastdfs单机部署
fdfs是一个常用的分布式文件存储服务器
可以根据情况进行配置调整,需要多节点fastdfs可以根据情况添加修改配置
两种版本的部署方案脚本,第一个脚本是部署的fasdfs-5.05的版本,新更新的第二个脚本是fasdfs-6.07的版本脚本稍微有改变
脚本1:
#!/bin/sh
# base image
#LABEL version="1.0"
#date = 2019-8-9
#MAINTAINER zhi_jie1c@163.com
#COPY fastdfs-nginx-module /usr/local/fastdfs-nginx-module
#几个包最好手动下载放到/src目录下面有时候github国内网络不稳定
yum provides '*/applydeltarpm'
yum -y groupinstall "Development Tools"
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
# Download source package libfastcommon fasts-nginx-moudel fastdfs
mkdir /src
cd /src
if [ -f /src/V1.0.7.tar.gz ];then
echo -e "\n\e[1;31m----------V1.0.7.tar.gz exit-------- exit\e[0m"
else
wget -P /src https://github.com/happyfish100/libfastcommon/archive/V1.0.7.tar.gz --no-check-certificate
if [ $? != 0 ];then
echo '下载包时github网络连接失败,请重新下载安装包V1.0.7'
exit
fi
fi
if [ -f /src/fastdfs-nginx-module_v1.16.tar.gz ];then
echo -e "\n\e[1;31m----------efastdfs-nginx-module_v1.16.tar.gz-------- exit\e[0m"
else
wget -P /src http://jaist.dl.sourceforge.net/project/fastdfs/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz --no-check-certificate
if [ $? != 0 ];then
echo '下载nginx插件失败,请重新下载包fastdfs-nginx-module'
exit
fi
fi
if [ -f /src/V5.05.tar.gz ];then
echo -e "\n\e[1;31m----------V5.05.tar.gz exit-------- exit\e[0m"
else
wget -P /src https://github.com/happyfish100/fastdfs/archive/V5.05.tar.gz --no-check-certificate
if [ $? != 0 ];then
echo '下载包时github网络连接失败,请重新下载安装包V5.05'
exit
fi
fi
if [ -f /src/nginx-1.18.0.tar.gz ];then
echo -e "\n\e[1;31m----------nginx-1.18.0.tar.gz exit-------- exit\e[0m"
else
wget -P /src http://nginx.org/download/nginx-1.18.0.tar.gz --no-check-certificate
if [ $? != 0 ];then
echo '下载nginx包失败,请重新下载安装包nginx-1.18.0'
exit
fi
fi
#nginx-1.18.0.tar.gz /src
# 解压源码包
tar xf V1.0.7.tar.gz -C /src
tar xf fastdfs-nginx-module_v1.16.tar.gz -C /src
tar xf V5.05.tar.gz -C /src
tar xf nginx-1.18.0.tar.gz -C /src
# 安装libfastcommon跟fastdfs
cd /src/libfastcommon-1.0.7
./make.sh && ./make.sh install
cd /src/fastdfs-5.05
sed -i -e '/^TARGET_PREFIX=$DESTDIR&/d;s/usr/&\/local/' make.sh
./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/local/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
ln -s /usr/local/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so
#替换tracker配置参数
cd /etc/fdfs
cp tracker.conf.sample tracker.conf
mkdir -p /fastdfs/tracker && mkdir -p /fastdfs/storage
sed -i -e 's/\/home\/yuqing\/fastdfs/\/fastdfs\/tracker/g' tracker.conf
echo "/usr/local/nginx/sbin/nginx -s reload" >>/etc/rc.d/rc.local
chkconfig --add fdfs_trackerd && chkconfig fdfs_trackerd on
#优化ip地址变化影响迁移配置
sed -i -e 's/use_storage_id\ =\ false/use_storage_id\ =\ ture/g' tracker.conf
sed -i -e '/^id_type_in_filename&/d;s/ip/id/g' tracker.conf
cp storage.conf.sample storage.conf
sed -i -e 's/\/home\/yuqing\/fastdfs/\/fastdfs\/storage/g' storage.conf
ID=`echo $SSH_CONNECTION | awk -F" " '{print $3}'` #这里是抓取的远程连接的主机的IP
echo -e "# <id> <group_name> <ip_or_hostname>\n100001 group1 $ID" >/src/fastdfs-5.05/conf/storage_ids.conf
cp /src/fastdfs-5.05/conf/storage_ids.conf /etc/fdfs/
echo "tracker_server=$ID:22122" >>storage.conf
sed -i -e '/^tracker_server =/d' storage.conf
#echo "store_path0=/fastdfs/storage" >>storage.conf
sed -i -e 's/8888/80/g' /etc/fdfs/storage.conf
chkconfig --add fdfs_storaged && chkconfig fdfs_storaged on
/etc/init.d/fdfs_trackerd start
/etc/init.d/fdfs_storaged start
cp client.conf.sample client.conf
sed -i -e 's/\/home\/yuqing\/fastdfs/\/fastdfs\/tracker/g' client.conf
sed -i -e '/^tracker_server =/d' client.conf
echo "tracker_server=$ID:22122" >>client.conf
cd /src/fastdfs-nginx-module/src/
sed -i -e 's/\/usr\/local\/include\/fastcommon/\/usr\/include\/fastcommon/' config
sed -i -e 's/\/home\/yuqing\/fastdfs/\/fastdfs\/storage/g' mod_fastdfs.conf
sed -i -e '/^tracker_server=tracker:22122$/d' mod_fastdfs.conf
sed -i -e '/^url_have_group_name&/d;s/false/true/g' mod_fastdfs.conf
echo -e "tracker_server=$ID:22122\n[group1]\ngroup_name=group1\nstorage_server_port=23000\nstore_path_count=1 ">>mod_fastdfs.conf
cp mod_fastdfs.conf /etc/fdfs
cp /src/fastdfs-5.05/conf/http.conf /etc/fdfs/ && cp /src/fastdfs-5.05/conf/mime.types /etc/fdfs
ln -s /fastdfs/storage/data/ /fastdfs/storage/data/M00
cd /src/nginx-1.18.0
make clean
useradd -M -s /sbin/nologin nginx
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_flv_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre \
--add-module=/src/fastdfs-nginx-module/src
make
make install
if [ $? !=0 ];then
exit
fi
echo "/usr/local/lib64" >> /etc/ld.so.conf && ldconfig
mkdir -p /usr/local/nginx/conf.d
sed -i '19a\ include \/usr\/local\/nginx\/conf.d\/*.conf;' /usr/local/nginx/conf/nginx.conf
cat > /usr/local/nginx/conf.d/fast.conf << EOF
server {
listen 80;
server_name localhost;
location ~/group([0-9])/M00 {
root /fastdfs/storage/data;
ngx_fastdfs_module;
}
}
EOF
sed -i -e 's/80/8888/g' /usr/local/nginx/conf/nginx.conf
/usr/local/nginx/sbin/nginx
echo 'export PATH="$PATH:/usr/local/nginx/sbin"' >>/etc/profile
#或者使用-e加双引号,(双引号解析变量,单引号不解析变量$,使用双引号时加反斜杠不解析变量$)
#echo -e "export PATH="\$PATH:/usr/local/nginx/sbin""
#生成本地HTTPS证书用于测试
#certPassword = 123456
#openssl genrsa -des3 -passout pass:${certPassword} -out server.key 2048
#openssl rsa -passin pass:${certPassword} -in server.key -out server.key
#openssl req -sha256 -new -key server.key -out server.csr -subj '/CN=localhost'
#openssl x509 -req -sha256 -days 365 -in server.csr -signkey server.key -out server.crt
#openssl pkcs12 -export -out server.pfx -inkey server.key -in server.crt -certfile server.crt -passout pass:${certPassword}
脚本2:
#!/bin/sh
# base image
#LABEL version="1.0"
#update 2021-12-31
#LABEL description="This is a fdfsDFS"
#MAINTAINER zhi_jie1c@163.com
#COPY fastdfs-nginx-module /usr/local/fastdfs-nginx-module
#几个包最好手动下载放到/src目录下面有时候github国内网络不稳定
yum provides '*/applydeltarpm'
yum install -y gcc gcc-c++ deltarpm cpp zlib zlib-devel libblkid libblkid-devel glibc cmake autoconf openssl openssl-devel wget libxslt-devel gd gd-devel GeoIP GeoIP-devel pcre pcre-devel epel-release whatprovides libstdc++.so.6 openssl*
yum -y groupinstall "Development Tools"
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
# Download source package libfastcommon fasts-nginx-moudel fastdfs
mkdir /src
cd /src
if [ -f /src/V1.0.45.tar.gz ];then
echo -e "\n\e[1;31m----------V1.0.45.tar.gz exit-------- exit\e[0m"
else
wget -P /src https://github.com/happyfish100/libfastcommon/archive/V1.0.45.tar.gz --no-check-certificate
if [ $? != 0 ];then
echo '下载包时github网络连接失败,请重新下载安装包V1.0.45'
exit
fi
fi
if [ -f /src/V1.22.tar.gz ];then
echo -e "\n\e[1;31m----------efastdfs-nginx-module_v1.16.tar.gz-------- exit\e[0m"
else
wget -P /src https://github.com/happyfish100/fastdfs-nginx-module/archive/refs/tags/V1.22.tar.gz --no-check-certificate
if [ $? != 0 ];then
echo '下载nginx插件失败,请重新下载包fastdfs-nginx-module'
exit
fi
fi
if [ -f /src/V6.07.tar.gz ];then
echo -e "\n\e[1;31m----------V6.07.tar.gz exit-------- exit\e[0m"
else
wget -P /src https://github.com/happyfish100/fastdfs/archive/V6.07.tar.gz --no-check-certificate
if [ $? != 0 ];then
echo '下载包时github网络连接失败,请重新下载安装包V6.07'
exit
fi
fi
if [ -f /src/nginx-1.18.0.tar.gz ];then
echo -e "\n\e[1;31m----------nginx-1.18.0.tar.gz exit-------- exit\e[0m"
else
wget -P /src http://nginx.org/download/nginx-1.18.0.tar.gz --no-check-certificate
if [ $? != 0 ];then
echo '下载nginx包失败,请重新下载安装包nginx-1.18.0'
exit
fi
fi
#nginx-1.18.0.tar.gz /src
# 解压源码包
tar xf V1.0.45.tar.gz -C /src
tar xf V1.22.tar.gz -C /src
tar xf V6.07.tar.gz -C /src
tar xf nginx-1.18.0.tar.gz -C /src
mv fastdfs-nginx-module-1.22 fastdfs-nginx-module
# 安装libfastcommon跟fastdfs
cd /src/libfastcommon-1.0.45
./make.sh && ./make.sh install
cd /src/fastdfs-6.07
#sed -i -e '/^TARGET_PREFIX=$DESTDIR&/d;s/usr/&\/local/' make.sh
./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/local/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
ln -s /usr/local/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so
#替换tracker配置参数
cd /etc/fdfs
cp tracker.conf.sample tracker.conf
mkdir -p /fastdfs/tracker && mkdir -p /fastdfs/storage
sed -i -e 's/\/home\/yuqing\/fastdfs/\/fastdfs\/tracker/g' tracker.conf
echo "/usr/local/nginx/sbin/nginx -s reload" >>/etc/rc.d/rc.local
chkconfig --add fdfs_trackerd && chkconfig fdfs_trackerd on
#优化ip地址变化影响迁移配置
sed -i -e 's/use_storage_id\ =\ false/use_storage_id\ =\ ture/g' tracker.conf
sed -i -e '/^id_type_in_filename&/d;s/ip/id/g' tracker.conf
cp storage.conf.sample storage.conf
sed -i -e 's/\/home\/yuqing\/fastdfs/\/fastdfs\/storage/g' storage.conf
ID=`echo $SSH_CONNECTION | awk -F" " '{print $3}'` #这里是抓取的远程连接的主机的IP
echo -e "# <id> <group_name> <ip_or_hostname>\n100001 group1 $ID" >/src/fastdfs-6.07/conf/storage_ids.conf
cp /src/fastdfs-6.07/conf/storage_ids.conf /etc/fdfs/
echo "tracker_server=$ID:22122" >>storage.conf
sed -i -e '/^tracker_server =/d' storage.conf
#echo "store_path0=/fastdfs/storage" >>storage.conf
sed -i -e 's/8888/80/g' /etc/fdfs/storage.conf
chkconfig --add fdfs_storaged && chkconfig fdfs_storaged on
/etc/init.d/fdfs_trackerd start
/etc/init.d/fdfs_storaged start
cp client.conf.sample client.conf
sed -i -e 's/\/home\/yuqing\/fastdfs/\/fastdfs\/tracker/g' client.conf
sed -i -e '/^tracker_server =/d' client.conf
echo "tracker_server=$ID:22122" >>client.conf
cd /src/fastdfs-nginx-module/src/
sed -i -e 's/\/usr\/local\/include\/fastcommon/\/usr\/include\/fastcommon/' config
sed -i -e 's/\/home\/yuqing\/fastdfs/\/fastdfs\/storage/g' mod_fastdfs.conf
sed -i -e '/^tracker_server=tracker:22122$/d' mod_fastdfs.conf
sed -i -e '/^url_have_group_name&/d;s/false/true/g' mod_fastdfs.conf
echo -e "tracker_server=$ID:22122\n[group1]\ngroup_name=group1\nstorage_server_port=23000\nstore_path_count=1 ">>mod_fastdfs.conf
cp mod_fastdfs.conf /etc/fdfs
cp /src/fastdfs-6.07/conf/http.conf /etc/fdfs/ && cp /src/fastdfs-6.07/conf/mime.types /etc/fdfs
ln -s /fastdfs/storage/data/ /fastdfs/storage/data/M00
cd /src/nginx-1.18.0
make clean
useradd -M -s /sbin/nologin nginx
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_flv_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre \
--add-module=/src/fastdfs-nginx-module/src
make
make install
if [ $? !=0 ];then
exit
fi
echo "/usr/local/lib64" >> /etc/ld.so.conf && ldconfig
mkdir -p /usr/local/nginx/conf.d
sed -i '19a\ include\ \/usr\/local\/nginx\/conf.d\/*.conf;' /usr/local/nginx/conf/nginx.conf
cat > /usr/local/nginx/conf.d/fdfs.conf << EOF
server {
listen 80;
server_name localhost;
location ~/group([0-9])/M00 {
root /fastdfs/storage/data;
ngx_fastdfs_module;
}
}
EOF
sed -i -e 's/80/8888/g' /usr/local/nginx/conf/nginx.conf
/usr/local/nginx/sbin/nginx
echo 'export PATH="$PATH:/usr/local/nginx/sbin"' >>/etc/profile
#或者使用-e加双引号,(双引号解析变量,单引号不解析变量$,使用双引号时加反斜杠不解析变量$)
#echo -e "export PATH="\$PATH:/usr/local/nginx/sbin""
#生成本地HTTPS证书用于测试
#certPassword = 123456
#openssl genrsa -des3 -passout pass:${certPassword} -out server.key 2048
#openssl rsa -passin pass:${certPassword} -in server.key -out server.key
#openssl req -sha256 -new -key server.key -out server.csr -subj '/CN=localhost'
#openssl x509 -req -sha256 -days 365 -in server.csr -signkey server.key -out server.crt
#openssl pkcs12 -export -out server.pfx -inkey server.key -in server.crt -certfile server.crt -passout pass:${certPassword}
测试上传一个文件
[root@localhost ~]# fdfs_upload_file /etc/fdfs/client.conf fdfs.sh