ISO安装CoreOS

计划三个coreos节点如下:
core1.example.com 10.3.8.101
core2.example.com 10.3.8.102
core2.example.com 10.3.8.103
用esxi6.7创建虚拟机,创建类型是新虚拟机,不是用ova镜像,这里从标准的ISO镜像安装。

查看当前稳定版本号:
https://stable.release.core-os.net/amd64-usr/current/version.txt,可以看到当前稳定版为1911.4.0

找一台linux主机(我的是centos7,10.3.8.234),搭建http服务:
yum install -y httpd
sytemctl start httpd
cd /var/www/html //切换到网站主目录
mkdir 1911.4.0 && cd 1911.4.0 //文件夹名必须与版本号相同
下载coreos安装文件到此目录:
wget https://stable.release.core-os.net/amd64-usr/current/coreos_production_image.bin.bz2
wget https://stable.release.core-os.net/amd64-usr/current/coreos_production_image.bin.bz2.sig

利用xshell工具软件生成密钥对:
工具——用户密钥管理者——生成——RSA,2048——生成公钥。

官方不再推荐cloud-config这种文件,取而代之的是方便人类可读的Container Linux Configs文件(yaml格式)和机器专用的Ignition configs文件(json格式)。Container Linux Configs文件并不能直接使用,要将其转换为Ignition configs文件。

在centos7(10.3.8.234)上编辑Container Linux Configs文件并转换成Ignition configs文件。
yum install git make
下载Config transpiler:
cd ~
git clone https://github.com/coreos/container-linux-config-transpiler.git
cd container-linux-config-transpiler
make //生成bin/ct脚本
cd bin

编写Container Linux Configs文件(参考https://coreos.com/os/docs/1911.4.0/clc-examples.html)
[root@cobbler bin]# vi core1.yml

passwd:
  users:
    - name: core
      ssh_authorized_keys:
        - ssh-rsa AAAAB3NzaC1yc......RSA密钥从前面的xshell工具里生成的公钥里复制过来
      groups:
        - wheel
        - docker


networkd:
  units:
    - name: static.network
      contents: |
        [Match]
        Name=ens192

        [Network]
        Address=10.3.8.101/24
        Gateway=10.3.8.254
        DNS=10.1.4.80
       
systemd:
  units:
    - name: settimezone.service
      enabled: true
      contents: |
        [Unit]
        Description=Set the time zone
        [Service]
        Type=oneshot
        RemainAfterExit=yes
        ExecStart=/usr/bin/timedatectl set-timezone Asia/Shanghai

        [Install]
        WantedBy=multi-user.target
        
storage:
  files:
    - path: /etc/hostname
      filesystem: root
      mode: 0644
      user:
        id: 0
      group:
        id: 0
      contents:
        inline: core1.example.com
    - path: /etc/hosts
      filesystem: root
      mode: 0644
      user:
        id: 0
      group:
        id: 0
      contents:
        local: hosts

网卡名要启动liveOS后才能看到,对新手来说,网卡配置这一段可先不要,装完coreos后再配置。

[root@cobbler bin]# vi /root/hosts

127.0.0.1   localhost localhost4
::1         localhost localhost6
10.3.8.101  core1 core1.example.com
10.3.8.102  core2 core2.example.com
10.3.8.103  core3 core3.example.com

将core1.yml复制为core2.yml和core13.yml,每个文件修改其中的主机名和IP,共2处。
将yml格式转换成json格式:
[root@cobbler bin]# ./ct < core1.yml --files-dir /root > /var/www/html/core1.json
[root@cobbler bin]# ./ct < core2.yml --files-dir /root > /var/www/html/core2.json
[root@cobbler bin]# ./ct < core3.yml --files-dir /root > /var/www/html/core3.json
–files-dir /root是告诉脚本到/root下查找hosts文件

到win机器上下载coreos的liveOS启动镜像,类似winpe,是用来安装coreos_production_image.bin.bz2的。
下载链接:https://stable.release.core-os.net/amd64-usr/current/coreos_production_iso_image.iso
从web页登录esxi,左边列表选择存储,右边选择数据存储浏览器,上传刚才下载的iso镜像。

创建三台虚拟机,分别命名core1,core2,core3,分配1cpu,2G内存,内存不足会报错。给虚拟机指定刚才上传的liveOS镜像,然后启动。

启动完成后,默认为core用户自动登录。使用sudo su - root切换到root用户下开始安装:
wget http://10.3.8.234/coreX.json
coreos-install -d /dev/sda -i coreX.json -b http://10.3.8.234
那个coreX.json对应虚拟机的数字号。

安装等几分钟,当看到最后一行
Success! coreos Container Linux stable 1911.4.0 is installed on /dev/sda
就表明安装成功了。
localhost ~ # reboot
重启后就是硬盘版coreos系统了,要用core用户的私钥才能登录了,用诸如xshell工具登录很方便。

基本配置差不多了,配置etcd+TLS的过程跟上一篇博文的过程一模一样,这里就不再重复了。

我有个问题,如果不考虑TLS,把etcd配置写在core1.yml中是可以装系统就能启动集群的。如果考虑TLS,始终启动不了集群。在core1.yml文件中写那几行指定证书位置无法转换成json格式,每个关键字都不能识别,比如test.yml:

etcd:
  version:                     "3.3.9"
  name:                        "core1.example.com"
  advertise_client_urls:       "https://10.3.8.101:2379"
  initial_advertise_peer_urls: "https://10.3.8.101:2380"
  listen_client_urls:          "https://10.3.8.101:2379,https://127.0.0.1:2379"
  listen_peer_urls:            "https://10.3.8.101:2380"
  initial_cluster:              "core1.example.com=https://10.3.8.101:2380"
  client-cert-auth: true 
  cert-file: /etc/ssl/etcd/etcd.pem
  key-file: /etc/ssl/etcd/etcd-key.pem
  trusted-ca-file: /etc/ssl/etcd/ca.pem

转换报错如下:
[root@cobbler bin]# ./ct < test.yml > test.json
Config has unrecognized key: trusted-ca-file
Config has unrecognized key: key-file
Config has unrecognized key: client-cert-auth
Config has unrecognized key: cert-file
我去掉后面4行,但保留https,转换后从json文件中可以看到服务名是etcd-member.service,unit文件名是20-clct-etcd-member.conf。安装完coreos后,可以在/etc/systemd/system/etcd-member.service.d 中找到此文件,etcd相关配置就在其中,把证书相关几行添加到末尾,也是启动不了TLS。

追踪服务程序:
ls -l /etc/systemd/system/multi-user.target.wants/etcd-member.service
lrwxrwxrwx. 1 root root 43 Dec 7 13:49 /etc/systemd/system/multi-user.target.wants/etcd-member.service -> /usr/lib/systemd/system/etcd-member.service

cat /usr/lib/systemd/system/etcd-member.service
可以找到 ExecStart=/usr/lib/coreos/etcd-wrapper $ETCD_OPTS

cat /usr/lib/coreos/etcd-wrapper
从里面也没有找到接收证书相关几行参数的地方,看来不是在20-clct-etcd-member.conf中添加证书相关配置,究竟是在哪里添加呢?

猜你喜欢

转载自blog.csdn.net/liuyuhui_gdtyj/article/details/84866505