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

#查看启动状态
ps -aux | grep fdfs_trackerd
ps -aux | grep fdfs_storaged
ps -aux | grep nginx
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章