Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

fifty-seven。 Create a custom CentOS image and upload to Azure to create a virtual machine (21V)

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

To create a virtual machine on Azure is generally to use the operating system image made in the market, but sometimes for the special requirements of some business systems, some special versions of the system image are not available in the market. For example, I need to use CentOS6.4 here, but there is no one in the market, so I need to make an image of CentOS6.4 and upload it to Azure for future use. Before you make it, you need to understand some of Azure's limitations on custom images:

Azure does not support VHDX format, only fixed size VHD is supported.

When installing Linux systems, it is recommended that you use standard partitions instead of LVM (usually the default for many installations). This avoids LVM name conflicts with the clone VM, especially if you need to connect the OS disk to another similar VM for troubleshooting.

The kernel needs to support mounting the UDF file system.

Linux kernel versions lower than 2.6.37 do not support NUMA on Hyper-V with larger VM sizes

Do not configure swap partitions on the operating system disk.

All VHD on Azure must have virtual resized to 1MB. When converting from raw disk to VHD, you must ensure that the original disk size is a multiple of 1MB before conversion.

According to the above requirements, I will make an image of CentOS6.4. First, I will create a virtual machine of CentOS64 on Hyper-V.

The virtual disk will be created later, because VHDX is created by default, but the virtual disk of VHD is needed here.

After creating the virtual machine, set up the virtual machine, and click add hard disk drive.

New, next step

Select VHD, next step

Select fixed size

Set the name and save location of the VHD

Set the size, of course, only the system disk is needed here.

Hang the ISO on CentOS6.4, and then start the virtual machine

Skip

NEXT

Next

Next

Next

Yes

Configure the network card, edit and check the automatic connection, and Next after application

Select Shanghai time zone and uncheck UTC

Set root password

Select create Custom layout, Next

Create a standard partition

Use full size without creating swap partition

Next step

Yes

Formatting

Write changes to disk

Next step

Next step

Start the installation and wait for the installation to complete

Restart

Restart the login, and then look at the kernel first.

+ + optional steps + +

Note: if you upgrade the kernel, you will upgrade the CentOS system version number, for example, the latest CentOS6.4 upgrade will become CentOS6.10.

Linux kernel versions with kernel lower than 2.6.37 do not support NUMA on Hyper-V with larger VM size, so the kernel needs to be upgraded.

Upgrade network security services

Yum update nss

Import public key

Rpm-- import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

First, go to the following URL, http://elrepo.org/tiki/tiki-index.php.

Select the ELRepo to install

Yum install https://www.elrepo.org/elrepo-release-6-8.el6.elrepo.noarch.rpm

Install kernel-lt (lt=long-term)

Yum-enablerepo=elrepo-kernel install kernel-lt-y

Edit the grub.conf file to modify the Grub boot sequence

Vim / etc/grub.conf

Finally restart the system

Shutdown-r now

After the kernel upgrade, check the kernel version again

+ + optional steps + +

