概述
环境简介:
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
1
2
3
4
5
6
7
8
9
wgethttps://github.com/coreos/etcd/releases/download/v3.3.5/etcd-v3.3.5-linux-amd64.tar.gz
tar-xfetcd-v3.3.5-linux-amd64.tar.gz
cdetcd-v3.3.5-linux-amd64
#将etcd与etcdctl copy到/usr/local/bin
cpetcdetcdctl/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)
1
2
3
4
5
6
7
8
9
10
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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[Unit]
Description=EtcdServer
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 /
1
2
3
4
5
6
7
systemctlstartetcd
systemctlenableetcd
#测试程序
etcdctlcluster-health
etcdctlmk/test
etcdctlls/
#至此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"}'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
yuminstalldockerflannel-y
#修改/etc/sysconfig/flanneld配置
vietc/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中添加网络信息
etcdctlmk/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 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 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
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 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
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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
systemctlstartflanneld
systemctlstartdocker
systemctlenableflanneld
systemctlenabledocker
#使用ifconfig查看网络,会看到flannel0以及docker0两个网卡启动并且分配了预设值的网段,3台设备的物理网段到虚拟网段可以完全互联互通
docker0:flags=4099mtu1500
inet192.167.46.1netmask255.255.255.0broadcast0.0.0.0
ether02:42:83:3f:3e:d5txqueuelen0(Ethernet)
RXpackets0bytes0(0.0B)
RXerrors0dropped0overruns0frame0
TXpackets0bytes0(0.0B)
TXerrors0dropped0overruns0carrier0collisions0
ens192:flags=4163mtu1500
inet172.16.10.102netmask255.255.255.0broadcast172.16.10.255
inet6fe80::250:56ff:feba:49a5prefixlen64scopeid0x20
ether00:50:56:ba:49:a5txqueuelen1000(Ethernet)
RXpackets3511949bytes363753229(346.9MiB)
RXerrors0dropped40overruns0frame0
TXpackets3454048bytes287758009(274.4MiB)
TXerrors0dropped0overruns0carrier0collisions0
flannel0:flags=4305mtu1472
inet192.167.46.0netmask255.255.0.0destination192.167.46.0
inet6fe80::2089:87b0:329d:68ecprefixlen64scopeid0x20
unspec00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00txqueuelen500(UNSPEC)
RXpackets2bytes168(168.0B)
RXerrors0dropped0overruns0frame0
TXpackets5bytes312(312.0B)
TXerrors0dropped0overruns0carrier0collisions0
最后
以上就是自信大白为你收集整理的linux 安装 yum etcd,CentOS7安装etcd和flannel的全部内容,希望文章能够帮你解决linux 安装 yum etcd,CentOS7安装etcd和flannel所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复