一键安装nginx和fsfs分布式文件存储shell脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了一键安装nginx和fsfs分布式文件存储shell脚本相关的知识,希望对你有一定的参考价值。

#!/bin/bash
# lty 20180116
# fastdfs install script

if [ `id -u` -ne 0 ];then
    echo "非root用户,脚本退出"
    exit 0
fi
if [ ! -f "/root/soft/fastdfs_install.sh" ];then
    echo "请将安装脚本方在/root/soft目录后重新执行安装。"
fi

install_fdfs()
{
cd /root/soft
wget https://codeload.github.com/happyfish100/libfastcommon/zip/master -O libfastcommon-master.zip
if [ ! -f "libfastcommon-master.zip" ];then
    echo "下载libfastcommon-master.zip出错" && exit 1 
fi
unzip libfastcommon-master.zip
cd libfastcommon-master/
sh ./make.sh
sh ./make.sh install
cd ..
wget http://jaist.dl.sourceforge.net/project/fastdfs/FastDFS%20Server%20Source%20Code/FastDFS%20Server%20with%20php%20Extension%20Source%20Code%20V5.08/FastDFS_v5.08.tar.gz
if [ ! -f "FastDFS_v5.08.tar.gz" ];then
    echo "下载FastDFS_v5.08.tar.gz出错" && exit 1
fi
tar xf FastDFS_v5.08.tar.gz
cd FastDFS
sh ./make.sh
sh ./make.sh install
cd /etc/fdfs/
cp storage.conf.sample storage.conf
cp tracker.conf.sample tracker.conf
cp client.conf.sample client.conf

mkdir -p /data/fastdfs
sed -i "[email protected]/home/yuqing/@/data/@g" ./*f
}

install_nginx()
{
cd /root/soft
wget http://nchc.dl.sourceforge.net/project/fastdfs/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz
if [ ! -f "fastdfs-nginx-module_v1.16.tar.gz" ];then
    echo "下载fastdfs-nginx-module_v1.16.tar.gz出错"
fi 
tar xf fastdfs-nginx-module_v1.16.tar.gz 
cd fastdfs-nginx-module/src/
sed -i "[email protected]/usr/local/@/usr/@g" config
# 或手动编辑vim config,/usr/local改成/usr,执行:%s+/usr/local/+/usr/+g命令进行批量替换并保存退出
\cp mod_fastdfs.conf /etc/fdfs/

# 开始配置fastdfs
IPLINE=`ip addr | grep -E 'inet 172|inet 192|inet 10' | awk -F'[/]' '{print$1}' | awk '{print$2}' |wc -l`
if [ $IPLINE -gt 1 ];then
echo "本机有多个内网IP,请手动配置/etc/fdfs/mod_fastdfs.conf的tracker_server项"
elif [ $IPLINE -eq 1 ];then
IP=`ip addr | grep -E 'inet 172|inet 192|inet 10' | awk -F'[/]' '{print$1}' | awk '{print$2}'`
sed -i "[email protected]:[email protected]$IP:[email protected]" /etc/fdfs/mod_fastdfs.conf
sed -i "[email protected]@[email protected]" /etc/fdfs/*conf
sed -i "[email protected]@[email protected]" /etc/fdfs/*conf
else
echo "未检测到本机内网IP,请手动配置/etc/fdfs/mod_fastdfs.conf的tracker_server项"
fi
sed -i "[email protected]_have_group_name = [email protected]_have_group_name = [email protected]" /etc/fdfs/mod_fastdfs.conf
sed -i "[email protected]/[email protected]@g" /etc/fdfs/*conf

#需要检查是否有系统安装的nginx
NGINX_PROC=`ps -ef | grep nginx | grep -v grep`
if [ $NGINX_PROC ];then
echo "存在nginx进程,将跳过nginx安装。请手动配置nginx.conf"
return
fi

cd /root/soft
yum install -y pcre-devel zlib-devel
wget http://nginx.org/download/nginx-1.12.2.tar.gz
if [ ! -f "nginx-1.12.2.tar.gz" ];then
    echo "下载nginx-1.12.2.tar.gz出错" && exit 1
fi
tar xf nginx-1.12.2.tar.gz
cd nginx-1.12.2
./configure --prefix=/apps/nginx/ --add-module=../fastdfs-nginx-module/src/
make
make install
cd /apps/nginx/conf
cat > /apps/nginx/conf/nginx.conf <<EOF
    user  root;    
    worker_processes  1;
    events {
       worker_connections  1024;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        client_max_body_size 300M;
        keepalive_timeout  65;
        server {
            listen       80;
            server_name  localhost;
            location ~/group[0-9]/ {
                ngx_fastdfs_module;
            }
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
            #root   html;
            }
        }
    }
EOF

\cp /apps/nginx/conf/mime.types /etc/fdfs/
\cp /root/soft/FastDFS/conf/http.conf /etc/fdfs/
}

# 启动
start_service()
{
fdfs_storaged /etc/fdfs/storage.conf
fdfs_trackerd /etc/fdfs/tracker.conf
ln -s /data/fastdfs/data/ /data/fastdfs/data/M00
/apps/nginx/sbin/nginx
echo "fdfs、nginx安装完成,启动成功"
ps -ef | grep -E "nginx|fdfs"| grep -v grep
}

install_fdfs || exit 1
install_nginx|| exit 1
start_service|| exit 1
exit 0


以上是关于一键安装nginx和fsfs分布式文件存储shell脚本的主要内容,如果未能解决你的问题,请参考以下文章

人为增加SVN(FSFS)存储库中的修订号

Linux下编译安装SVN

安装lnmp 时如何修改数据库数据存储地址及默认访问地址

LNMP架构搭建(一键部署)

使用playbook实现一键安装nginx+PHP

nginx1.10.3一键安装/系统内核优化/配置文件优化/https/日志切割