• 华为私有云HCS810中Ubuntu镜像分发ECS不能修改主机名问题


    背景:HCS810   Ubuntu操作系统无法自定主机名,cloud-init和UVP-tools安装完成

    #vim /etc/cloud/cloud.cfg
    参数preserve_hostname: true 修改成true
    然后把这两行注释"set_name"和"update_hostname"
      1 # The top level settings are used as module
      2 # and system configuration.
      3 # A set of users which may be applied and/or used by various modules
      4 # when a 'default' entry is found it will reference the 'default_user'
      5 # from the distro configuration specified below
      6 users:
      7    - default
      8 
      9 
     10 # If this is set, 'root' will not be able to ssh in and they
     11 # will get a message to login instead as the default $user
     12 disable_root: true
     13 
     14 # This will cause the set+update hostname module to not operate (if true)
     15 preserve_hostname: true
     16 
     17 # If you use datasource_list array, keep array items in a single line.
     18 # If you use multi line array, ds-identify script won't read array items.
     19 # Example datasource config
     20 # datasource:
     21 #    Ec2:
     22 #      metadata_urls: [ 'blah.com' ]
     23 #      timeout: 5 # (defaults to 50 seconds)
     24 #      max_wait: 10 # (defaults to 120 seconds)
     25 
     26 
     27 
     28 # The modules that run in the 'init' stage
     29 cloud_init_modules:
     30  - migrator
     31  - seed_random
     32  - bootcmd
     33  - write-files
     34  - growpart
     35  - resizefs
     36  - disk_setup
     37  - mounts
     38  #- set_hostname
     39  #- update_hostname
     40  - update_etc_hosts
     41  - ca-certs
     42  - rsyslog
     43  - users-groups
     44  - ssh
     45 
     46 # The modules that run in the 'config' stage
     47 cloud_config_modules:
     48 # Emit the cloud config ready event
     49 # this can be used by upstart jobs for 'start on cloud-config'.
     50  - emit_upstart
     51  - snap
     52  - ssh-import-id
     53  - locale
     54  - set-passwords
     55  - grub-dpkg
     56  - apt-pipelining
     57  - apt-configure
     58  - ubuntu-advantage
     59  - ntp
     60  - timezone
     61  - disable-ec2-metadata
     62  - runcmd
     63  - byobu
     64 
     65 # The modules that run in the 'final' stage
     66 cloud_final_modules:
     67  - package-update-upgrade-install
     68  - fan
     69  - landscape
     70  - lxd
     71  - ubuntu-drivers
     72  - write-files-deferred
     73  - puppet
     74  - chef
     75  - mcollective
     76  - salt-minion
     77  - reset_rmc
     78  - refresh_rmc_and_interface
     79  - rightscale_userdata
     80  - scripts-vendor
     81  - scripts-per-once
     82  - scripts-per-boot
     83  - scripts-per-instance
     84  - scripts-user
     85  - ssh-authkey-fingerprints
     86  - keys-to-console
     87  - install-hotplug
     88  - phone-home
     89  - final-message
     90  - power-state-change
     91 
     92 # System and/or distro specific settings
     93 # (not accessible to handlers/transforms)
     94 system_info:
     95    # This will affect which distro class gets used
     96    distro: ubuntu
     97    # Default user name + that default users groups (if added/used)
     98    default_user:
     99      name: ubuntu
    100      lock_passwd: True
    101      gecos: Ubuntu
    102      groups: [adm, audio, cdrom, dialout, dip, floppy, lxd, netdev, plugdev, sudo, video]
    103      sudo: ["ALL=(ALL) NOPASSWD:ALL"]
    104      shell: /bin/bash
    105    # Automatically discover the best ntp_client
    106    ntp_client: auto
    107    # Other config here will be given to the distro class and/or path classes
    108    paths:
    109       cloud_dir: /var/lib/cloud/
    110       templates_dir: /etc/cloud/templates/
    111       upstart_dir: /etc/init/
    112    package_mirrors:
    113      - arches: [i386, amd64]
    114        failsafe:
    115          primary: http://archive.ubuntu.com/ubuntu
    116          security: http://security.ubuntu.com/ubuntu
    117        search:
    118          primary:
    119            - http://%(ec2_region)s.ec2.archive.ubuntu.com/ubuntu/
    120            - http://%(availability_zone)s.clouds.archive.ubuntu.com/ubuntu/
    121            - http://%(region)s.clouds.archive.ubuntu.com/ubuntu/
    122          security: []
    123      - arches: [arm64, armel, armhf]
    124        failsafe:
    125          primary: http://ports.ubuntu.com/ubuntu-ports
    126          security: http://ports.ubuntu.com/ubuntu-ports
    127        search:
    128          primary:
    129            - http://%(ec2_region)s.ec2.ports.ubuntu.com/ubuntu-ports/
    130            - http://%(availability_zone)s.clouds.ports.ubuntu.com/ubuntu-ports/
    131            - http://%(region)s.clouds.ports.ubuntu.com/ubuntu-ports/
    132          security: []
    133      - arches: [default]
    134        failsafe:
    135          primary: http://ports.ubuntu.com/ubuntu-ports
    136          security: http://ports.ubuntu.com/ubuntu-ports
    137    ssh_svcname: ssh

    然后执行

    虚拟机内执行rm -rf /var/lib/cloud/*和rm -f /var/log/cloud-init* (高危操作 切勿在生产镜像虚拟机中直接执行,要先进行测试没问题后再进行生产环境的动作)
    #rm -rf /var/lib/cloud/*
    #rm -f /var/log/cloud-init*

    不需要重装cloud-init,关机转成镜像后测试。

    #vim /etc/cloud/cloud.cfg配置禁止cloud-init接管网络

    在最后一行添加

    network:

      config: disabled

    删除/etc/cloud/cloud.cfg.d/目录下除了log相关的配置文件外的所有文件

    至此问题并没有解决;

    然后重新搞了一台新的镜像虚拟机

    调整配置:

    1、rm -rf /var/lib/cloud/*

    2、rm -f /var/log/cloud-init*

    3、删除/etc/cloud/cloud.cfg.d/目录下除了log相关的配置文件外的所有文件

    4、vim /etc/cloud/cloud.cfg配置禁止cloud-init接管网络(可选)

     #vim /etc/cloud/cloud.cfg配置禁止cloud-init接管网络

      在最后一行添加

    network:

      config: disabled

    然后制作镜像,成了 主机名能够自定义识别了。

  • 相关阅读:
    移植thinkPHP的dump()函数
    PHP生成linux命令行进度条
    没有ORM库的时候,通过PDO连接MySQL的方法
    mysql json字符串 解析成对应字段
    linux上安装并启动nginx
    linux上启动redis
    mui的input搜索框里的清除按钮的点击监听事件
    miniui 修改input样式及弹出框按钮文字
    js 删除数组元素的方法
    miniui反选
  • 原文地址:https://www.cnblogs.com/hekuangquanshuiweiteng/p/16300843.html
Copyright © 2020-2023  润新知