fdfs是一个常用的分布式文件存储服务器

可以根据情况进行配置调整,需要多节点fastdfs可以根据情况添加修改配置

#!/bin/sh
# base image
#LABEL version="1.0"
#date = 2019-8-9
#LABEL description="This is a fdfsDFS"
#MAINTAINER zhi_jie1c@163.com

#COPY fastdfs-nginx-module /usr/local/fastdfs-nginx-module
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.7.tar.gz ];then
     echo -e "\n\e[1;31m----------V1.0.7.tar.gz exit-------- exit\e[0m"
  else
     wget https://github.com/happyfish100/libfastcommon/archive/V1.0.7.tar.gz --no-check-certificate
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 http://jaist.dl.sourceforge.net/project/fastdfs/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz --no-check-certificate
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 https://github.com/happyfish100/fastdfs/archive/V5.05.tar.gz --no-check-certificate  
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 http://nginx.org/download/nginx-1.18.0.tar.gz --no-check-certificate
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
tar xf V1.0.7.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
echo $SSH_CONNECTION | awk -F" " '{print $3.$9}' >/tmp/ipt  #这里是抓取的远程连接的主机的IP
ID=`cat /tmp/ipt`
rm -rf /tmp/ipt

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=192.168.209.121:22122$/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=192.168.0.197:22122$/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

echo "/usr/local/lib64" >> /etc/ld.so.conf && ldconfig
mkdir -p /usr/local/nginx/conf.d
sed -i '20a\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
source /etc/profile



#本地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}