Azure FreeBSD 简介Introduction to FreeBSD on Azure

本文概述如何在 Azure 中运行 FreeBSD 虚拟机。This article provides an overview of running a FreeBSD virtual machine in Azure.

概述Overview

Azure FreeBSD 是一种高级的计算机操作系统,用于增强新式服务器、台式机和嵌入式平台的功能。FreeBSD for Azure is an advanced computer operating system used to power modern servers, desktops, and embedded platforms.

我们在 Azure 上提供预先配置了 Azure VM 来宾代理 的 FreeBSD 映像。We are making images of FreeBSD available on Azure with the Azure VM Guest Agent pre-configured. 目前,以下 FreeBSD 版本由 Azure 以映像形式提供:Currently, the following FreeBSD versions are offered as images by Azure:

进行首次使用时的 VM 预配(用户名、密码或 SSH 密钥、主机名等)以及为选择性 VM 扩展启用相关功能等操作时,该代理负责在 FreeBSD VM 和 Azure 结构之间进行通信。The agent is responsible for communication between the FreeBSD VM and the Azure fabric for operations such as provisioning the VM on first use (user name, password or SSH key, host name, etc.) and enabling functionality for selective VM extensions.

至于未来版本的 FreeBSD,所采用的策略是始终进行更新,确保在 FreeBSD 版本工程团队发布最新版本后很快就可以使用这些版本。As for future versions of FreeBSD, the strategy is to stay current and make the latest releases available shortly after they are published by the FreeBSD release engineering team.

在 FreeBSD 上通过 Azure CLI 创建 FreeBSD VMCreate a FreeBSD VM through Azure CLI on FreeBSD

首先需要通过以下命令在 FreeBSD 计算机上安装 Azure CLIFirst you need to install Azure CLI though following command on a FreeBSD machine.

curl -L https://aka.ms/InstallAzureCli | bash

如果 FreeBSD 计算机上未安装 bash,请在安装前运行以下命令。If bash is not installed on your FreeBSD machine, run following command before the installation. 

sudo pkg install bash

如果 FreeBSD 计算机上未安装 python,请在安装前运行以下命令。If python is not installed on your FreeBSD machine, run following commands before the installation. 

sudo pkg install python35
cd /usr/local/bin 
sudo rm /usr/local/bin/python 
sudo ln -s /usr/local/bin/python3.5 /usr/local/bin/python

安装期间,系统询问你 Modify profile to update your $PATH and enable shell/tab completion now? (Y/n)During the installation, you are asked Modify profile to update your $PATH and enable shell/tab completion now? (Y/n). 如果回答 y 并输入 /etc/rc.conf 作为 a path to an rc file to update,则可能会出现问题 ERROR: [Errno 13] Permission deniedIf you answer y and enter /etc/rc.conf as a path to an rc file to update, you may meet the problem ERROR: [Errno 13] Permission denied. 为了解决该问题,应针对文件 etc/rc.conf 向当前用户授予写入权限。To resolve this problem, you should grant the write right to current user against the file etc/rc.conf.

现在可登录 Azure 并创建 FreeBSD VM。Now you can sign in to Azure and create your FreeBSD VM. 以下是创建 FreeBSD 11.0 VM 的一个示例。Below is an example to create a FreeBSD 11.0 VM. 也可以为新创建的公共 IP 添加具有全局唯一 DNS 名称的 --public-ip-address-dns-name 参数。You can also add the parameter --public-ip-address-dns-name with a globally unique DNS name for a newly created Public IP.

Note

在 Azure China 中使用 Azure CLI 2.0 之前,请首先运行 az cloud set -n AzureChinaCloud 更改云环境。Before you can use Azure CLI 2.0 in Azure China, please run az cloud set -n AzureChinaCloud first to change the cloud environment. 如果要切换回全局 Azure,请再次运行 az cloud set -n AzureCloudIf you want to switch back to Global Azure, run az cloud set -n AzureCloud again.

az login 
az group create --name myResourceGroup --location chinaeast
az vm create --name myFreeBSD11 \
    --resource-group myResourceGroup \
    --image MicrosoftOSTC:FreeBSD:11.0:latest \
    --admin-username azureuser \
    --generate-ssh-keys

