11#! /usr/bin/env bash
22
3- # #############################################################################
4- # console color
5- C_BLACK =" \033[1;30m"
6- C_RED =" \033[1;31m"
7- C_GREEN =" \033[1;32m"
8- C_YELLOW =" \033[1;33m"
9- C_BLUE =" \033[1;34m"
10- C_PURPLE =" \033[1;35m"
11- C_CYAN =" \033[1;36m"
12- C_RESET =" $( tput sgr0) "
13- # #############################################################################
14-
15- printf " ${C_PURPLE } "
3+ # ##################################################################################
4+ # 控制台颜色
5+ BLACK =" \033[1;30m"
6+ RED =" \033[1;31m"
7+ GREEN =" \033[1;32m"
8+ YELLOW =" \033[1;33m"
9+ BLUE =" \033[1;34m"
10+ PURPLE =" \033[1;35m"
11+ CYAN =" \033[1;36m"
12+ RESET =" $( tput sgr0) "
13+ # ##################################################################################
14+
15+ printf " ${BLUE } "
1616cat << EOF
1717
1818###################################################################################
1919# install FastDFS 脚本
2020# FastDFS 会被install到 /opt/fdfs 路径。
2121# @system: 适用于 CentOS
2222# @author: Zhang Peng
23+ # @ses: https://github.com/happyfish100/fastdfs/wiki
2324###################################################################################
2425
2526EOF
26- printf " ${C_RESET } "
27+ printf " ${RESET } "
2728
28- command -v yum > /dev/null 2>&1 || { echo >&2 -e " ${C_RED} Require yum but it's not installed. Aborting.${C_RESET} " ; exit 1; }
29- command -v git > /dev/null 2>&1 || { echo >&2 -e " ${C_RED} Require git but it's not installed. Aborting.${C_RESET} " ; exit 1; }
29+ printf " ${GREEN} >>>>>>>> install fastdfs begin.${RESET} \n"
3030
31- yum install git gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl-devel wget vim -y
31+ command -v yum > /dev/null 2>&1 || { printf " ${RED} Require yum but it's not installed.${RESET} \n" ; exit 1; }
32+ command -v git > /dev/null 2>&1 || { printf " ${RED} Require git but it's not installed.${RESET} \n" ; exit 1; }
3233
33- root=/opt/fdfs
34- if [[ -n $1 ]]; then
35- root=$1
34+ if [[ $# -lt 1 ]] || [[ $# -lt 2 ]]; then
35+ printf " ${PURPLE} [Hint]\n"
36+ printf " \t sh fastdfs-install.sh [path]\n"
37+ printf " \t Example: sh fastdfs-install.sh /opt/fastdfs\n"
38+ printf " ${RESET} \n"
3639fi
3740
38- version=1.16.0
39- if [[ -n $2 ]]; then
40- version= $2
41+ path=/opt/fdfs
42+ if [[ -n $1 ]]; then
43+ path= $1
4144fi
4245
46+ nginx_version=1.16.0
4347nginx_path=/opt/nginx
44- if [[ -n $3 ]]; then
45- root=$3
46- fi
4748
48- mkdir -p ${root}
49- root=/opt/fdfs
50- echo -e " \n${C_GREEN} >>>>>>>>> install libfastcommon${C_RESET} "
51- mkdir -p ${root} /libfastcommon
52- curl -o ${root} /libfastcommon.zip http://dunwu.test.upcdn.net/soft/fdfs/libfastcommon.zip
53- if [[ ! -f ${root} /libfastcommon.zip ]]; then
54- echo -e " \n${C_RED} >>>>>>>>> install libfastcommon failed,exit. ${C_RESET} "
49+ printf " ${GREEN} >>>>>>>> install required libs.${RESET} \n\n"
50+ yum install git gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl-devel wget vim -y
51+
52+ # download and decompression
53+ mkdir -p ${path}
54+ path=/opt/fdfs
55+ mkdir -p ${path} /libfastcommon
56+ curl -o ${path} /libfastcommon.zip http://dunwu.test.upcdn.net/soft/fdfs/libfastcommon.zip
57+ if [[ ! -f ${path} /libfastcommon.zip ]]; then
58+ printf " ${RED} [Error]install libfastcommon failed,exit. ${RESET} \n"
59+ exit 1
5560fi
56- unzip -o ${root} /libfastcommon.zip -d ${root}
57- cd ${root} /libfastcommon
58- chmod +x -R ${root} /libfastcommon/* .sh
61+ unzip -o ${path} /libfastcommon.zip -d ${path}
62+
63+
64+ cd ${path} /libfastcommon
65+ chmod +x -R ${path} /libfastcommon/* .sh
5966./make.sh && ./make.sh install
6067
61- echo -e " \n ${C_GREEN } >>>>>>>>> install fastdfs${C_RESET } "
62- mkdir -p ${root } /fastdfs
63- curl -o ${root } /fastdfs.zip http://dunwu.test.upcdn.net/soft/fdfs/fastdfs.zip
64- if [[ ! -f ${root } /fastdfs.zip ]]; then
65- echo -e " \n ${C_RED } >>>>>>>>> install fastdfs failed,exit. ${C_RESET} "
68+ printf " ${GREEN } >>>>>>>>> install fastdfs${RESET } "
69+ mkdir -p ${path } /fastdfs
70+ curl -o ${path } /fastdfs.zip http://dunwu.test.upcdn.net/soft/fdfs/fastdfs.zip
71+ if [[ ! -f ${path } /fastdfs.zip ]]; then
72+ printf " ${RED } >>>>>>>>> install fastdfs failed,exit. ${RESET} \n "
6673fi
67- unzip -o ${root } /fastdfs.zip -d ${root }
68- cd ${root } /fastdfs
69- chmod +x -R ${root } /fastdfs/* .sh
74+ unzip -o ${path } /fastdfs.zip -d ${path }
75+ cd ${path } /fastdfs
76+ chmod +x -R ${path } /fastdfs/* .sh
7077./make.sh && ./make.sh install
7178
72- echo -e " \n ${C_GREEN } >>>>>>>>> install fastdfs-nginx-module${C_RESET} "
73- mkdir -p ${root } /fastdfs-nginx-module
74- curl -o ${root } /fastdfs-nginx-module.zip http://dunwu.test.upcdn.net/soft/fdfs/fastdfs-nginx-module.zip
75- if [[ ! -f ${root } /fastdfs-nginx-module.zip ]]; then
76- echo -e " \n ${C_RED } >>>>>>>>> install fastdfs-nginx-module failed,exit. ${C_RESET} "
79+ printf " ${GREEN } >>>>>>>>> install fastdfs-nginx-module${RESET} \n "
80+ mkdir -p ${path } /fastdfs-nginx-module
81+ curl -o ${path } /fastdfs-nginx-module.zip http://dunwu.test.upcdn.net/soft/fdfs/fastdfs-nginx-module.zip
82+ if [[ ! -f ${path } /fastdfs-nginx-module.zip ]]; then
83+ printf " ${RED } >>>>>>>>> install fastdfs-nginx-module failed,exit. ${RESET} \n "
7784fi
78- unzip -o ${root } /fastdfs-nginx-module.zip -d ${root }
85+ unzip -o ${path } /fastdfs-nginx-module.zip -d ${path }
7986
80- echo -e " \n ${C_GREEN } >>>>>>>>> install nginx${C_RESET } "
87+ printf " ${GREEN } >>>>>>>>> install nginx${RESET } "
8188mkdir -p ${nginx_path}
82- wget -O ${nginx_path} /nginx-${version } .tar.gz http://nginx.org/download/nginx-${version } .tar.gz
83- tar zxf ${nginx_path} /nginx-${version } .tar.gz -C ${nginx_path}
84- cd ${nginx_path} /nginx-${version }
85- ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre --add-module=${root } /fastdfs-nginx-module/src/
89+ curl -o ${nginx_path} /nginx-${nginx_version } .tar.gz http://nginx.org/download/nginx-${nginx_version } .tar.gz
90+ tar zxf ${nginx_path} /nginx-${nginx_version } .tar.gz -C ${nginx_path}
91+ cd ${nginx_path} /nginx-${nginx_version }
92+ ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre --add-module=${path } /fastdfs-nginx-module/src/
8693make && make install
8794
88- echo -e " \n ${C_GREEN } >>>>>>>>> fastdfs 配置文件准备${C_RESET} "
95+ printf " ${GREEN } >>>>>>>>> fastdfs 配置文件准备${RESET} \n "
8996# 配置修改参考:https://github.com/happyfish100/fastdfs/wiki
9097
91- cp ${root } /fastdfs/conf/http.conf /etc/fdfs/ # 供nginx访问使用
92- cp ${root } /fastdfs/conf/mime.types /etc/fdfs/ # 供nginx访问使用
93- cp ${root } /fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs
98+ cp ${path } /fastdfs/conf/http.conf /etc/fdfs/ # 供nginx访问使用
99+ cp ${path } /fastdfs/conf/mime.types /etc/fdfs/ # 供nginx访问使用
100+ cp ${path } /fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs
94101wget -N https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/soft/config/fastdfs/tracker.conf -O /etc/fdfs/tracker.conf
95102wget -N https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/soft/config/fastdfs/storage.conf -O /etc/fdfs/storage.conf
96103wget -N https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/soft/config/fastdfs/client.conf -O /etc/fdfs/client.conf
@@ -100,26 +107,26 @@ fdfs_server_port=7001
100107ip=$( ip addr | awk ' /^[0-9]+: / {}; /inet.*global/ {print gensub(/(.*)\/(.*)/, "\\1", "g", $2)}' )
101108
102109mkdir -p ${fdfs_store_path}
103- echo -e " \n ${C_GREEN } - 修改 tracker.conf 配置${C_RESET} "
110+ printf " ${GREEN } - 修改 tracker.conf 配置${RESET} \n "
104111sed -i " s#^base_path=.*#base_path=${fdfs_store_path} #g" /etc/fdfs/tracker.conf
105- echo -e " \n ${C_GREEN } - 修改 storage.conf 配置${C_RESET} "
112+ printf " ${GREEN } - 修改 storage.conf 配置${RESET} \n "
106113sed -i " s#^base_path=.*#base_path=${fdfs_store_path} #g" /etc/fdfs/storage.conf
107114sed -i " s#^store_path0=.*#store_path0=${fdfs_store_path} #g" /etc/fdfs/storage.conf
108115sed -i " s#^tracker_server=.*#tracker_server=${ip} :22122#g" /etc/fdfs/storage.conf
109116sed -i " s#^http.server_port=.*#http.server_port=${fdfs_server_port} #g" /etc/fdfs/storage.conf
110- echo -e " \n ${C_GREEN } - 修改 client.conf 配置${C_RESET} "
117+ printf " ${GREEN } - 修改 client.conf 配置${RESET} \n "
111118sed -i " s#^base_path=.*#base_path=${fdfs_store_path} #g" /etc/fdfs/client.conf
112119sed -i " s#^tracker_server=.*#tracker_server=${ip} :22122#g" /etc/fdfs/client.conf
113- echo -e " \n ${C_GREEN } - 修改 mod_fastdfs.conf 配置${C_RESET} "
120+ printf " ${GREEN } - 修改 mod_fastdfs.conf 配置${RESET} \n "
114121sed -i " s#^url_have_group_name=.*#url_have_group_name=true#g" /etc/fdfs/mod_fastdfs.conf
115122sed -i " s#^tracker_server=.*#tracker_server=${ip} :22122#g" /etc/fdfs/mod_fastdfs.conf
116123sed -i " s#^store_path0=.*#store_path0=${fdfs_store_path} #g" /etc/fdfs/mod_fastdfs.conf
117- echo -e " \n ${C_GREEN } - 修改 nginx.conf 配置${C_RESET } \n"
124+ printf " ${GREEN } - 修改 nginx.conf 配置${RESET } \n"
118125mkdir -p /usr/local/nginx/conf/conf
119126wget -N https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/soft/config/nginx/nginx.conf -O /usr/local/nginx/conf/nginx.conf
120127wget -N https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/soft/config/nginx/conf/fdfs.conf -O /usr/local/nginx/conf/conf/fdfs.conf
121128
122- echo -e " \n ${C_GREEN } >>>>>>>>> 启动 fastdfs ${C_RESET} "
129+ printf " ${GREEN } >>>>>>>>> 启动 fastdfs ${RESET} \n "
123130chmod +x /etc/init.d/fdfs_trackerd
124131/etc/init.d/fdfs_trackerd start # 启动tracker服务
125132# /etc/init.d/fdfs_trackerd restart #重启动tracker服务
@@ -142,7 +149,13 @@ systemctl start nginx.service
142149# systemctl restart nginx.service
143150# systemctl stop nginx.service
144151
145- echo -e " \n >>>>>>>>> add fastdfs port"
152+ printf " >>>>>>>>> add fastdfs port"
146153firewall-cmd --zone=public --add-port=${fdfs_server_port} /tcp --permanent
147154firewall-cmd --zone=public --add-port=22122/tcp --permanent
148155firewall-cmd --reload
156+
157+ printf " ${GREEN} <<<<<<<< install fastdfs end.${RESET} \n"
158+ # touch test.txt
159+ # result=`fdfs_upload_file /etc/fdfs/client.conf test.txt`
160+ # echo ${result}
161+ # rm -f test.txt
0 commit comments