flannel一键安装运行

1.脚本运行

# 参数为etcd集群
 ./flannel.sh http://192.168.2.44:2379,http://192.168.2.45:2379,http://192.168.2.46:2379

2.脚本源码

#!/bin/sh
# ./flannel.sh http://192.168.2.44:2379,http://192.168.2.45:2379,http://192.168.2.46:2379
# etcdctl set /coreos.com/network/config '{"Network": $1, "Backend":{"Type": "vxlan"}}'
# etcdctl get /coreos.com/network/config

flanneld -version

if [[ $? -eq 0 ]];
	then 
		echo 'flannel exists, exit!'
		exit
	else 
		yum -y install flannel
fi

tee /etc/sysconfig/flanneld <<-'EOF'
FLANNEL_ETCD="$1"
FLANNEL_ETCD_KEY="/coreos.com/network"
EOF

echo "replace config file :" $1 
sed -i "s%\$1%"$1"%g"  /etc/sysconfig/flanneld
echo "sysatemctl start"
systemctl start flanneld
systemctl enable flanneld


mk-docker-opts.sh -i
source /run/flannel/subnet.env
echo ${FLANNEL_NETWORK}
echo ${FLANNEL_SUBNET}
ifconfig docker0 ${FLANNEL_SUBNET}
route -n
systemctl restart docker

flanneld -version
if [[ $? -eq 0 ]];
	then 
		echo 'flanneld install success!'
	else 
		echo 'flanneld install error!'
fi
posted @ 2016-07-22 16:08  mint_vip  阅读(550)  评论(0)    收藏  举报