标签:eating 分发 多少 缓存 ica tar 相关 already 直接
1.服务端与客户端建立公钥及私钥信任关系。服务端作为原始文件存储地,ansible主机。(这个一般在云服务器管理中常见,堡垒机到内网主机ssh连接,但是每连一台主机都输入密码短语都比较麻烦,可用以下方式设置)
运行eval命令自动声明环境变量。eval ssh-agent
ssh环境变量加入当前会话环境变量。
ssh-add 把专用密钥添加到ssh-agent的高速缓存中。提示输入密码短语,输入即可。
在当前的环境变量中直接ssh就能连接到远程主机。退出当前shell的时候,ssh-agent也退出。下次连接的时候,再次eval即可。
2.相关脚本定义
思路:基于第一步,建立了ansible主机到各个客户端信任关系后,运行tracker服务,生成大文件的.torrent的文件,播种需要分发的文件包,最后在客户端定义下载文件脚本。
2.1 首先定义两个目录 :存放大文件目录/opt/data/ ;定义脚本目录/opt/app/
2.2 修改/opt/app/murder下的seeder.conf配置文件内容。
#大文件
deploy_file=/opt/data/update_v0.27-91-2
#要生成的torrent文件存放地址,放在ansible的相应目录下。
torrent_file=/etc/ansible/roles/update/files/update_v0.27-91-2.torrent
#tracker服务,其他成员依赖tracker
tracker_ip=21.0.0.153:8998
local_ip=21.0.0.153
2.3 /opt/app/murder/murder_tracker.sh 定义,启动。
#/bin/sh
name="murder-tracker"
murder_tracker_bin="/opt/app/murder/murder-master/dist/murder_tracker.py"
murder_tracker_log="/opt/log/murder/murder_tracker.log"
murder_tracker_data="/opt/data/murder/tracker_data"
find_tracker_process(){
PID=`ps -ef |grep murder_tracker|grep python |grep -v $0|grep -v grep |grep -v sh|awk ‘{print $2}‘`
}
start(){
LOG_DIR=`dirname $murder_tracker_log`
DATA_DIR=`dirname $murder_tracker_data`
if [ ! -d $LOG_DIR ];then
#echo -e "\e[35mlog dir $LOG_DIR doesn‘t exist,creating\e[0m"
printf "log dir $LOG_DIR doesn‘t exist,creating...\n"
mkdir -p $LOG_DIR
fi
if [ ! -d $DATA_DIR ];then
printf "data dir $DATA_DIR doesn‘t exist,creating...\n"
mkdir -p $DATA_DIR
fi
find_tracker_process
echo $PID
if [ "$PID" != "" ]; then
printf "$name is already running...\n"
else
python $murder_tracker_bin > /dev/null 2>&1 &
printf "starting $name done....\n"
fi
}
stop(){
if [ `netstat -lnpt |grep 8998 |wc -l` -eq 1 ];then
find_tracker_process
kill $PID
printf "stoping $name done...\n"
else
printf "$name is already stopping...\n"
fi
}
restart(){
stop
sleep 2
start
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
printf "Usage: $0 {start|stop|restart}\n"
esac
exit
2.4 /opt/app/murder/murder_seeder.sh定义,启动。
#!/bin/sh
name="murder-seeder"
muder_seeder_data="/opt/data/murder"
muder_seeder_log="/opt/log/murder/muder_seeder.log"
murder_make_torrent_bin="/opt/app/murder/murder-master/dist/murder_make_torrent.py"
murder_seeder_bin="/opt/app/murder/murder-master/dist/murder_client.py"
seeder_conf_path="/opt/app/murder/seeder.conf"
deploy_file=$(awk -F= ‘/deploy_file/{print $2}‘ $seeder_conf_path)
torrent_file=$(awk -F= ‘/torrent_file/{print $2}‘ $seeder_conf_path)
tracker_ip=$(awk -F= ‘/tracker_ip/{print $2}‘ $seeder_conf_path)
local_ip=$(awk -F= ‘/local_ip/{print $2}‘ $seeder_conf_path)
#echo $murder_make_torrent_bin $deploy_file $tracker_ip $torrent_file
find_seed_process(){
PID=`ps -ef |grep murder_client|grep seed |grep -v $0|grep -v grep |grep -v sh|awk ‘{print $2}‘`
}
start(){
#make torrent
python $murder_make_torrent_bin $deploy_file $tracker_ip $torrent_file
#echo $?
if [ $? != 0 ];then
python $muder_make_torrent_bin $deploy_file $tracker_ip $torrent_file
fi
find_seed_process
#echo $PID
if [ "$PID" != "" ]; then
printf "$name is already running...\n"
else
python $murder_seeder_bin seed $torrent_file $deploy_file $local_ip >/dev/null 2>&1 &
printf "starting $name done....\n"
fi
}
stop(){
find_seed_process
if [ $PID != "" ];then
kill $PID
printf "stoping $name done...\n"
else
printf "$name is already stopping...\n"
fi
}
restart(){
stop
sleep 2
start
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
printf "Usage: $0 {start|stop|restart}\n"
esac
exit
2.5
标签:eating 分发 多少 缓存 ica tar 相关 already 直接
原文地址:https://blog.51cto.com/12191723/2432761