In CentOS 6, NetworkManager may interfere with Azure Linux agents. Run the following command to uninstall the package (I don't have this in the way I install it here):

Sudo rpm-e-nodeps NetworkManager

Check whether the / etc/sysconfig/network file is as follows: vim / etc/sysconfig/network

Check whether the / etc/sysconfig/network-scripts/ifcfg-eth0 file is as follows: vim / etc/sysconfig/network-scripts/ifcfg-eth0

Modify udev rules to avoid generating static rules for Ethernet interfaces. These rules can cause problems when cloning a virtual machine in Azure or Hyper-V:

# sudo ln-s / dev/null / etc/udev/rules.d/75-persistent-net-generator.rules

# sudo rm-f / etc/udev/rules.d/70-persistent-net.rules

Ensure that the network service starts at boot time by running the following command

# sudo chkconfig network on

If you want to use an OpenLogic image hosted by the Azure data center, create a new CentOS-Azure.repo file in the / etc/yum.repos.d/ directory

The contents of the file are as follows, including the [openlogic] repository of other packages such as Azure Linux Agent:

# CentOS-Azure.repo

#

# The mirror system uses the connecting IP address of the client and the

# update status of each mirror to pick mirrors that are updated to and

# geographically close to the client. You should use this for CentOS updates

# unless you are manually picking other mirrors.

#

# If the mirrorlist= does not work for you, as a fall back you can try the

# remarked out baseurl= line instead.

#

#

[base]

Name=CentOS-$releasever-Base

Baseurl= http://olcentchan.chinacloudapp.cn/centos/$releasever/os/$basearch/

Gpgcheck=1

Gpgkey= file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

# released updates

[updates]

Name=CentOS-$releasever-Updates

Baseurl= http://olcentchan.chinacloudapp.cn/centos/$releasever/updates/$basearch/

Gpgcheck=1

Gpgkey= file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

# additional packages that may be useful

[extras]

Name=CentOS-$releasever-Extras

Baseurl= http://olcentchan.chinacloudapp.cn/centos/$releasever/extras/$basearch/

Gpgcheck=1

Gpgkey= file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

# additional packages that extend functionality of existing packages

[centosplus]

Name=CentOS-$releasever-Plus

Baseurl= http://olcentchan.chinacloudapp.cn/centos/$releasever/centosplus/$basearch/

Gpgcheck=1

Enabled=0

Gpgkey= file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

# contrib-packages by Centos Users

[contrib]

Name=CentOS-$releasever-Contrib

Baseurl= http://olcentchan.chinacloudapp.cn/centos/$releasever/contrib/$basearch/

Gpgcheck=1

Enabled=0

Gpgkey= file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

Add the following line to / etc/yum.conf

Http_caching=packages

Run the following command to clear the current yum metadata and update the system with the latest package

# yum clean all

It is recommended that all packages be updated to the latest version unless you want to create an image for the older version of CentOS

# sudo yum-y update

Restart the system after running this command

Shutdown-r now

Install the driver for Linux Integration Services (LIS) (required for CentOS 6.3 and earlier and optional for later)

# sudo rpm-e hypervkvpd # # (an error may be returned if there is no installation, it doesn't matter)

# sudo yum install-y microsoft-hyper-v

Install the Azure Linux agent and dependencies (if the NetworkManager and NetworkManager-gnome packages are not removed, they will be removed when the WALinuxAgent package is installed)

# sudo yum install python-pyasn1 WALinuxAgent

Modify the kernel boot line in the grub configuration to include the other kernel parameters of Azure (will ensure that all console messages are sent to the first serial port to assist Azure support personnel to debug the problem), open / boot/grub/menu.lst

Vim / boot/grub/menu.lst

Console=ttyS0 earlyprintk=ttyS0 rootdelay=300

CentOS 6.5 or earlier must also set the kernel parameter numa=off

Because of bug in Linux kernel versions earlier than 2.6.37, large VM does not support inconsistent memory access (NUMA). Systems running custom kernels earlier than 2.6.37 or RHEL-based kernels earlier than 2.6.32-504 must set the startup parameter numa=off on the kernel command line in grub.conf. For more information, see Red Hat KB 436883.

If the following parameters are found in this file, it is recommended to delete them.

Rhgb quiet crashkernel=auto

Then check whether the kernel supports mounting the UDF file system. Here, it looks like it does. OK is fine.

Permanently shut down SELinux (this takes effect after the server is restarted)

Sed-I's Union SELINUXPRENTENTFORCING sed'/ etc/selinux/config

Permanently shut down the Linux Firewall

Chkconfig iptables off

Then install waagent (Microsoft Azure Linux Agent) first open https://github.com/Azure/WALinuxAgent/releases and select the latest version

Cd / tmp/

Yum install-y wget

Wget https://github.com/Azure/WALinuxAgent/archive/v2.2.38.tar.gz

Tar-xzf v2.2.38.tar.gz

Ls-l

Cd WALinuxAgent-2.2.38

Ls-l

Then install pip

Sudo yum install python-pip

Python package setuptools is a prerequisite for installing Azure Linux Agent

Yum install-y python-setuptools

Continue to install Azure Linux Agent after installing python package setuptools

Sudo python setup.py install

View waagent running status

Service waagent restart

View waagent version

Waagent-version

Create a new non-root account, such as zjunsen

# useradd zjunsen

# passwd zjunsen

Enter a new password (it is recommended that the password be set to meet the complexity requirements for Azure virtual machine creation)

Enter the new password again

Let zjunsen join the root group

# usermod-G root zjunsen

# visudo

Add zjunsen to execute sudo

Finally, run the following command to set up the generalization of the virtual machine. You need to modify the network configuration before setting it. Why do you want to do it before the generalization before shutdown? you are afraid that the network card cannot be found.

Sudo vim / etc/sysconfig/network-scripts/ifcfg-eth0

Edit "/ etc/resolv.conf" to add a DNS server on Azure

Sudo vim / etc/resolv.conf

Modify as follows

Search pfa1hgkf53jujovxud25btaopc.shax.internal.chinacloudapp.cn

Nameserver 168.63.129.16

In addition, you can generalize CentOS. General generalization uses waagent-deprovision+user or waagent-deprovision.

Note: the + user parameter also deletes the last preconfigured user account (the deprovision parameter disables the root account); the user accounts of other newly created root groups are still available

The execution here is as follows:

# sudo waagent-deprovision+user-force

# export HISTSIZE=0

# sudo shutdown-h 0

Perform init 0 or shutdown-h 0 shutdown, the virtual machine can be seen in Hyper-V Manager, and CentOS6.4 VHD is ready to upload to Azure.

Next, switch to the Azure portal and create a resource group

Next, create a storage account in this resource group

Once created, you will see that the storage account has two sets of 25-character access keys. Here I only need to use the KEY1 key.

Next, create the container

Add Container

Set up special purpose

Next, upload VHD to the Azure container. Because the VHD file is relatively large, Azcopy is used here, because Azcopy can support resuming upload from breakpoints.

Azcopy download address: https://docs.azure.cn/zh-cn/storage/common/storage-use-azcopy?toc=%2fstorage%2ftables%2ftoc.json

Using Azcopy to operate Azure storage, you can refer to https://docs.azure.cn/zh-cn/articles/azure-operations-guide/storage/aog-storage-how-to-use-azcopy

By default, Azcopy is installed in C:\ Program Files (x86)\ Microsoft SDKs\ Azure,32-bit Windows as C:\ Program Files\ Microsoft SDKs\ Azure

Use Azcopy to upload local files to the container under the corresponding storage account

The format of the command is: AzCopy / Source:C:\ myfolder / Dest: https://myaccount.blob.core.chinacloudapi.cn/mycontainer / DestKey:key / Pattern:abc.txt

The command executed here is: (the highlighted part is modified according to your actual situation) (the storage account does not open the shared access signature (the new storage account is not opened by default))

Note: when / Source is a blob container or blob virtual directory, AzCopy uses case-sensitive matching, while in all other cases case-insensitive matching is used.

PS C:\ Program Files (x86)\ Microsoft SDKs\ Azure\ AzCopy >.\ AzCopy.exe / Source:D:\ Hyper-V\ CentOS64\ Cent64OS.vhd / Dest: https://vmosimage.blob.core.chinacloudapi.cn/mydisk/CentOS64.vhd / DestKey:/eAKlZpIy7sWO0AT3Hi4DV895mwHubHDqe+wbz0vJnbyes0f9oB4pCdKELZ3yvrLfjrqGjJwEYzpiioCO0EiGQ== / BlobType:page

CentOS64.vhd in red font is the saved name uploaded to the Azure container; finally, be sure to add / BlobType:page or upload it as block blob, not page blob for vhd

Execution waits for upload to be completed, because breakpoint continuation is supported. If you are interrupted, execute this command again and continue upload today. (if you are halfway through upload and suddenly find that you want to modify the content of the source vhd, don't forget to select No to start a new upload when you re-execute the command upload after universal settings, instead of before Yes breakpoint.)

You can also use Windows Admin Center to check the upload status.

Upload complete

You can also see the uploaded vhd file on the Azure portal

Next, you can create a custom image and select the image among all services.

Click add

Set the name, select OS type is Linux, and select the location of the custom image you just uploaded

Choose whether the account type is standard HDD, standard SSD or advanced SSD. Of course, standard HDD can only create virtual machine models without SSD, and standard SSD can create virtual machine models with SSD disks, such as D4s v2.

After the image is created, this is the template image. Click it to go in.

Click create VM to create multiple system services based on this CentOS6.4 that provide different businesses based on this template image.

Set the name, size, virtual network, etc., of the virtual machine, and then create it. (it is recommended to use the account name and password of the new local account (here is zjunsen) when creating the VM. After success, you can see the public network IP and private network IP.

Then open port 22 to the inbound network security group to connect.

At this point, I'll show you how to customize the Linux image and upload it to create a virtual machine based on that image.

PS: one of the imperfections in the whole process is that the VM deployment will last for half an hour when using the image to create the deployment. Finally, the deployment fails without generalization, but the actual virtual machine has been created and ready for connection. Personally, I don't think it has much impact, just for reference.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report