官方文档中关于集群的配置需要在cloud-config.yaml中配置discovery,而我的实验环境没有外网。
- #cloud-config
- coreos:
- etcd:
- # generate a new token for each unique cluster from https://discovery.etcd.io/new
- discovery: https://discovery.etcd.io/<token>
- # multi-region and multi-cloud deployments need to use $public_ipv4
- addr: $private_ipv4:4001
- peer-addr: $private_ipv4:7001
- units:
- - name: etcd.service
- command: start
- - name: fleet.service
- command: start
解决方案1、搭建自己的Discovery Endpoint(我没解决)
https://github.com/coreos/discovery.etcd.io 下载本地部署。我部署访问显示不能生成token,放弃尝试,有兴趣的朋友可以尝试下,期待你的解决。
解决方案2、手工启动etcd(有问题)
登录coreos1
- ssh core@192.168.1.104
执行如下代码
- etcd -name="coreos1" -addr="192.168.1.104:4001" -peer-addr="192.168.1.104:7001" -data-dir="/home/core/etcd"
登录coreos2
- ssh core@192.168.1.106
执行如下代码
- etcd -name="coreos2" -addr="192.168.1.105:4001" -peer-addr="192.168.1.105:7001" -peers="192.168.1.104:7001" -data-dir="/home/core/etcd"
登录coreos3
- ssh core@192.168.1.105
执行如下代码
- etcd -name="coreos3" -addr="192.168.1.106:4001" -peer-addr="192.168.1.106:7001" -peers="192.168.1.104:7001,192.168.1.105:7001" -data-dir="/home/core/etcd"
测试集群
新开窗口登录coreos1
- ssh core@192.168.1.103
输入
- fleetctl list-machines
得到
- core@coreos1 ~ $ fleetctl list-machines
- MACHINE IP METADATA
- 79a6a4fe... 192.168.1.103 -
- d049e2ca... 192.168.1.106 -
- dcbf31c5... 192.168.1.105 -
问题
1、etcd不能后台运行
按照上面的etcd命令执行,当关闭客户端的时候,etcd就关闭了,随之集群就没有了,尝试nohup无效。
解决方案3:使用cloud-config.yaml(用这个吧)
单个机器按照《平台云基石-CoreOS之离线安装篇(无需互联网)》,配置按照如下做修改。完美解决!此处要格外小心yaml文件的格式缩进、空格、tab等等,若失败多检查文件。
第一台机器
为主节点,配置如下
cloud-config-104.yaml
- #cloud-config
- hostname: coreos1
- coreos:
- etcd:
- addr: 192.168.1.104:4001
- peer-addr: 192.168.1.104:7001
- units:
- - name: etcd.service
- command: start
- - name: fleet.service
- command: start
- - name: static.network
- content: |
- [Match]
- Name=enp3s0
- [Network]
- Address=192.168.1.104/24
- Gateway=192.168.1.254
- DNS=192.168.1.254
- users:
- - name: core
- ssh-authorized-keys:
- - ssh-rsa #你的公钥
- - groups:
- - sudo
- - docker
第二台机器
cloud-config-105.yaml
- #cloud-config
- hostname: coreos2
- coreos:
- etcd:
- peers: 192.168.1.104:7001
- addr: 192.168.1.105:4001
- peer-addr: 192.168.1.105:7001
- units:
- - name: etcd.service
- command: start
- - name: fleet.service
- command: start
- - name: static.network
- content: |
- [Match]
- Name=enp3s0
- [Network]
- Address=192.168.1.105/24
- Gateway=192.168.1.254
- DNS=192.168.1.254
- users:
- - name: core
- ssh-authorized-keys:
- - ssh-rsa #你的公钥
- - groups:
- - sudo
- - docker
第三台机器
cloud-config-106.yaml
- #cloud-config
- hostname: coreos3
- coreos:
- etcd:
- peers: 192.168.1.104:7001
- addr: 192.168.1.106:4001
- peer-addr: 192.168.1.106:7001
- units:
- - name: etcd.service
- command: start
- - name: fleet.service
- command: start
- - name: static.network
- content: |
- [Match]
- Name=enp3s0
- [Network]
- Address=192.168.1.106/24
- Gateway=192.168.1.254
- DNS=192.168.1.254
- users:
- - name: core
- ssh-authorized-keys:
- - ssh-rsa #你的公钥
- - groups:
- - sudo
- - docker
测试
- fleetctl list-machines
时间: 2024-09-28 20:44:38