doc-exports/docs/as/umn/as_faq_0008.html
guoyanyan a80bb7d522 as_umn_0325
Reviewed-by: Pristromskaia, Margarita <margarita.pristromskaia@t-systems.com>
Co-authored-by: guoyanyan <guoyanyan3@huawei.com>
Co-committed-by: guoyanyan <guoyanyan3@huawei.com>
2023-04-13 12:10:58 +00:00

142 lines
7.6 KiB
HTML

<a name="as_faq_0008"></a><a name="as_faq_0008"></a>
<h1 class="topictitle1">How Do I Enable Automatic Initialization of EVS Disks on Instances that Have Been Added to an AS Group During Scaling Actions?</h1>
<div id="body42865624"><div class="section" id="as_faq_0008__section19634929"><h4 class="sectiontitle">Scenarios</h4><p id="as_faq_0008__p49563504">After an ECS instance is created, you need to manually initialize EVS disks attached to the instance before using them. If multiple instances are added to the AS group, you must initialize the EVS disks on each instance, which takes a while.</p>
<p id="as_faq_0008__p43418353">This section describes how to configure a script to enable automatic initialization of EVS disks, including disk partitioning and attachment of specified directories. The script can only be used to initialize one EVS disk.</p>
<p id="as_faq_0008__p55220864">This section uses CentOS 6.5 as an example. For how to configure automatic initialization of EVS disks on other OSs, see the relevant OS documentation.</p>
</div>
<div class="section" id="as_faq_0008__section42496641"><h4 class="sectiontitle">Procedure</h4><ol id="as_faq_0008__ol43705009"><li id="as_faq_0008__li57800765">Log in to the instance as user <strong id="as_faq_0008__b84235270619035">root</strong>.</li><li id="as_faq_0008__li50444842">Run a command to switch to the directory where the script will be stored:<p class="litext" id="as_faq_0008__p51350402"><a name="as_faq_0008__li50444842"></a><a name="li50444842"></a><strong id="as_faq_0008__b1945033573417">cd /</strong><em id="as_faq_0008__i842352697112241">script directory</em></p>
<p class="litext" id="as_faq_0008__p65741883">For example:</p>
<p class="litext" id="as_faq_0008__p54806039"><strong id="as_faq_0008__b23492305">cd /home</strong></p>
</li><li id="as_faq_0008__li10104154">Run the following command to create the script:<p class="litext" id="as_faq_0008__p23828523"><a name="as_faq_0008__li10104154"></a><a name="li10104154"></a><strong id="as_faq_0008__b1342153233712">vi </strong><em id="as_faq_0008__i30903095152739">script name</em></p>
<p class="litext" id="as_faq_0008__p51062193">For example:</p>
<p class="litext" id="as_faq_0008__p56906561"><strong id="as_faq_0008__b42397005">vi fdisk_mount.sh</strong></p>
</li><li id="as_faq_0008__li174541337430">Press <strong id="as_faq_0008__b842352706235544">i</strong> to enter editing mode.<p class="litext" id="as_faq_0008__p46028725">The following script is used as an example to show how to implement automatic initialization of one data disk:</p>
<pre class="screen" id="as_faq_0008__screen11605348">#!/bin/bash
bash_scripts_name=fdisk_mount.sh
ini_path=/home/fdisk.ini
disk=
size=
mount=
partition=
function get_disk_from_ini()
{
disk=`cat $ini_path|grep disk| awk -F '=' '{print $2}'`
if [ $disk = "" ]
then
echo "disk is null in file,exit"
exit
fi
result=`fdisk -l $disk | grep $disk`
if [ $result = 1 ]
then
echo "disk path does not exist in linux,exit"
exit
fi
}
function get_size()
{
size=`cat $ini_path| grep size|awk -F '=' '{print $2}'`
if [ $size = "" ]
then
echo "size is null,exit"
exit
fi
}
function make_fs_mount()
{
mkfs.ext4 -T largefile $partition
if [ $? -ne 0 ]
then
echo "mkfs disk failed,exit"
exit
fi
dir=`cat $ini_path|grep mount |awk -F '=' '{print $2}'`
if [ $dir = "" ]
then
echo "mount dir is null in file,exit"
exit
fi
if [ ! -d $dir ]
then
mkdir -p $dir
fi
mount $partition $dir
if [ $? -ne 0 ]
then
echo "mount disk failed,exit"
exit
fi
echo "$partition $dir ext3 defaults 0 0" &gt;&gt; /etc/fstab
}
function remove_rc()
{
cat /etc/rc.local | grep $bash_scripts_name
if [ $? ne 0 ]
then
sed -i '/'$bash_scripts_name'/d' /etc/rc.local
fi
}
################## start #######################
##1. Check whether the configuration file exists.
if [ ! -f $ini_path ]
then
echo "ini file not exist,exit"
exit
fi
##2. Obtain the device path for the specified disk from the configuration file.
get_disk_from_ini
##3. Obtain the size of the size partition from the configuration file.
get_size
##4. Partition the disk.
fdisk $disk &lt;&lt;EOF
n
p
1
1
$size
w
EOF
partition=`fdisk -l $disk 2&gt;/dev/null| grep "^/dev/[xsh].*d" | awk '{print $1}'`
##5. Format the partition and attach the partition to the specified directory.
make_fs_mount
##6. Change startup items to prevent re-execution of the scripts.
remove_rc
echo 'SUCESS'</pre>
</li><li id="as_faq_0008__li37339274">Press <strong id="as_faq_0008__b11451126152513">Esc</strong>, enter <strong id="as_faq_0008__b1847726172510">:wq</strong>, and press <strong id="as_faq_0008__b84942618256">Enter</strong> to save the changes and exit.</li><li id="as_faq_0008__li4582376">Run the following command to create the configuration file:<p class="litext" id="as_faq_0008__p41241385"><a name="as_faq_0008__li4582376"></a><a name="li4582376"></a><strong id="as_faq_0008__b35628150">vi fdisk.ini</strong></p>
</li><li id="as_faq_0008__li19254510114513">Press <strong id="as_faq_0008__b842352706235621">i</strong> to enter editing mode.<p class="litext" id="as_faq_0008__p52217894">The drive letter, size, and mount directory of the EVS disk are configured in the configuration file. You can change the settings based on the following displayed information.</p>
<pre class="screen" id="as_faq_0008__screen199004">disk=/dev/xdev
size=+100G
mount=/opt/test</pre>
</li><li id="as_faq_0008__li1791040">Press <strong id="as_faq_0008__b1242329112512">Esc</strong>, enter <strong id="as_faq_0008__b14243122942516">:wq</strong>, and press <strong id="as_faq_0008__b19244162915257">Enter</strong> to save the changes and exit.</li><li id="as_faq_0008__li10856542">Run the following command to open configuration file <strong id="as_faq_0008__b14934174818435">rc.local</strong>:<p class="litext" id="as_faq_0008__p30600018"><strong id="as_faq_0008__b6964713">vi /etc/rc.local</strong></p>
</li><li id="as_faq_0008__li62682418">Press <strong id="as_faq_0008__b14103832112513">i</strong> to add the following content to <strong id="as_faq_0008__b1810411324256">rc.local</strong>:<p class="litext" id="as_faq_0008__p27270856"><strong id="as_faq_0008__b44111115">/home/fdisk_mount.sh</strong></p>
<p class="litext" id="as_faq_0008__p61455716">After <strong id="as_faq_0008__b317118455215">rc.local</strong> is configured, the EVS disk initialization script will be automatically executed when the ECS starts.</p>
</li><li id="as_faq_0008__li16230532">Press <strong id="as_faq_0008__b1360063213257">Esc</strong>, enter <strong id="as_faq_0008__b76011732192520">:wq</strong>, and press <strong id="as_faq_0008__b12603832132520">Enter</strong> to save the changes and exit.</li><li id="as_faq_0008__li39604677">Create a private image using an ECS.</li><li id="as_faq_0008__li20897776">Create an AS configuration.<p class="litext" id="as_faq_0008__p53862263"><a name="as_faq_0008__li20897776"></a><a name="li20897776"></a>When you specify the AS configuration information, select the private image created in the preceding step and select an EVS disk.</p>
</li><li id="as_faq_0008__li14998321">Create an AS group.<p id="as_faq_0008__p767169"><a name="as_faq_0008__li14998321"></a><a name="li14998321"></a>When you configure the AS group, select the AS configuration created in the preceding step.</p>
<p id="as_faq_0008__p6904527">After the AS group is created, EVS disks of new instances added to this AS group in scaling actions will be automatically initialized.</p>
</li></ol>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="as_faq_1105.html">Others</a></div>
</div>
</div>