然后可通过上述部署输出中打印的 IP 地址登录到 FreeBSD VM。Then you can sign in to your FreeBSD VM through the ip address that printed in the output of above deployment.

ssh azureuser@xx.xx.xx.xx -i /etc/ssh/ssh_host_rsa_key

FreeBSD 的 VM 扩展VM extensions for FreeBSD

以下是 FreeBSD 中支持的 VM 扩展。Following are supported VM extensions in FreeBSD.

VMAccessVMAccess

VMAccess 扩展可以:The VMAccess extension can:

  • 重置原始的 sudo 用户的密码。Reset the password of the original sudo user.
  • 使用指定的密码创建新的 sudo 用户。Create a new sudo user with the password specified.
  • 使用给定的密钥设置公共主机密钥。Set the public host key with the key given.
  • 重置在 VM 预配期间提供的公共主机密钥(如果未提供主机密钥)。Reset the public host key provided during VM provisioning if the host key is not provided.
  • 打开 SSH 端口 (22) 并还原 sshd_config(如果 reset_ssh 设置为 true)。Open the SSH port (22) and restore the sshd_config if reset_ssh is set to true.
  • 删除现有用户。Remove the existing user.
  • 检查磁盘。Check disks.
  • 修复添加的磁盘。Repair an added disk.

CustomScriptCustomScript

CustomScript 扩展可以:The CustomScript extension can:

  • 从 Azure 存储或外部公共存储(例如 GitHub)下载自定义的脚本(如果已提供)。If provided, download the customized scripts from Azure Storage or external public storage (for example, GitHub).
  • 运行入口点脚本。Run the entry point script.
  • 支持内联命令。Support inline commands.
  • 在 shell 和 Python 脚本中自动进行 Windows 样式的换行符转换。Convert Windows-style newline in shell and Python scripts automatically.
  • 自动删除 shell 和 Python 脚本中的 BOM。Remove BOM in shell and Python scripts automatically.
  • 保护 CommandToExecute 中的敏感数据。Protect sensitive data in CommandToExecute.

Note

FreeBSD VM 目前仅支持 CustomScript 1.x 版。FreeBSD VM only supports CustomScript version 1.x by now.

身份验证:用户名、密码和 SSH 密钥Authentication: user names, passwords, and SSH keys

使用 Azure 门户创建 FreeBSD 虚拟机时,必须提供用户名、密码或 SSH 公钥。When you're creating a FreeBSD virtual machine by using the Azure portal, you must provide a user name, password, or SSH public key. 在 Azure 上部署 FreeBSD 虚拟机时,用户名必须与已经存在于虚拟机中的系统帐户 (UID <100) 的名称(例如“root”)相符。User names for deploying a FreeBSD virtual machine on Azure must not match names of system accounts (UID <100) already present in the virtual machine ("root", for example). 目前仅支持 RSA SSH 密钥。Currently, only the RSA SSH key is supported. 多行 SSH 密钥必须以 ---- BEGIN SSH2 PUBLIC KEY ---- 开头,以 ---- END SSH2 PUBLIC KEY ---- 结尾。A multiline SSH key must begin with ---- BEGIN SSH2 PUBLIC KEY ---- and end with ---- END SSH2 PUBLIC KEY ----.

获取超级用户特权Obtaining superuser privileges

在 Azure 上部署虚拟机实例的过程中指定的用户帐户是特权帐户。The user account that is specified during virtual machine instance deployment on Azure is a privileged account. sudo 包安装在已发布的 FreeBSD 映像中。The package of sudo was installed in the published FreeBSD image. 通过此用户帐户登录后,即可使用命令语法以 root 用户身份运行命令。After you're logged in through this user account, you can run commands as root by using the command syntax.

$ sudo <COMMAND>

可以选择使用 sudo -s获取 root shell。You can optionally obtain a root shell by using sudo -s.

已知问题Known issues

Azure VM 来宾代理 2.2.2 存在已知问题,此问题导致 Azure 上的 FreeBSD VM 预配失败。The Azure VM Guest Agent version 2.2.2 has a known issue that causes the provision failure for FreeBSD VM on Azure. Azure VM 来宾代理 2.2.3 及更高版本已修复此问题。The fix was captured by Azure VM Guest Agent version 2.2.3 and later releases.

后续步骤Next steps