我怎样才能做到这一点?
#cloud-config
users:
- name: dev
ssh-authorized-keys:
- ssh-rsa AB3NzaC1yc...
sudo: ['ALL=(ALL) NOPASSWD:ALL']
groups: sudo
shell: /bin/bash
packages:
- mysql-client
- libmysqlclient-dev
- mysql-server
package-update: true
package_upgrade: true
runcmd:
#
# SSH
#
- sed -i -e '/^Port/s/^.*$/Port 22/' /etc/ssh/sshd_config
- sed -i -e '/^PermitRootLogin/s/^.*$/PermitRootLogin no/' /etc/ssh/sshd_config
- sed -i -e '/^PasswordAuthentication/s/^.*$/PasswordAuthentication no/' /etc/ssh/sshd_config
- sed -i -e '$aAllowUsers dev' /etc/ssh/sshd_config
- sudo service ssh restart
#
# Firewall
#
# defaults
- sudo ufw default deny incoming
- sudo ufw default allow outgoing
# exceptions
- sudo ufw allow ssh
- sudo ufw allow http
- sudo ufw allow https
# start on boot
- sed -i -e '/^ENABLED/s/^.*$/ENABLED=yes/' /etc/ufw/ufw.conf
- sudo ufw enable
有了这个配置,root帐户已被禁用。我可以访问dev
使用我的用户帐户进行远程访问。
然而,MySQL安装失败和:
Errors were encountered while processing:
/var/cache/apt/archives/mysql-server-5.7_5.7.17-0ubuntu0.16.04.1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
Cloud-init v. 0.7.8 running 'modules:final' at Sun, 29 Jan 2017 12:09:56 +0000. Up 14.23 seconds.
2017-01-29 12:11:24,114 - util.py[WARNING]: Failed to install packages: ['mysql-client', 'libmysqlclient-dev', 'mysql-server']
2017-01-29 12:11:24,125 - cc_package_update_upgrade_install.py[WARNING]: 1 failed with exceptions, re-raising the last one
2017-01-29 12:11:24,128 - util.py[WARNING]: Running module package-update-upgrade-install (<module 'cloudinit.config.cc_package_update_upgrade_install' from '/usr/lib/python3/dist-packages/cloudinit/config/cc_package_update_upgrade_install.py'>) failed
如果我不指定任何用户,并执行典型设置通过 apt-get安装运行良好。
是不是不可能在禁用 root 帐户的情况下使用 cloud-init 设置 MySQL?如果没有,我能以某种方式告诉cloud-init 在我的软件包安装/更新后设置我的用户?
答案1
我能够通过手动设置 mysql 服务器来克服这个问题:
runcmd:
- sudo apt-get -y install mysql-server
任何有同样问题的人可能也想考虑以非交互方式安装 mysql。
runcmd:
- echo "mysql-server mysql-server/root_password password pwd" | sudo debconf-set-selections
- echo "mysql-server mysql-server/root_password_again password pwd" | sudo debconf-set-selections
- sudo apt-get -y install mysql-server
最初发布的解决方案这里