#!/bin/bash source ~/.bashrc # 颜色变量'\033[字背景颜色;字体颜色m字符串\033[0m' GREENCOLOR='\033[1;32m' NC='\033[0m' #准备工作 #在生产环境中,建议不要关闭防火墙,根据实际需要开启端口即可 #自定义变量(注!!!执行脚本前需要进行修改) #安装包目录soft_path,即执行脚本的当前目录 soft_path=$(cd "$(dirname "$0")";pwd) #安装包名称fn fn_libfastcommon="libfastcommon-1.0.38.tar.gz" fn_fastdfs="fastdfs-5.12.tar.gz" fn_fastdfs_nginx_module="fastdfs-nginx-module-1.20.tar.gz" fn_nginx="nginx-1.20.1.tar.gz" #定义配置参数 # 公网ip ip="43.135.68.128" #服务器的IP,根据实际情况修改 tracker_port="22122" #跟踪服务器端口号,一般使用默认,不用修改 storage_port="23000" #存储服务器端口号,一般使用默认,不用修改 nginx_port="80" #Nginx端口号,根据实际情况修改 #定义安装目录参数 bp_fastdfs="/home/fastdfs" #base_path目录,fastdfs存放数据和日志的目录,根据实际情况修改 bp_tracker=${bp_fastdfs}"/tracker" #tracker目录,一般不用修改 bp_storage=${bp_fastdfs}"/storage" #storage目录,一般不用修改 bp_client=${bp_fastdfs}"/client" #client目录,一般不用修改 #以上部分需要根据实际情况修改 echo -e "${GREENCOLOR}下面开始安装.......${NC}" echo -e "${GREENCOLOR}创建目录${NC}" mkdir -p ${bp_tracker} mkdir -p ${bp_storage} mkdir -p ${bp_client} echo -e "${GREENCOLOR}解压缩安装包${NC}" cd ${soft_path} tar -zxvf ${fn_libfastcommon} tar -zxvf ${fn_fastdfs} tar -zxvf ${fn_fastdfs_nginx_module} tar -zxvf ${fn_nginx} #获取安装文件解压缩后的目录名称sp tp_libfastcommon=${fn_libfastcommon%.*} sp_libfastcommon=${tp_libfastcommon%.*} tp_fastdfs=${fn_fastdfs%.*} sp_fastdfs=${tp_fastdfs%.*} tp_fastdfs_nginx_module=${fn_fastdfs_nginx_module%.*} sp_fastdfs_nginx_module=${tp_fastdfs_nginx_module%.*} tp_nginx=${fn_nginx%.*} sp_nginx=${tp_nginx%.*} echo -e "${GREENCOLOR}安装fastdfs依赖包${NC}" yum install -y gcc-c++ echo -e "${GREENCOLOR}安装nginx依赖包${NC}" yum -y install zlib-devel pcre-devel openssl-devel echo -e "${GREENCOLOR}编译安装libfastcommon${NC}" cd ${soft_path}/${sp_libfastcommon} ./make.sh ./make.sh install #创建软链接(暂时没啥用) #ln -s /usr/local/include/fastcommon /usr/include/fastcommon echo -e "${GREENCOLOR}编译安装FastDFS${NC}" cd ${soft_path}/${sp_fastdfs} ./make.sh ./make.sh install echo -e "${GREENCOLOR}开始配置FastDFS${NC}" echo -e "${GREENCOLOR}FastDFS配置文件准备${NC}" cd /etc/fdfs cp tracker.conf.sample tracker.conf #tracker配置文件 cp storage.conf.sample storage.conf #storage配置文件 cp client.conf.sample client.conf #客户端配置文件,测试上传文件用 echo -e "${GREENCOLOR}nginx访问配置文件准备${NC}" cp ${soft_path}/${sp_fastdfs_nginx_module}/src/mod_fastdfs.conf /etc/fdfs #mod_fastdfs配置文件,供nginx访问使用 cp ${soft_path}/${sp_fastdfs}/conf/http.conf /etc/fdfs #供nginx访问使用 cp ${soft_path}/${sp_fastdfs}/conf/mime.types /etc/fdfs #供nginx访问使用 echo -e "${GREENCOLOR}配置tracker.conf 文件${NC}" #tracker服务器端口(默认22122,一般不修改) sed -i "s#port=22122#port=${tracker_port}#g" tracker.conf #存储数据和日志的根目录 sed -i "s#base_path=/home/yuqing/fastdfs#base_path=${bp_tracker}#g" tracker.conf #暂时不知道有啥用 #sed -i "s#http.server_port=8080#http.server_port=${nginx_port}#g" tracker.conf echo -e "${GREENCOLOR}配置storage.conf 文件${NC}" #storage服务端口(默认23000,一般不修改) sed -i "s#port=23000#port=${storage_port}#g" storage.conf #存储数据和日志的根目录 sed -i "s#base_path=/home/yuqing/fastdfs#base_path=${bp_storage}#g" storage.conf #第一个文件存储目录 sed -i "s#store_path0=/home/yuqing/fastdfs#store_path0=${bp_storage}#g" storage.conf #tracker服务器 sed -i "s#tracker_server=192.168.209.121:22122#tracker_server=${ip}:${tracker_port}#g" storage.conf #使用http访问文件时的端口(和nginx中保持一致) sed -i "s#http.server_port=8888#http.server_port=${nginx_port}#g" storage.conf echo -e "${GREENCOLOR}配置client.conf 文件${NC}" #存储数据和日志的根目录 sed -i "s#base_path=/home/yuqing/fastdfs#base_path=${bp_client}#g" client.conf #tracker服务器 sed -i "s#tracker_server=192.168.0.197:22122#tracker_server=${ip}:${tracker_port}#g" client.conf #sed -i "s#http.tracker_server_port=80#http.tracker_server_port=${nginx_port}#g" client.conf echo -e "${GREENCOLOR}Nginx插件安装及配置${NC}" #cd ${soft_path}/${sp_fastdfs_nginx_module}/src #sed -i "s#/usr/local/include/fastdfs#/usr/include/fastdfs#g" config #sed -i "s#/usr/local/lib#/usr/lib64#g" config echo -e "${GREENCOLOR}配置mod_fastdfs.conf文件${NC}" cd /etc/fdfs #sed -i "s#base_path=/tmp#base_path=${bp_storage}#g" mod_fastdfs.conf #tracker服务器IP和端口 sed -i "s#tracker_server=tracker:22122#tracker_server=${ip}:${tracker_port}#g" mod_fastdfs.conf #storage服务端口(与storage.conf中port保持一致) sed -i "s#port=23000#port=${storage_port}#g" mod_fastdfs.conf #url中是否包含group名称 sed -i "s#url_have_group_name = false#url_have_group_name = true#g" mod_fastdfs.conf #第一个文件存储目录 sed -i "s#store_path0=/home/yuqing/fastdfs#store_path0=${bp_storage}#g" mod_fastdfs.conf #创建软连接:在/home/fastdfs/storage/文件存储目录下创建软连接,将其链接到实际存放数据的目录 #暂时没什么作用 #ln -s /home/fastdfs/storage/data/ /home/fastdfs/storage/data/M00 echo -e "${GREENCOLOR}编译安装nginx${NC}" cd ${soft_path}/${sp_nginx} ./configure --add-module=${soft_path}/${sp_fastdfs_nginx_module}/src make make install echo -e "${GREENCOLOR}修改nginx配置文件${NC}" cd /usr/local/nginx/conf/ # 该端口为storage.conf中的http.server_port相同 sed -i "s#listen 80#listen ${nginx_port}#g" nginx.conf #在#error_page前一行增加location sed -i "/#error_page/i location ~/group[0-9]/ {ngx_fastdfs_module;}" nginx.conf #sed -i "s#location /#location ~/group[0-9]/#g" nginx.conf #sed -i "s#root html#root ${bp_storage}/data#g" nginx.conf #sed -i "s#index index.html index.htm#ngx_fastdfs_module#g" nginx.conf echo -e "${GREENCOLOR}配置开机自启动${NC}" echo -e "${GREENCOLOR}配置fastdfs开机自启动${NC}" systemctl enable fdfs_trackerd systemctl enable fdfs_storaged echo -e "${GREENCOLOR}配置nginx开机自启动${NC}" cat >> /etc/rc.d/rc.local << EOF # nginx start /usr/local/nginx/sbin/nginx EOF chmod +x /etc/rc.d/rc.local echo -e "${GREENCOLOR}启动程序${NC}" systemctl start fdfs_trackerd systemctl start fdfs_storaged /usr/local/nginx/sbin/nginx echo -e "${GREENCOLOR}安装结束${NC}"