CentOS7安装etcd和flannel

环境简介:

CentOS Linux release 7.4.1708 (Core)
Linux 3.10.0-693.el7.x86_64
3台linux服务器
172.16.10.100
172.16.10.101
172.16.10.102

软件版本:
etcd-v3.3.5-linux-amd64
flannel-0.7.1-3.el7.x86_64
docker-1.13.1-63.git94f4240.el7.centos.x86_64

etcd安装及配置

是一个键值存储仓库,却没有重视官方定义的后半句,用于配置共享和服务发现。
实际上,etcd作为一个受到Zookeeper与doozer启发而催生的项目,除了拥有与之类似的功能外,更具有以下4个特点{![引自Docker官方文档]}。
简单:基于HTTP+JSON的API让你用curl命令就可以轻松使用。
安全:可选SSL客户认证机制。
快速:每个实例每秒支持一千次写操作。
可信:使用Raft算法充分实现了分布式。

安装etcd

下载链接:https://github.com/coreos/etcd/releases/

wget https://github.com/coreos/etcd/releases/download/v3.3.5/etcd-v3.3.5-linux-amd64.tar.gz
tar -xf etcd-v3.3.5-linux-amd64.tar.gz
cd etcd-v3.3.5-linux-amd64

#将etcd与etcdctl copy到/usr/local/bin
cp etcd etcdctl /usr/local/bin

#添加环境变量
echo "PATH=$PATH:/usr/local/bin" >> /etc/profile

#编写etcd配置文件

vi /etc/etcd/etcd.conf
ETCD_DATA_DIR=/var/lib/etcd
ETCD_NAME=etcd100
ETCD_INITIAL_CLUSTER=etcd100=http://172.16.10.100:2380,etcd101=http://172.16.10.101:2380,etcd102=http://172.16.10.102:2380
ETCD_INITIAL_CLUSTER_STATE=new
ETCD_LISTEN_PEER_URLS=http://172.16.10.100:2380
ETCD_INITIAL_ADVERTISE_PEER_URLS=http://172.16.10.100:2380
ETCD_ADVERTISE_CLIENT_URLS=http://172.16.10.100:2379
ETCD_LISTEN_CLIENT_URLS=http://172.16.10.100:2379,http://127.0.0.1:2379
GOMAXPROCS=$(nproc)

#将配置传给其他两台主机并根据主机IP修改以下变量:ETCD_NAME,ETCD_LISTEN_PEER_URLS,ETCD_INITIAL_ADVERTISE_PEER_URLS,ETCD_ADVERTISE_CLIENT_URLS,ETCD_LISTEN_CLIENT_URLS.

#配置systemd管理控制启动程序

[Unit]
Description=Etcd Server
Documentation=https://github.com/coreos/etcd
After=network.target

[Service]
User=root
Type=simple
EnvironmentFile=-/etc/etcd/etcd.conf
ExecStart=/usr/local/bin/etcd
Restart=on-failure
RestartSec=3s
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target

#分别在三台启动etcd并测试

systemctl start etcd
systemctl enable etcd

#测试程序
etcdctl cluster-health
etcdctl mk /test
etcdctl ls /

#至此etcd集群已经部署完毕,从集群任意一台均可查到etcd配置

docker与flannel安装及配置

yum install docker flannel -y

#修改/etc/sysconfig/flanneld配置
vi etc/sysconfig/flanneld
# Flanneld configuration options

# etcd url location.  Point this to the server where etcd runs
FLANNEL_ETCD_ENDPOINTS="http://172.16.10.100:2379,http://172.16.10.101:2379,http://172.16.10.102:2379"

# etcd config key.  This is the configuration key that flannel queries
# For address range assignment
FLANNEL_ETCD_PREFIX="/atomic.io/network"

# Any additional options that you want to pass
#FLANNEL_OPTIONS=""

#在etcd中添加网络信息
etcdctl mk /atomic.io/network/config '{"Network":"192.167.0.0/16", "SubnetMin": "192.167.1.0", "SubnetMax": "192.167.254.0"}'

#分别启动flannel和docker

systemctl start flanneld
systemctl start docker
systemctl enable flanneld
systemctl enable docker

#使用ifconfig查看网络,会看到flannel0以及docker0两个网卡启动并且分配了预设值的网段,3台设备的物理网段到虚拟网段可以完全互联互通
docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.167.46.1  netmask 255.255.255.0  broadcast 0.0.0.0
        ether 02:42:83:3f:3e:d5  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens192: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.16.10.102  netmask 255.255.255.0  broadcast 172.16.10.255
        inet6 fe80::250:56ff:feba:49a5  prefixlen 64  scopeid 0x20<link>
        ether 00:50:56:ba:49:a5  txqueuelen 1000  (Ethernet)
        RX packets 3511949  bytes 363753229 (346.9 MiB)
        RX errors 0  dropped 40  overruns 0  frame 0
        TX packets 3454048  bytes 287758009 (274.4 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

flannel0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST>  mtu 1472
        inet 192.167.46.0  netmask 255.255.0.0  destination 192.167.46.0
        inet6 fe80::2089:87b0:329d:68ec  prefixlen 64  scopeid 0x20<link>
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 500  (UNSPEC)
        RX packets 2  bytes 168 (168.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 5  bytes 312 (312.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

此条目发表在kubernetes分类目录。将固定链接加入收藏夹。

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注