FastDFS 快速安装脚本
This commit is contained in:
232
centos-fastdfs/FasDFS配置说明.md
Normal file
232
centos-fastdfs/FasDFS配置说明.md
Normal file
@@ -0,0 +1,232 @@
|
||||
安装途中需要修改配置文件里的ip地址,查看ip命令:`ifconfig`。以下配置项中,tracker_server值中的ip均替换为该ip地址
|
||||
|
||||
### 1.编译和安装
|
||||
a.安装FastDFS依赖环境
|
||||
|
||||
```sh
|
||||
yum install gcc-c++ -y
|
||||
yum install pcre pcre-devel openssl ssl-devel perl-devel -y
|
||||
```
|
||||
|
||||
b.安装FastDFS依赖包libfastcommon
|
||||
|
||||
```sh
|
||||
cd /usr/local/src
|
||||
wget https://github.com/happyfish100/libfastcommon/archive/V1.0.38.tar.gz
|
||||
tar -zxvf V1.0.38.tar.gz
|
||||
cd libfastcommon-1.0.38/
|
||||
./make.sh
|
||||
./make.sh install
|
||||
```
|
||||
|
||||
c.安装FastDFS
|
||||
|
||||
```sh
|
||||
cd /home
|
||||
wget https://github.com/happyfish100/fastdfs/archive/V5.12.tar.gz
|
||||
cd /usr/local/src
|
||||
cp /home/V5.12.tar.gz ./
|
||||
tar -zxvf V5.12.tar.gz
|
||||
cd fastdfs-5.12/
|
||||
./make.sh
|
||||
./make.sh install
|
||||
```
|
||||
|
||||
d.将配置文件复制到系统为fdfs预设的目录
|
||||
|
||||
```sh
|
||||
cd /usr/local/src/fastdfs-5.12/conf
|
||||
cp mime.types http.conf /etc/fdfs/
|
||||
```
|
||||
|
||||
e.查看安装FastDFS过程中产生的可执行文件
|
||||
|
||||
```sh
|
||||
ls -la /usr/bin/fdfs*
|
||||
```
|
||||
|
||||
### 2.信息配置
|
||||
a.创建目录
|
||||
分别对`tracker`,`storage`,`client`进行配置
|
||||
|
||||
```sh
|
||||
mkdir /home/fastdfs/tracker -p
|
||||
mkdir /home/fastdfs/storage -p
|
||||
cd /etc/fdfs/
|
||||
```
|
||||
|
||||
b.配置tracker
|
||||
|
||||
```sh
|
||||
cp tracker.conf.sample tracker.conf
|
||||
vi tracker.conf
|
||||
```
|
||||
|
||||
将内容修改为:
|
||||
|
||||
```
|
||||
“base_path=/home/fastdfs/tracker”
|
||||
“thread_stack_size = 128KB”
|
||||
```
|
||||
|
||||
c.启动tracker
|
||||
|
||||
```sh
|
||||
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
|
||||
```
|
||||
|
||||
d.配置storage
|
||||
|
||||
```sh
|
||||
cd /etc/fdfs/
|
||||
cp storage.conf.sample storage.conf
|
||||
vi storage.conf
|
||||
```
|
||||
|
||||
将内容修改为:
|
||||
|
||||
```
|
||||
“base_path=/home/fastdfs/storage”
|
||||
“store_path0=/home/fastdfs/storage”
|
||||
“tracker_server= xx.xx.xx.xx:22122”
|
||||
```
|
||||
|
||||
e.启动storage
|
||||
|
||||
```sh
|
||||
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf start
|
||||
```
|
||||
|
||||
f.查看storage启动日志
|
||||
|
||||
```sh
|
||||
vi /home/fastdfs/storage/logs/storaged.log
|
||||
```
|
||||
|
||||
查看最后几行,显示类似如下所示,表示启动成功:
|
||||
|
||||
g.配置client
|
||||
|
||||
```sh
|
||||
cd /etc/fdfs/
|
||||
cp client.conf.sample client.conf
|
||||
vi client.conf
|
||||
```
|
||||
|
||||
将内容修改为:
|
||||
|
||||
```
|
||||
“base_path=/home/fastdfs/tracker”
|
||||
“tracker_server=XX.XX.XX.XX:22122”
|
||||
```
|
||||
|
||||
#### 2.1.安装和配置fastdfs-nginx-modul
|
||||
a.安装fastdfs-nginx-module
|
||||
|
||||
```sh
|
||||
cd /usr/local/src
|
||||
wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.20.tar.gz
|
||||
tar -zxvf V1.20.tar.gz
|
||||
```
|
||||
|
||||
b.配置fastdfs-nginx-module的`config`文件
|
||||
|
||||
```sh
|
||||
cd /usr/local/src/fastdfs-nginx-module-1.20/src/
|
||||
vi config
|
||||
```
|
||||
|
||||
将内容修改为:
|
||||
|
||||
```
|
||||
ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/"
|
||||
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
|
||||
```
|
||||
|
||||
c.配置fastdfs-nginx-module的“mod_fastdfs.conf”文件
|
||||
|
||||
```
|
||||
cp /usr/local/src/fastdfs-nginx-module-1.20/src/mod_fastdfs.conf /etc/fdfs/
|
||||
vi /etc/fdfs/mod_fastdfs.conf
|
||||
```
|
||||
|
||||
将内容修改为:
|
||||
|
||||
```
|
||||
“base_path=/home/fastdfs”
|
||||
“tracker_server=XX.XX.XX.XX:22122”
|
||||
“url_have_group_name = true”
|
||||
“store_path0=/home/fastdfs/storage”
|
||||
```
|
||||
|
||||
|
||||
|
||||
### 3.Nginx服务安装及测试
|
||||
|
||||
3.1.安装和配置Nginx
|
||||
a.安装Nginx
|
||||
|
||||
```sh
|
||||
cd /usr/local/src/
|
||||
wget http://nginx.org/download/nginx-1.15.2.tar.gz
|
||||
tar -zxvf nginx-1.15.2.tar.gz
|
||||
cd nginx-1.15.2
|
||||
./configure --prefix=/usr/local/nginx --add-module=/usr/local/src/fastdfs-nginx-module-1.20/src/
|
||||
make && make install
|
||||
```
|
||||
|
||||
b.配置Nginx
|
||||
|
||||
```sh
|
||||
cd /usr/local/nginx/conf/
|
||||
vi nginx.conf
|
||||
```
|
||||
|
||||
加一段内容:
|
||||
|
||||
```nginx
|
||||
location ~/M00 {
|
||||
root /home/fastdfs/storage/data;
|
||||
ngx_fastdfs_module;
|
||||
}
|
||||
```
|
||||
|
||||
3.2.启动nginx和测试
|
||||
1)启动nginx
|
||||
|
||||
```sh
|
||||
cd /usr/local/nginx/sbin/
|
||||
./nginx
|
||||
```
|
||||
|
||||
2)生成测试文件
|
||||
|
||||
```sh
|
||||
cd /usr/local/src
|
||||
touch a.txt
|
||||
vi a.txt
|
||||
```
|
||||
|
||||
插入如下内容并保存:
|
||||
|
||||
```sh
|
||||
kungpeng test fastdfs ok!
|
||||
```
|
||||
|
||||
3)生成文件链接
|
||||
|
||||
```sh
|
||||
/usr/bin/fdfs_upload_file /etc/fdfs/client.conf a.txt
|
||||
```
|
||||
|
||||
回显信息如下:
|
||||
|
||||
```
|
||||
[root@ecs-c755 src]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf a.txt
|
||||
group1/M00/00/00/wKgB7l5Uiy2AAnPRAAAAGmbRVtQ088.txt
|
||||
```
|
||||
|
||||
4)浏览器访问文件链接
|
||||
放通云服务器安全组中入口规则里的80端口,在浏览器中输入“http://[ECS IP]:80/group1/M00/00/00/wKgB7l5Uiy2AAnPRAAAAGmbRVtQ088.txt”可以看到返回的“a.txt”相关信息。
|
||||
4.老数据迁移
|
||||
将原FastDFS下的文件,拷贝到该服务器目录下“`/home/fastdfs/storage/data`”文件夹内。
|
BIN
centos-fastdfs/FastDFS.tar.gz
Normal file
BIN
centos-fastdfs/FastDFS.tar.gz
Normal file
Binary file not shown.
44
centos-fastdfs/README.md
Normal file
44
centos-fastdfs/README.md
Normal file
@@ -0,0 +1,44 @@
|
||||
## FastDFS 快速配置安装
|
||||
### 依赖包
|
||||
|
||||
```sh
|
||||
# 下载依赖包
|
||||
wget http://1453788.d.cturls.net/down/1453788/fastdfs/FastDFS.tar.gz -O FastDFS.tar.gz
|
||||
|
||||
# 解压依赖包
|
||||
tar -zxvf FastDFS.tar.gz
|
||||
|
||||
# 进入文件夹
|
||||
cd FastDFS
|
||||
```
|
||||
|
||||
### 脚本参数修改
|
||||
|
||||
根据自己的需求,修改shell脚本中的定义的 `端口`、`ip`、`安装目录`等内容,除了`ip地址`外,其他都可以使用默认。
|
||||
|
||||
```sh
|
||||
#定义配置参数
|
||||
|
||||
# 自定义 ip
|
||||
ip="172.19.0.14" #服务器的IP,根据实际情况修改
|
||||
|
||||
# 命令行获取当前的 ip
|
||||
# ip = `ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
|
||||
|
||||
tracker_port="22122" #跟踪服务器端口号,一般使用默认,不用修改
|
||||
storage_port="23000" #存储服务器端口号,一般使用默认,不用修改
|
||||
nginx_port="80" #Nginx端口号,根据实际情况修改
|
||||
````
|
||||
|
||||
### 执行一键安装脚本
|
||||
|
||||
```sh
|
||||
sh fastDFS_nginx_exec.sh
|
||||
```
|
||||
|
||||
### 测试文件上传及访问
|
||||
|
||||
```sh
|
||||
fdfs_upload_file /etc/fdfs/client.conf /tmp/a.txt
|
||||
```
|
||||
返回FID表示成功 如:group1/M00/00/00/xx.txt
|
173
centos-fastdfs/centos-fasdfs-install.sh
Normal file
173
centos-fastdfs/centos-fasdfs-install.sh
Normal file
@@ -0,0 +1,173 @@
|
||||
#!/bin/bash
|
||||
source ~/.bashrc
|
||||
|
||||
# 颜色变量'\033[字背景颜色;字体颜色m字符串\033[0m'
|
||||
GREENCOLOR='\033[1;32m'
|
||||
NC='\033[0m'
|
||||
|
||||
#准备工作
|
||||
#在生产环境中,建议不要关闭防火墙,根据实际需要开启端口即可
|
||||
#使用ifconfig查看本机ip地址
|
||||
|
||||
#自定义变量(注!!!执行脚本前需要进行修改)
|
||||
#安装包目录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="172.19.0.14" #服务器的IP,根据实际情况修改
|
||||
|
||||
# 命令行获取当前的 ip
|
||||
# ip = `ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
|
||||
|
||||
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目录,一般不用修改
|
||||
bp_storage0=${bp_fastdfs}"/storage0" #storage_path目录,即文件存储目录,一般不用修改
|
||||
#以上部分需要根据实际情况修改
|
||||
|
||||
echo -e "${GREENCOLOR}下面开始安装.......${NC}"
|
||||
|
||||
echo -e "${GREENCOLOR}创建目录${NC}"
|
||||
mkdir -p ${bp_tracker}
|
||||
mkdir -p ${bp_storage}
|
||||
mkdir -p ${bp_client}
|
||||
mkdir -p ${bp_storage0}
|
||||
|
||||
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
|
||||
sp_libfastcommon=${fn_libfastcommon%.*}
|
||||
sp_fastdfs=${fn_fastdfs%.*}
|
||||
sp_fastdfs_nginx_module=${fn_fastdfs_nginx_module%.*}
|
||||
sp_nginx=${fn_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_storage0}#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}"
|
Reference in New Issue
Block a user