1 Star 0 Fork 12

lxh5431/docker_bigdata

forked from lzc2025/docker_bigdata 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
contains.sh 2.08 KB
一键复制 编辑 原始数据 按行查看 历史
lzc 提交于 2020-11-08 16:26 . 增加zsh,oh-my-zsh,autojump, 语法高亮
#!/bin/bash
hosts=(162 163 164)
case $1 in
"start")
br0=$(ifconfig | grep ^br0)
if [ -z "$br0" ]; then
# 获取 eth0 或者 eth33 的 ip
if [ -n "$(ifconfig | grep eth0)" ]; then
ip=$(ifconfig eth0 | awk '/inet / { print $2 }')
device=eth0
else
ip=$(ifconfig ens33 | awk '/inet / { print $2 }')
device=ens33
fi
gateway=$(ip route show | awk '/default/ {print $3}')
echo ""
echo "开始搭建网桥...."
sudo brctl addbr br0; \
sudo ip link set dev br0 up; \
sudo ip addr del "$ip"/24 dev $device; \
sudo ip addr add "$ip"/24 dev br0 ; \
sudo brctl addif br0 $device ; \
sudo ip route add default via "$gateway" dev br0
echo "网桥 br0 搭建成功"
else
echo "网桥已经搭建, 不需要重新搭建...."
fi
echo ""
echo "开始启动容器....."
for contain in ${hosts[*]} ; do
echo "===== 启动容器: hadoop$contain ======"
docker start hadoop"$contain"
echo "===== 容器: hadoop$contain 启动成功 ======"
echo "++++++++++++++++++++++++++++++++++++"
done
echo "5 秒之后给容器配置 ip ......"
sleep 5
echo "开始给容器配置 ip ......"
# ip前 3 个字段
pre_ip=$(ifconfig br0 | awk '/inet / { print $2 }'|awk -F '.' '{print $1"."$2"."$3}')
gateway=$(ip route show | awk '/default/ {print $3}')
sudo pipework br0 hadoop"${hosts[0]}" "$pre_ip"."${hosts[0]}"/24@"$gateway"
sudo pipework br0 hadoop"${hosts[1]}" "$pre_ip"."${hosts[1]}"/24@"$gateway"
sudo pipework br0 hadoop"${hosts[2]}" "$pre_ip"."${hosts[2]}"/24@"$gateway"
echo "完成容器 ip 配置 ......"
;;
"stop")
echo "开始关闭容器....."
for contain in ${hosts[*]} ; do
echo "===== 关闭容器: hadoop$contain ======"
docker stop hadoop"$contain"
done
;;
*)
echo "你启动的姿势不对, 换个姿势再来"
echo " contains.sh start 启动所有容器"
echo " contains.sh stop 关闭所有容器"
;;
esac
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/li842094/docker_bigdata.git
git@gitee.com:li842094/docker_bigdata.git
li842094
docker_bigdata
docker_bigdata
main

搜索帮助

0d507c66 1850385 C8b1a773 1850385