一键安装FastDFS-单机版
手动安装方式请参考: https://github.com/happyfish100/fastdfs/wiki
出于学习目的,由于每次手动安装比较费时,为了提高效率,编写脚本。
FastDFS 需要和 Nginx配合使用,所以一并安装
前期准备
-
准备好 nginx.conf.default
其中添加了一些FastDFS的配置
需要和脚本放在同一个目录
配置内容
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
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;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
server {
#端口和sorage.conf中http.server_port相同
listen 8888;
server_name localhost;
location ~/group[0-9]/ {
ngx_fastdfs_module;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
脚本内容
fastdfs_single_install.sh
#!/bin/bash
function result_echo
{
if [ $? -eq 0 ];then
echo "$1" | tee -a $CUR_PATH/log.log
else
echo "$2" | tee -a $CUR_PATH/log.log
exit 1
fi
}
echo "单机版部署fastdfs开始!!!"
echo "first step: check if fastdfs exists"
CUR_PATH=$(readlink -f $(dirname $0))
#数据存储路径
FDFS_BASE_PATH=/root/fdfs
FDFS_CONFIG_PATH=/etc/fdfs
FDFS_IP=192.168.114.133
#libfastcommon源码路径
SOURCE_PATH=$CUR_PATH/libfastcommon
SOURCE_FDFS_PATH=$CUR_PATH/fastdfs
FDFS_MODEL_SOURCE_PATH=$CUR_PATH/fastdfs-nginx-module
NGINX_SOURCE_PATH=$CUR_PATH/nginx-1.15.4
#杀死存在的进程
ps -ef|grep fdfs_trackerd |grep -v grep | awk '{print $2}' > /tmp/fdfs_trackerd.pid
if [ -s /tmp/fdfs_trackerd.pid ];then
kill -9 `cat /tmp/fdfs_trackerd.pid`
fi
ps -ef|grep fdfs_storaged |grep -v grep | awk '{print $2}' > /tmp/fdfs_storaged.pid
if [ -s /tmp/fdfs_storaged.pid ];then
kill -9 `cat /tmp/fdfs_storaged.pid`
fi
ps -ef|grep nginx |grep -v grep | awk '{print $2}' > /tmp/nginx.pid
if [ -s /tmp/nginx.pid ];then
kill -9 `cat /tmp/nginx.pid`
fi
#判断如果配置文件不存在,则退出
if [ ! -e $CUR_PATH/nginx.conf.default ];then
echo "$CUR_PATH/nginx.conf.default not exist, please check!!!" | tee -a $CUR_PATH/log.log
exit 1
fi
#如果源码存储,则删除
if [ -e $SOURCE_PATH ]; then
rm -rf $SOURCE_PATH
fi
if [ -e $SOURCE_FDFS_PATH ]; then
rm -rf $SOURCE_FDFS_PATH
fi
if [ -e $FDFS_MODEL_SOURCE_PATH ]; then
rm -rf $FDFS_MODEL_SOURCE_PATH
fi
if [ -e $NGINX_SOURCE_PATH ]; then
rm -rf $NGINX_SOURCE_PATH
fi
if [ -e $CUR_PATH/nginx-1.15.4.tar.gz ]; then
rm -rf $CUR_PATH/nginx-1.15.4.tar.gz
fi
if [ -e $FDFS_BASE_PATH ]; then
rm -rf $FDFS_BASE_PATH
fi
if [ ! -e $FDFS_BASE_PATH ]; then
mkdir -p $FDFS_BASE_PATH
fi
if [ -e $CUR_PATH/log.log ]; then
rm -rf $CUR_PATH/log.log
fi
result_echo "Ok... remove SOURCE_PATH is success " "Failed... remove SOURCE_PATH is failed!!!"
#安装dfs
yum repolist | grep epel &> /dev/null
if [ $? -ne 0 ]; then
yum install epel-release -y
yum makecache
fi
yum install ansible -y
yum install git gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl-devel wget vim -y
result_echo "Ok... base soft is install success!!!" "Failed... base soft is uninstall please check!!!"
if [ -e "/etc/fdfs" ]; then
rm -rf /etc/fdfs
fi
#下载源码
git clone https://github.com/happyfish100/libfastcommon.git --depth 1
result_echo "Ok... git clone libfastcommon success" "Failed... git clone is failed, please check!!!"
cd $SOURCE_PATH
sh make.sh
result_echo "Ok... libfastcommon make success" "Failed... libfastcommon make failed please check!!!"
sh make.sh install
result_echo "Ok... libfastcommon make install success" "Failed... libfastcommon make failed pleancheck!!!"
cd $CUR_PATH
#下载fdfs源码
git clone https://github.com/happyfish100/fastdfs.git --depth 1
result_echo "Ok... git clone fastdfs success" "Failed... git clone fastdfs is failed, please check!!!"
cd $SOURCE_FDFS_PATH
sh make.sh
result_echo "Ok... fastdfs make success" "Failed... fastdfs make failed please check!!!"
sh make.sh install
result_echo "Ok... fastdfs make install success" "Failed... fastdfs make failed pleancheck!!!"
cd $CUR_PATH
#nginx 用到的文件
cp $SOURCE_FDFS_PATH/conf/http.conf /etc/fdfs
#nginx 访问的文件
cp $SOURCE_FDFS_PATH/conf/mime.types /etc/fdfs
result_echo "Ok... fdfs need http config is ok" "Failed... fdfs neet http config is failed, please check!!!"
#安装nginx module
git clone https://github.com/happyfish100/fastdfs-nginx-module.git --depth 1
result_echo "Ok... fastdfs nginx module use git download success" "Failed... fastdfs nginx model use git download failed!!! "
cp $FDFS_MODEL_SOURCE_PATH/src/mod_fastdfs.conf /etc/fdfs
#下载nginx
wget http://nginx.org/download/nginx-1.15.4.tar.gz
result_echo "Ok... Download nginx is success" "Failed... Download nginx is failed, please check!!!"
tar -zxvf nginx-1.15.4.tar.gz
cd "$NGINX_SOURCE_PATH"
./configure --add-module=$FDFS_MODEL_SOURCE_PATH/src
make && make install
result_echo "Ok... config nginx" "Failed config nginx failed"
cd $CUR_PATH
#替换basepath
sed -i "s/base_path = \/home\/yuqing\/fastdfs/base_path = \/root\/fdfs/g" $FDFS_CONFIG_PATH/tracker.conf
sed -i "s/base_path = \/home\/yuqing\/fastdfs/base_path = \/root\/fdfs/g" $FDFS_CONFIG_PATH/storage.conf
sed -i "s/store_path0 = \/home\/yuqing\/fastdfs/store_path0 = \/root\/fdfs/g" $FDFS_CONFIG_PATH/storage.conf
sed -i "s/tracker_server = 192.168.209.121:22122/tracker_server = $FDFS_IP:22122/g" $FDFS_CONFIG_PATH/storage.conf
sed -i "s/tracker_server = 192.168.209.121:22122/tracker_server = $FDFS_IP:22122/g" $FDFS_CONFIG_PATH/storage.conf
#nginx 配置
sed -i "s/tracker_server = 192.168.209.121:22122/tracker_server = $FDFS_IP:22122/g" $FDFS_CONFIG_PATH/mod_fastdfs.conf
#启动fdfs tracker
fdfs_trackerd $FDFS_CONFIG_PATH/tracker.conf
result_echo "Ok... fdfs tracker started" "Failed fdfs tracker failed, please check!!!"
#启动fdfs storage
fdfs_storaged $FDFS_CONFIG_PATH/storage.conf
result_echo "Ok... fdfs storage started" "Failed fdfs storage failed, please check!!!"
#配置并启动nginx
sed -i "s/tracker_server = tracker:22122/tracker_server = $FDFS_IP:22122/g" $FDFS_CONFIG_PATH/mod_fastdfs.conf
sed -i "s/url_have_group_name = false/url_have_group_name = true/g" $FDFS_CONFIG_PATH/mod_fastdfs.conf
sed -i "s/store_path0=\/home\/yuqing/store_path0=\/root\/fdfs/g" $FDFS_CONFIG_PATH/mod_fastdfs.conf
#nginx 配置并启动
if [ -e /usr/local/nginx/conf/nginx.conf ]; then
rm -rf /usr/local/nginx/conf/nginx.conf
fi
cp $CUR_PATH/nginx.conf.default /usr/local/nginx/conf/nginx.conf
/usr/local/nginx/sbin/nginx
请关于一下啦^_^
微信公众号