0

我创建了一个Azure file share并连接到它,我在azure控制台中给出了一个脚本,如下所示

sudo mkdir /mnt/Totalvm
if [ ! -d "/etc/smbcredentials" ]; then
sudo mkdir /etc/smbcredentials
fi
if [ ! -f "/etc/smbcredentials/Totalcontainerstorage.cred" ]; then
    sudo bash -c 'echo "username=Totalcontainerstorage" >> /etc/smbcredentials/Totalcontainerstorage.cred'
    sudo bash -c 'echo "password=WPt39LGSSagFVeWbsNJ8HuhTaoPa1aiAZsOR3pBXnrOGjXFWVZj2BqooibIXvqbtjwbn4TLC4j+gJhOAk798pQ==" >> /etc/smbcredentials/Totalcontainerstorage.cred'
fi
sudo chmod 600 /etc/smbcredentials/Totalcontainerstorage.cred

sudo bash -c 'echo "//Totalcontainerstorage.file.core.windows.net/Totalvm /mnt/Totalvm cifs nofail,vers=3.0,credentials=/etc/smbcredentials/Totalcontainerstorage.cred,dir_mode=0777,file_mode=0777,serverino" >> /etc/fstab'
sudo mount -t cifs //Totalcontainerstorage.file.core.windows.net/Totalvm /mnt/Totalvm -o vers=3.0,credentials=/etc/smbcredentials/Totalcontainerstorage.cred,dir_mode=0777,file_mode=0777,serverino

我想在中使用这个cloudinit脚本azure。我该怎么做,对此的任何帮助将不胜感激。

4

1 回答 1

1

cloud-init 用于虚拟机的创建时间。因此,您可以在通过 CLI 命令创建 VM 时使用它,如下所示:

az vm create \
    --resource-group myResourceGroupAutomate \
    --name myAutomatedVM \
    --image UbuntuLTS \
    --admin-username azureuser \
    --generate-ssh-keys \
    --custom-data cloud-init.txt

但这里有一个问题。cloud-init 脚本以“root”用户身份运行。所以你不需要使用该sudo模式。您可以像这样直接使用自定义用户数据格式:

$ cat mount_script.sh
#!/bin/bash
mkdir /mnt/Totalvm
if [ ! -d "/etc/smbcredentials" ]; then
mkdir /etc/smbcredentials
fi
if [ ! -f "/etc/smbcredentials/Totalcontainerstorage.cred" ]; then
    bash -c 'echo "username=Totalcontainerstorage" >> /etc/smbcredentials/Totalcontainerstorage.cred'
    bash -c 'echo "password=WPt39LGSSagFVeWbsNJ8HuhTaoPa1aiAZsOR3pBXnrOGjXFWVZj2BqooibIXvqbtjwbn4TLC4j+gJhOAk798pQ==" >> /etc/smbcredentials/Totalcontainerstorage.cred'
fi
chmod 600 /etc/smbcredentials/Totalcontainerstorage.cred

bash -c 'echo "//Totalcontainerstorage.file.core.windows.net/Totalvm /mnt/Totalvm cifs nofail,vers=3.0,credentials=/etc/smbcredentials/Totalcontainerstorage.cred,dir_mode=0777,file_mode=0777,serverino" >> /etc/fstab'
mount -t cifs //Totalcontainerstorage.file.core.windows.net/Totalvm /mnt/Totalvm -o vers=3.0,credentials=/etc/smbcredentials/Totalcontainerstorage.cred,dir_mode=0777,file_mode=0777,serverino

查看 cloud-init用户数据脚本

于 2020-08-24T02:06:04.597 回答