Basic management and disk expansion of Alibaba Cloud ECS server
Article directory
- Basic management and disk expansion of Alibaba Cloud ECS server
1. Set the password of the ECS server
Click More -> Password/Key -> Reset Instance Password
Fill in the instance password and click Submit.
After resetting the password, we will be asked to restart the server.
2. Remotely connect to the ECS server through the Alibaba Cloud console
Click Remote Connection to connect to the server remotely using WorkBench.
Select the ECS instance to be remoted, and enter the server account and password to log in remotely.
At this point, the terminal is connected to the ECS, and the corresponding commands can be executed.
3. Bind the public IP to ECS and connect to the cloud server through Xshell
3.1. Create an elastic public IP
1) Search for the elastic public IP in the console, and enter the product management page.
2) Click to create an elastic public IP
3) Configure elastic public IP
If the product type is billed by volume, the region and region must select the region and region where the ECS is located. The bandwidth peak is directly full, and the traffic type is billed by usage.
4) Confirm the order information and click Activate Now
After the purchase is successful, you can see it in the elastic public network IP of the console.
3.2. Bind the public IP to the ESC instance
Click More -> Network and Security Group -> Bind Elastic IP
Select the purchased elastic public IP.
After the elastic IP binding is completed, you can see that an elastic address has been added to the IP address of the ECS, and the status of the elastic public IP is already allocated.
3.3. Use xshell to connect to the ECS cloud host
4. Connect to the server via VNC
VNC is equivalent to the operation interface in our VM virtual machine, which is used to debug the server. When the server has a problem, it can be operated here.
1) First, set the VNC password
2) Restart the ECS instance
The restart of ECS is very slow, about 10-15 minutes. You can also enter reboot in the terminal to restart.
3) Connect ECS via VNC
Select VNC login as the remote connection method.
Enter the VNC password.
successfully entered.
5. Prohibit ping of public IP
Find the ECS management page -> Security Group -> Find the list of security groups corresponding to ECS
Click Manual Add, the authorization policy is Deny, the priority is set, the protocol type is all ICMP, the setting range is -1/-1, and the authorization object is 0.0.0.0/0, which means that all hosts are prohibited from using the ICMP protocol to request hosts.
Protocol added successfully.
It is no longer possible to ping the public network address to protect the security of the intranet.
5. ECS cloud server disk expansion
In practice, the ECS cloud service requires a system disk and a data disk. The ECS server we just purchased does not have a data disk. We can purchase a cloud disk and mount it to the ECS server. When the data disk space of the ECS server is available When it is not enough, the disk capacity can also be flexibly expanded.
5.1. Purchase a cloud disk
1) Find the cloud disk on the ECS management interface -> create a cloud disk
2) Set the basic information and storage space of the cloud disk
Whether to mount, choose not to mount, and manually mount to the corresponding ECS server later.
The region and availability zone of the cloud disk must be consistent with ECS.
The payment method of cloud disk is set to pay-as-you-go.
Choose an efficient cloud disk for storage, with a space of 20GB.
Check the ECS Terms of Service for the cloud server.
3) Set the name information of the cloud disk
When we have many ECS instances and many cloud disks, in order to easily distinguish which ECS the cloud disk belongs to, we need to give the cloud disk a meaningful name.
The name is Web-01-data cloud disk, and the description information is the data disk of the Web-01 instance.
Put the cloud disk and ECS in the same resource group, and click Confirm Order.
4) Confirm the creation
5.2. Mount the cloud disk to ECS
1) Find the purchased cloud disk, click More -> Mount.
2) Select the corresponding ECS instance and execute the mount.
3) Successfully mounted to ECS.
5.3. Initialize a new cloud disk and mount it
The cloud disks in Alibaba Cloud are all vdx mounted to virtual machines, and all physical machines are sdx.
1.先将磁盘进行分区
[root@iZ2ze7rto8oqydzzemi1enZ ~]# fdisk /dev/vdb
Command (m for help): n
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-41943039, default 2048):
Command (m for help): w
[root@iZ2ze7rto8oqydzzemi1enZ ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 253:0 0 40G 0 disk
└─vda1 253:1 0 40G 0 part /
vdb 253:16 0 20G 0 disk
└─vdb1 253:17 0 20G 0 part
2.格式化分区
[root@iZ2ze7rto8oqydzzemi1enZ ~]# mkfs.xfs /dev/vdb1
3.将分区挂载到/data目录
[root@iZ2ze7rto8oqydzzemi1enZ ~]# mkdir /data
[root@iZ2ze7rto8oqydzzemi1enZ ~]# mount /dev/vdb1 /data
4.将分区与目录写入到开机自动挂载的文件中
[root@iZ2ze7rto8oqydzzemi1enZ ~]# vim /etc/fstab
/dev/vdb1 /data xfs defaults 0 0
5.4. Expansion of the existing cloud disk
1) Click More -> Cloud Disk Expansion.
2) Check online expansion, set the expanded capacity to 30GB, and finally check the expansion instructions, and confirm the expansion.
3) You can see that the cloud disk and the expansion are successful, and the capacity of the cloud disk mounted on the ECS is already the space after the expansion, but the partition has not changed.
5.5. Refresh the expanded cloud disk capacity in ECS
Steps: First unmount the cloud disk, then delete the partition of the existing cloud disk, re-partition the cloud disk, and finally refresh the disk.
Deleting a partition will not clear the data in the disk, the data is stored in the track, not the partition.
1.在/data目录生成数据,测试扩容前后数据是否会丢失
[root@iZ2ze7rto8oqydzzemi1enZ ~]# mkdir /data/{123.txt,456.txt}
2.查看磁盘的大小是否是扩容后的容量
[root@iZ2ze7rto8oqydzzemi1enZ ~]# fdisk -l /dev/vdb
Disk /dev/vdb: 32.2 GB, 32212254720 bytes, 62914560 sectors
#可以看到容量已经是扩容后的容量了,只是分区没有变。
3.将分区取消挂载
[root@iZ2ze7rto8oqydzzemi1enZ ~]# umount /data/
4.重新将/dev/vdb1进行分区,获取磁盘全部容量
[root@iZ2ze7rto8oqydzzemi1enZ ~]# fdisk /dev/vdb
Command (m for help): d
Command (m for help): n
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-62914559, default 2048):
Command (m for help): w
5.查看分区容量是否发生变化
[root@iZ2ze7rto8oqydzzemi1enZ ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 253:0 0 40G 0 disk
└─vda1 253:1 0 40G 0 part /
vdb 253:16 0 30G 0 disk
└─vdb1 253:17 0 30G 0 part
6.挂载分区
[root@iZ2ze7rto8oqydzzemi1enZ ~]# mount -a
7.刷新分区空间
[root@iZ2ze7rto8oqydzzemi1enZ ~]# xfs_growfs /data/
8.验证数据是否丢失
[root@iZ2ze7rto8oqydzzemi1enZ ~]# ll /data/
total 0
drwxr-xr-x 2 root root 6 Jan 13 15:04 123.txt
drwxr-xr-x 2 root root 6 Jan 13 15:04 456.txt