centos7一键部署fastdfs

受人之托,写了个一键部署fastdfs的脚本,并配置好通过nginx访问资源。

环境资源:centos-7、nginx-1.15.4、fastdfs-最新版

大家可以根据自身需要更换版本,同时也可以更换安装包的镜像地址(有的资源下载比较慢),加快部署速度。

#!/bin/bash

#关闭防火墙
systemctl stop firewalld.service

#安装编译环境
yum install -y git gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl-devel wget vim 
#创建数据存储目录
data_path=/data/dfs
mkdir -p ${data_path}

#下载包存放目录
cd /usr/local/src 
#安装libfatscommon
git clone https://github.com/happyfish100/libfastcommon.git --depth 1
cd libfastcommon/
#编译安装
./make.sh && ./make.sh install

cd ../

#安装fastdfs
git clone https://github.com/happyfish100/fastdfs.git --depth 1
cd fastdfs/
#编译安装
./make.sh && ./make.sh install 
#配置文件准备
cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
#客户端文件
cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf 
#供nginx访问使用
cp /usr/local/src/fastdfs/conf/http.conf /etc/fdfs/ 
#供nginx访问使用
cp /usr/local/src/fastdfs/conf/mime.types /etc/fdfs/ 

cd ../ 

#安装fastdfs-nginx-module
git clone https://github.com/happyfish100/fastdfs-nginx-module.git --depth 1
cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs

#安装nginx
wget http://nginx.org/download/nginx-1.15.4.tar.gz 
#解压
tar -zxvf nginx-1.15.4.tar.gz
cd nginx-1.15.4/
#添加fastdfs-nginx-module模块
./configure --add-module=/usr/local/src/fastdfs-nginx-module/src/ 
#编译安装
make && make install 

#内网ip
ip=`ip addr|grep inet|grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}'|grep -v 127.0.0.1|head -n 1`


#tracker配置
sed -i 's#/home/yuqing/fastdfs#'$data_path'#g' /etc/fdfs/tracker.conf

#storage配置
sed -i 's#/home/yuqing/fastdfs#'$data_path'#g' /etc/fdfs/storage.conf
sed -i 's#192.168.209.121#'$ip'#g' /etc/fdfs/storage.conf
sed -i 's#tracker_server = 192.168.209.122:22122#''#g' /etc/fdfs/storage.conf

#配置client
sed -i 's#/home/yuqing/fastdfs#'$data_path'#g' /etc/fdfs/client.conf
sed -i 's#192.168.0.196#'$ip'#g' /etc/fdfs/client.conf
sed -i 's#tracker_server = 192.168.0.197:22122#''#g' /etc/fdfs/client.conf

#配置nginx访问
sed -i 's#base_path=/tmp#base_path='$data_path'#g' /etc/fdfs/mod_fastdfs.conf
sed -i 's#tracker_server=tracker:22122#tracker_server='$ip':22122#g' /etc/fdfs/mod_fastdfs.conf
sed -i 's#url_have_group_name = false#url_have_group_name = true#g' /etc/fdfs/mod_fastdfs.conf
sed -i 's#store_path0=/home/yuqing/fastdfs#store_path0='$data_path'#g' /etc/fdfs/mod_fastdfs.conf

echo '#user  nobody;
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
    #access_log  logs/access.log  main;

    sendfile        on;
    keepalive_timeout  65;
    gzip  on;

    server {
        listen       8888;
        server_name  localhost;
        #access_log  logs/host.access.log  main;
        
        location ~/group[0-9]/ {
            ngx_fastdfs_module;
        }
        
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }
}' > /usr/local/nginx/conf/nginx.conf

systemctl daemon-reload

#启动tracker
/etc/init.d/fdfs_trackerd start
#启动storage
/etc/init.d/fdfs_storaged start
#启动nginx
/usr/local/nginx/sbin/nginx

 

你可能感兴趣的:(运维)