filer使用:seaweedfs安装配置使用
http://blog.chinaunix.net/uid-29677448-id-5602995.html
java使用https://github.com/HalfWater/seaweedfs-java-client(自己下载编译)
1、下载weedfs:https://github.com/chrislusf/seaweedfs/releases
wget https://github.com/chrislusf/seaweedfs/releases/download/2.14/linux_amd64.tar.gz
mkdir -p /usr/local/weedfs/ cd /usr/localweedfs/
mkdir -p /home/yyt/weedfs/
/weedfs目录
tar -xzvf linux_amd64.tar.gz
mkdir -p /data/weedfs_data
mkdir -p /data/weedfs_data/vol{a..c}
mkdir -p /data/weedfs_data/master
mkdir -p /data/weedfs_data/filter
nohup ./weed master -mdir=/root/sea/data -port=9333 -ip="172.16.20.71" &>> /root/sea/logs/master.log & ------------------ ./weed volume -dir="D:\data1" -max=500 -mserver="localhost:9333" -port=9331 &>>/root/sea/logs/vol1.log & ./weed volume -dir="D:\data2" -max=500 -mserver="localhost:9333" -port=9332 &>>/root/sea/logs/vol1.log & volume默认最大7个,你可以设置100等等。。。 -master.volumeSizeLimitMB 默认最大30000000 (30G) -filer.dir 目录来存储元数据,默认为指定-dir的“filer”子目录 -master.dir用于存储元数据的数据目录,默认为与指定的-dir相同
./weed -log_dir='/path/to/seaweedfs/master/logs' master -defaultReplication="001" -mdir="./master" -peers="1.1.2.2:9333" -volumeSizeLimitMB=10
./weed -log_dir='/path/to/seaweedfs/volume/logs' volume -dir="volume" -ip="1.1.2.3" -max="3" -mserver='1.1.2.2:9333' -rack='rack2'
建议在启动服务时都指定一下log_dir, 否则使用的默认值是/tmp目录, 生成的文件较多, 很难看.
https://blog.csdn.net/weixin_34380296/article/details/92359656
ps -ef | grep weed
docker rm -f master ; docker rm -f volume
#docker ps -n 4
cd /home/yyt/weedfs/data ;du -sh *
# 创建文件夹
rm -rf /home/yyt/weedfs/data && \
mkdir -p /home/yyt/weedfs/data/master && \
mkdir -p /home/yyt/weedfs/data/vol1
#用这条命令,开启一个master
docker run -d --restart=always \
-p 9333:9333 \
--name master \
-v /home/yyt/weedfs/data/master:/data \
chrislusf/seaweedfs \
master \
-ip="10.60.0.22"
#用这条命令,开一个volume,master不用写成ip
docker run -d --restart=always \
-v /home/yyt/weedfs/data/vol1:/data \
-p 8089:8080 -p 18080:18080 \
--name volume \
--link master \
chrislusf/seaweedfs \
volume \
-max=15 -mserver="master:9333" -port=8080 \
-publicUrl="10.60.0.22:8089"
docker run -d --restart=always \
-p 8089:8089 -p 18080:18080 \
--name volume1 \
--link master \
chrislusf/seaweedfs \
volume \
-max=15 -mserver="10.60.0.23:9333" -port=8089
# 可以创建第二个volume
docker run -d --restart=always \
-p 8090:8090 -p 18080:18080 \
--name volume2 \
chrislusf/seaweedfs \
volume -volumeSizeLimitMB=10 -mserver="master:9333" -port=8090
# 访问
http://10.60.0.23:9333/
docker-compose搭建:
debian8
python2.7
docker17.04
docker-compose1.12.0
1)git clone https://github.com/chrislusf/seaweedfs.git
2)cd seaweedfs/docker
3)docker build -t sunsl/seaweedfs .
4)修改docker-compose.yml中的 image 为 sunsl/seaweedfs
5)docker-compose up
参考docker-compose.yml
version: '2'
services:
master:
image: chrislusf/seaweedfs # use a remote image
volumes:
- $PWD/out:/etc/seaweedfs/out
- $PWD/security.toml:/etc/seaweedfs/security.toml
- $PWD/filer.toml:/etc/seaweedfs/filer.toml
- /var/yr/seaweedfs_data/master:/data
# ports:
# - 9333:9333
# - 19333:19333
command: "master"
restart: always
networks:
seaweedfs_network:
volume:
image: chrislusf/seaweedfs # use a remote image
volumes:
- $PWD/out:/etc/seaweedfs/out
- $PWD/security.toml:/etc/seaweedfs/security.toml
- $PWD/filer.toml:/etc/seaweedfs/filer.toml
- /var/yr/seaweedfs_data/node1:/data
# ports:
# - 8080:8080
# - 18080:18080
command: 'volume -max=45 -index=leveldb -mserver="master:9333" -port=8080'
depends_on:
- master
restart: always
networks:
seaweedfs_network:
filer:
image: chrislusf/seaweedfs # use a remote image
volumes:
- $PWD/out:/etc/seaweedfs/out
- $PWD/security.toml:/etc/seaweedfs/security.toml
- $PWD/filer.toml:/etc/seaweedfs/filer.toml
- /var/yr/seaweedfs_data/filerdb:/data/filerdb
# ports:
# - 8880:8888
# - 18880:18888
command: 'filer -master="master:9333" -collection "finance"'
# tty: true
# stdin_open: true
depends_on:
- master
- volume
- mysql
restart: always
networks:
seaweedfs_network:
nxinx:
image: nginx:alpine
volumes:
- $PWD/pwd:/pwd
- $PWD/nginx.conf:/etc/nginx/nginx.conf
links:
- filer
ports:
- 8600:80
restart: always
networks:
seaweedfs_network:
mysql:
image: mysql:latest
environment:
- MYSQL_ROOT_PASSWORD=lambdax
- MYSQL_USER=finance
- MYSQL_PASSWORD=shuzhi2019
- MYSQL_DATABASE=seaweedfs_finance_filer
volumes:
- /var/yr/seaweedfs_data/mysql_data:/var/lib/mysql
ports:
- "8599:3306"
restart: always
networks:
seaweedfs_network:
# cronjob:
# image: chrislusf/seaweedfs # use a remote image
# volumes:
# - ./out:/etc/seaweedfs/out
# - ./security.toml:/etc/seaweedfs/security.toml
# - ./filer.toml:/etc/seaweedfs/filer.toml
# # ports:
# command: 'cronjob'
# environment:
# # Run re-replication every 2 minutes
# CRON_SCHEDULE: '*/2 * * * * *' # Default: '*/5 * * * * *'
# WEED_MASTER: master:9333 # Default: localhost:9333
# depends_on:
# - master
# - volume
# restart: always
# networks:
# seaweedfs_network:
networks:
seaweedfs_network:
ipam:
config:
- subnet: 192.168.10.0/24
gateway: 192.168.10.111
1)获取Fid和URL
# curl "http://localhost:9333/dir/assign?replication=001"
curl -X POST http://localhost:9333/dir/assign
{"fid":"1,0240cd0175","url":"172.18.0.3:8080","publicUrl":"172.18.0.3:8080","count":1}
#申请带存活时间的fid
# ttl string 存活时间 1m,1h,1d,1M,1y
# 获取fid带ttl的 http://localhost:9333/dir/assign?ttl=2m
# 获取上传带ttl的 http://localhost:9333/5,01d8f2bc3c?ttl=2m
# 取fid带ttl的时间要大于等于上传带ttl的时间
# 上传
curl -F file=@qs.png http://192.168.2.101:9333/5,01d8f2bc3c
# 查看
GET http://192.168.2.101:9333/5,01d8f2bc3c
# 查看卷
# curl -X get http://192.168.0.193:9333/dir/lookup?volumeId=8
GET http://localhost:9333/dir/lookup?volumeId=40
{
"volumeId": "40",
"locations": [
{
"url": "192.168.10.212:8082",
"publicUrl": "192.168.10.212:8082"
}
]
}
# 查看卷信息
http://localhost:8081/status?pretty=y
http://localhost:8082/status?pretty=y
# 压缩空间
http://localhost:9333/vol/vacuum
(1)tcp端口监控
(2)测试写入, 每1分钟写入1次
[{"fileName":"/tmp/anaconda-post.log","error":"Post http://172.17.0.7:9333/dir/assign: dial tcp 172.17.0.7:9333: connection refused"}] 不正常的返回结果
[{"fileName":"abc.txt","fileUrl":"172.17.0.8:8080/9,01b16f4a4c2f","fid":"9,01b16f4a4c2f","size":83}] 正常的返回结果
(3)各master的 http://172.17.0.8:9333/cluster/status?pretty=y 结果, 必须要有Leader,且同一组master服务器的Leader值要相同.另外因为线上是按3个master部署的, 所以Peers中要有2个才对. 监控这一条是为了保证在出现一个master异常时, 其它master可以自动切换, 否则几个master之间的状态已经不对了, 当主master故障时就没有办法自动切换了.
(4)curl "http://172.17.0.8:9333/dir/status?pretty=y" 检查DataNodes的数量, 这个值表示的是从master中查看到的DataNode的数量. 如果连续2次获取到的DataNode数量不相同, 则表明有节点down机或新扩容了节点
window环境搭建
weed.exe master -mdir=f:\data -port=9333 -ip="localhost"
weed.exe volume -dir="f:\vol" \
-max=4 \
-mserver="localhost:9333" -port=8083
linux环境搭建
一、安装
1、首先安装配置golang开发环境
go的最新版本是1.9.1 可到
https://storage.googleapis.com/golang/go1.9.1.linux-amd64.tar.gz
下载 go1.9.1.linux-amd64.tar.gz
2、上传并解压到指定目录
sudo tar -xzf go1.9.1.linux-amd64.tar.gz -C /opt
3、配置环境变量
vim /etc/profile
export GOROOT=/usr/local/go
export PATH=$GOROOT/bin:$PATH
#export GOPATH=$GORROT/workspace
source /etc/profile
#4、创建文件夹可以直接从这步开始
mkdir -p /home/yyt/weedfs/data/ && \
mkdir -p /home/yyt/weedfs/data/vol1 && \
mkdir -p /home/yyt/weedfs/data/vol2 && \
mkdir -p /home/yyt/weedfs/data/master && \
mkdir -p /home/yyt/weedfs/data/filer
rm -rf /home/yyt/weedfs/data && \
mkdir -p /home/yyt/weedfs/data/master && \
mkdir -p /home/yyt/weedfs/data/vol1
# 查看
netstat -lnp | grep 9333
ps -ef | grep weed
#5、启动master当前目录要使用./weed执行
nohup /home/yyt/weedfs/weed master -mdir=/home/yyt/weedfs/data/master -port=9333 -ip="10.60.0.22" &>>/home/yyt/weedfs/data/master/master.log &
# 查看日志
cat /home/yyt/weedfs/data/master/master.log
#6、启动vol1
nohup /home/yyt/weedfs/weed volume -dir="/home/yyt/weedfs/data/vol1" \
-max=15 \
-mserver="192.168.10.212:9333" -port=8081 \
&>>/home/yyt/weedfs/data/vol1/vol1.log &
#cat /home/yyt/weedfs/data/vol2/vol2.log
#7、 启动vol2
nohup /home/yyt/weedfs/weed volume -dir="/home/yyt/weedfs/data/vol2" \
-max=15 \
-fileSizeLimitMB=8 \
-mserver="192.168.10.212:9333" -port=8082 \
&>>/home/yyt/weedfs/data/vol2/vol2.log &
#关闭 ps -ef | grep weedfs | grep -v grep | awk '{print $2 }' | xargs kill
#------------------扩展
mkdir -p /home/yyt/weedfs/data/filer/leveldb2
#启动filer 生成一个配置文件filer.toml
/home/yyt/weedfs/weed scaffold -config=filer -output=.
#修改filer.toml,把filer的数据目录的dir指向到/home/yyt/weedfs/data/filer/leveldb2下
vi /home/yyt/weedfs/filer.toml
#然后启动filer
nohup /home/yyt/weedfs/weed filer -port=8888 -master=localhost:9333 &>> /home/yyt/weedfs/data/filer/filer.log &
# mount挂载(一般不用,因为使用的容量是双倍的)
mkdir -p /home/yyt/weedfs/data/newfilermount/data
yum install -y fuse
nohup /home/yyt/weedfs/weed mount -filer=localhost:8888 -dir=/home/yyt/weedfs/data/newfilermount/data &>> /home/yyt/weedfs/data/newfilermount/wefsmount.log &
#filer的mount 为了方便本地操作,把一个collection里面的内容挂载导某个目录,方便操作
#post 上传图片http://192.168.10.212:8888/path/to/sources/20150429093808_83019.jpg
#关闭挂在需要关闭mount并且手动umont ~/wz/mdir目录,如果一般用户失败请使用root用户
#使用fid上传挂载目录看不到,挂载的目录大小还是不变
#使用/path/to/sources上传,挂载和volum大小都会增加(相当于双倍使用磁盘容量,只能用1半的容器量了),但是删除操作2个空间都会也立马释放不用在压缩了。
#所有操作都可以访问:http://192.168.10.212:9333/
sh /home/yyt/weedfs/bin/start_weedfs.sh
#!/bin/bash
# master
nohup /home/yyt/weedfs/weed master -mdir=/home/yyt/weedfs/data/master -port=9333 -ip="192.168.10.212" &>>/home/yyt/weedfs/data/master/master.log &
# vol1
nohup /home/yyt/weedfs/weed volume -dir="/home/yyt/weedfs/data/vol1" \
-max=15 \
-fileSizeLimitMB=8 \
-mserver="192.168.10.212:9333" -port=8081 \
&>>/home/yyt/weedfs/data/vol1/vol1.log &
# vol2
nohup /home/yyt/weedfs/weed volume -dir="/home/yyt/weedfs/data/vol2" \
-max=15 \
-fileSizeLimitMB=8 \
-mserver="192.168.10.212:9333" -port=8082 \
&>>/home/yyt/weedfs/data/vol2/vol2.log &
sh /home/yyt/weedfs/bin/stop_weedfs.sh
#!/bin/bash
ps -ef | grep weedfs | grep -v grep | awk '{print $2 }' | xargs kill
echo "weedfs stop"
cd /home/yyt/weedfs/data ;du -sh *
开机启动
Centos 7
vi /etc/rc.d/rc.local
/xx.sh
chmod +x xx.sh
UBUNTU
vi /etc/rc.local
/weedfs/yyt/weedfs/weedfs_service.sh start
启动脚本的创建
现在我们以安装nginx为例,假设我们的nginx安装在/usr/sbin/目录下。
- 首先,我们在/etc/init.d创建文件sudo vim nginx,并将shell代码拷贝进去。
- 修改文件权限为755 sudo chmod 755 nginx。
- 添加服务到启动过程 sudo update-rc.d nginx defaults。
cp /weedfs/yyt/weedfs/weedfs_service.sh /etc/init.d
vi /etc/init.d/weedfs_service.sh
weedfs_service.sh添加 BEGIN INIT INFO信息
```yaml
### BEGIN INIT INFO
# Provides: lostphp.com
# Required-Start: $local_fs $network
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: weedfs service
# Description: weedfs service daemon
### END INIT INFO
sudo update-rc.d start_weedfs.sh defaults
现在,我们就可以用以下命令正常启动nginx了。
启动
/etc/init.d/nginx start
停止
/etc/init.d/nginx stop
重启
/etc/init.d/nginx restart
vi /etc/rc.local
/weedfs/yyt/weedfs/weedfs_service.sh start
cp /weedfs/yyt/weedfs/weedfs_service.sh /etc/init.d/weedfs_service.sh
vi /etc/init.d/weedfs_service.sh
修改后weedfs_service.sh如下:
#!/bin/sh
### BEGIN INIT INFO
# Provides: lostphp.com
# Required-Start: $local_fs $network
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: weedfs service
# Description: weedfs service daemon
### END INIT INFO
export master_port=9333
export volume_port=8089
ip="10.10.103.242"
max=115
WEEDFS_HOME=/weedfs/yyt/weedfs
masterName=master
volumeName=volume
mdir="/weedfs/yyt/weedfs/data/master"
mdir_log="/weedfs/yyt/weedfs/data/master/master.log"
vdir="/weedfs/yyt/weedfs/data/vol1"
vdir_log="/weedfs/yyt/weedfs/data/vol1/vol1.log"
# -d 参数判断 $mdir 是否存在
if [ ! -d "${mdir}" ]; then
mkdir -p "$mdir"
fi
if [ ! -d "${vdir}" ]; then
mkdir -p "${vdir}"
fi
# -f 参数判断 $file 是否存在
if [ ! -f "$mdir_log" ]; then
touch "$mdir_log"
fi
if [ ! -f "$vdir_log" ]; then
touch "$vdir_log"
fi
startMaster(){
echo "--------"Master" begin starting--------------"
nohup ${WEEDFS_HOME}/weed master -mdir="${mdir}" -port=$master_port -ip="${ip}" &>>"${mdir_log}" &
service_pid=`lsof -i:$master_port|grep "LISTEN"|awk '{print $2}'`
until [ -n "$service_pid" ]
do
service_pid=`lsof -i:$master_port|grep "LISTEN"|awk '{print $2}'`
done
echo "master pid is $service_pid"
echo "--------master start success--------------"
}
startVolume(){
echo "---------"volume" begin starting---------------"
nohup ${WEEDFS_HOME}/weed volume -dir="${vdir}" -max=${max} -mserver="${ip}:${master_port}" -port=$volume_port &>>"${vdir_log}" &
service_pid=`lsof -i:$volume_port|grep "LISTEN"|awk '{print $2}'`
until [ -n "$service_pid" ]
do
service_pid=`lsof -i:$volume_port|grep "LISTEN"|awk '{print $2}'`
done
echo "volume pid is $service_pid"
echo "---------"volume" start success-----------"
}
stopMaster(){
# 此处直接写port会重复所以需要加上 port= 才会只有master的进程
P_ID=`ps -ef | grep -w port=${master_port} | grep -v "grep" | awk '{print $2}'`
if [ "$P_ID" == "" ]; then
echo "==="$masterName" process not exists or stop success"
else
kill -9 $P_ID
echo ""$masterName" killed success"
fi
}
stopVolume(){
P_ID=`ps -ef | grep -w ${volume_port} | grep -v "grep" | awk '{print $2}'`
if [ "$P_ID" == "" ]; then
echo "==="$volumeName" process not exists or stop success"
else
kill -9 $P_ID
echo ""$volumeName" killed success"
fi
}
case "$1" in
start)
case "$2" in
master|MASTER)
## 启动
startMaster
;;
volume|VOLUME)
## 启动
startVolume
;;
""|"")
## 启动所有
startMaster
startVolume
;;
esac
;;
stop)
case "$2" in
master|MASTER)
stopMaster
;;
volume|VOLUME)
stopVolume
;;
""|"")
stopMaster
stopVolume
;;
esac
;;
restart)
$0 stop $2
sleep 2
$0 start $2
echo "===restart $2 success==="
;;
esac
exit 0
chmod +x weedfs_service.sh
sudo update-rc.d weedfs_service.sh defaults
weedfs删除比较麻烦,可使用过期删除,但是一直上传使用的情况下不会自动压缩空间(手动测试不出来,可能是上传的频率没有这么高,会自动压缩空间)。
可以创建2对master和volume用定时器切换存储达到不服务自动瘦身的效果。
空间占用少时不会可能不会压缩,可以手动调用压缩的url进行压缩,压缩效果不会马上看出有延时,好像最多10分钟之内会自动完成。
// ip:9333/vol/vacuum
restTemplate.getForObject(Constant.picAccessIpPortWeedFS + "/vol/vacuum", Object.class);