#!/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
FastDFS一鍵部署腳本
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.