|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +############################################################################## |
| 4 | +# console color |
| 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 "${PURPLE}" |
| 16 | +cat << EOF |
| 17 | +
|
| 18 | +################################################################################### |
| 19 | +# 安装 FastDFS 脚本 |
| 20 | +# FastDFS 会被安装到 /opt/fdfs 路径。 |
| 21 | +# @system: 适用于 CentOS |
| 22 | +# @author: Zhang Peng |
| 23 | +################################################################################### |
| 24 | +
|
| 25 | +EOF |
| 26 | +printf "${RESET}" |
| 27 | + |
| 28 | +command -v yum >/dev/null 2>&1 || { echo >&2 -e "${RED}Require yum but it's not installed. Aborting.${RESET}"; exit 1; } |
| 29 | +command -v git >/dev/null 2>&1 || { echo >&2 -e "${RED}Require git but it's not installed. Aborting.${RESET}"; exit 1; } |
| 30 | + |
| 31 | +yum install git gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl-devel wget vim -y |
| 32 | + |
| 33 | +root=/opt/fdfs |
| 34 | +if [[ -n $1 ]]; then |
| 35 | + root=$1 |
| 36 | +fi |
| 37 | + |
| 38 | +version=1.16.0 |
| 39 | +if [[ -n $2 ]]; then |
| 40 | + version=$2 |
| 41 | +fi |
| 42 | + |
| 43 | +nginx_path=/opt/nginx |
| 44 | +if [[ -n $3 ]]; then |
| 45 | + root=$3 |
| 46 | +fi |
| 47 | + |
| 48 | +mkdir -p ${root} |
| 49 | + |
| 50 | +echo -e "\n${GREEN}>>>>>>>>> 安装 libfastcommon${RESET}" |
| 51 | +mkdir -p ${root}/libfastcommon |
| 52 | +git clone https://github.com/happyfish100/libfastcommon.git "${root}/libfastcommon" |
| 53 | +cd ${root}/libfastcommon |
| 54 | +./make.sh && ./make.sh install |
| 55 | + |
| 56 | +echo -e "\n${GREEN}>>>>>>>>> 安装 fastdfs${RESET}" |
| 57 | +mkdir -p ${root}/fastdfs |
| 58 | +git clone https://github.com/happyfish100/fastdfs.git "${root}/fastdfs" |
| 59 | +cd ${root}/fastdfs |
| 60 | +./make.sh && ./make.sh install |
| 61 | + |
| 62 | +echo -e "\n${GREEN}>>>>>>>>> 安装 fastdfs-nginx-module${RESET}" |
| 63 | +mkdir -p ${root}/fastdfs-nginx-module |
| 64 | +git clone https://github.com/happyfish100/fastdfs-nginx-module.git "${root}/fastdfs-nginx-module" |
| 65 | + |
| 66 | +echo -e "\n${GREEN}>>>>>>>>> 安装 nginx${RESET}" |
| 67 | +mkdir -p ${nginx_path} |
| 68 | +wget -O ${nginx_path}/nginx-${version}.tar.gz http://nginx.org/download/nginx-${version}.tar.gz |
| 69 | +tar zxf ${nginx_path}/nginx-${version}.tar.gz -C ${nginx_path} |
| 70 | +cd ${nginx_path}/nginx-${version} |
| 71 | +./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre --add-module=${root}/fastdfs-nginx-module/src/ |
| 72 | +make && make install |
| 73 | + |
| 74 | +echo -e "\n${GREEN}>>>>>>>>> fastdfs 配置文件准备${RESET}" |
| 75 | +# 配置修改参考:https://github.com/happyfish100/fastdfs/wiki |
| 76 | + |
| 77 | +cp ${root}/fastdfs/conf/http.conf /etc/fdfs/ #供nginx访问使用 |
| 78 | +cp ${root}/fastdfs/conf/mime.types /etc/fdfs/ #供nginx访问使用 |
| 79 | +cp ${root}/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs |
| 80 | +wget -N https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/soft/config/fastdfs/tracker.conf -O /etc/fdfs/tracker.conf |
| 81 | +wget -N https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/soft/config/fastdfs/storage.conf -O /etc/fdfs/storage.conf |
| 82 | +wget -N https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/soft/config/fastdfs/client.conf -O /etc/fdfs/client.conf |
| 83 | +# fdfs 存储路径和服务端口(以默认形式配置) |
| 84 | +fdfs_store_path=/home/fdfs |
| 85 | +fdfs_server_port=7001 |
| 86 | +ip=$(ip addr | awk '/^[0-9]+: / {}; /inet.*global/ {print gensub(/(.*)\/(.*)/, "\\1", "g", $2)}') |
| 87 | +echo -e "\n${GREEN} - 修改 tracker.conf 配置${RESET}" |
| 88 | +sed -i "s#^base_path=.*#base_path=${fdfs_store_path}#g" /etc/fdfs/tracker.conf |
| 89 | +echo -e "\n${GREEN} - 修改 storage.conf 配置${RESET}" |
| 90 | +sed -i "s#^base_path=.*#base_path=${fdfs_store_path}#g" /etc/fdfs/storage.conf |
| 91 | +sed -i "s#^store_path0=.*#store_path0=${fdfs_store_path}#g" /etc/fdfs/storage.conf |
| 92 | +sed -i "s#^tracker_server=.*#tracker_server=${ip}:22122#g" /etc/fdfs/storage.conf |
| 93 | +sed -i "s#^http.server_port=.*#http.server_port=${fdfs_server_port}#g" /etc/fdfs/storage.conf |
| 94 | +echo -e "\n${GREEN} - 修改 client.conf 配置${RESET}" |
| 95 | +sed -i "s#^base_path=.*#base_path=${fdfs_store_path}#g" /etc/fdfs/client.conf |
| 96 | +sed -i "s#^tracker_server=.*#tracker_server=${ip}:22122#g" /etc/fdfs/client.conf |
| 97 | +echo -e "\n${GREEN} - 修改 mod_fastdfs.conf 配置${RESET}" |
| 98 | +sed -i "s#^url_have_group_name=.*#url_have_group_name=true#g" /etc/fdfs/mod_fastdfs.conf |
| 99 | +sed -i "s#^tracker_server=.*#tracker_server=${ip}:22122#g" /etc/fdfs/mod_fastdfs.conf |
| 100 | +sed -i "s#^store_path0=.*#store_path0=${fdfs_store_path}#g" /etc/fdfs/mod_fastdfs.conf |
| 101 | +echo -e "\n${GREEN} - 修改 nginx.conf 配置${RESET}\n" |
| 102 | +mkdir -p /usr/local/nginx/conf/conf |
| 103 | +wget -N https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/soft/config/nginx/nginx.conf -O /usr/local/nginx/conf/nginx.conf |
| 104 | +wget -N https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/soft/config/nginx/conf/fdfs.conf -O /usr/local/nginx/conf/conf/fdfs.conf |
| 105 | + |
| 106 | +echo -e "\n${GREEN}>>>>>>>>> 启动 fastdfs ${RESET}" |
| 107 | +/etc/init.d/fdfs_trackerd start #启动tracker服务 |
| 108 | +#/etc/init.d/fdfs_trackerd restart #重启动tracker服务 |
| 109 | +#/etc/init.d/fdfs_trackerd stop #停止tracker服务 |
| 110 | +chkconfig fdfs_trackerd on #自启动tracker服务 |
| 111 | + |
| 112 | +/etc/init.d/fdfs_storaged start #启动storage服务 |
| 113 | +#/etc/init.d/fdfs_storaged restart #重动storage服务 |
| 114 | +#/etc/init.d/fdfs_storaged stop #停止动storage服务 |
| 115 | +chkconfig fdfs_storaged on #自启动storage服务 |
| 116 | + |
| 117 | +wget -N https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/soft/config/nginx/nginx.service -O /usr/lib/systemd/system/nginx.service |
| 118 | +chmod +x /usr/lib/systemd/system/nginx.service |
| 119 | +#设置nginx.service为系统服务 |
| 120 | +systemctl enable nginx.service |
| 121 | +##通过系统服务操作nginx |
| 122 | +systemctl start nginx.service |
| 123 | +#systemctl reload nginx.service |
| 124 | +#systemctl restart nginx.service |
| 125 | +#systemctl stop nginx.service |
| 126 | + |
| 127 | +echo -e "\n>>>>>>>>> add fastdfs port" |
| 128 | +firewall-cmd --zone=public --add-port=${fdfs_server_port}/tcp --permanent |
| 129 | +firewall-cmd --zone=public --add-port=22122/tcp --permanent |
| 130 | +firewall-cmd --reload |
0 commit comments