首先登陆linux服务器,将用户切换到root用户。

sudo -i

然后安装psmisc工具包,操作命令为:

yum install psmisc 

该工具包提供了fuser, killall, pstree, pstree.x11(→pstree)等功能,其中

fuser报告使用所给文件或文件系统的进程的进程ID(PID)。
killall通过进程名来终止进程,它发送消息到所有正在运行任意所给指令的进程。
oldfuser报告使用所给文件或文件系统的进程的进程ID(PID)。
pstree以目录树的形式显示所有正在运行的进程
pstree.x11同 pstree ,只是它在退出前要求确认

执行以下命令,查看磁盘分区情况。

fdisk -l 
aws linux服务器磁盘初始化、挂载、时间同步等操作插图

其中未格式化的磁盘为:/dev/nvme0n1

格式化磁盘

选择未格式化的磁盘:/dev/nvme0n1

fdisk /dev/nvme0n1

输入m可获得命令操作的帮助信息:

aws linux服务器磁盘初始化、挂载、时间同步等操作插图1

这里选择输入n,你的操作为添加一个新的分区

n   add a new partition

然后,一路回车采用默认值,当然也可根据需要进行设置。

aws linux服务器磁盘初始化、挂载、时间同步等操作插图2

最后,输入w保存退出。

卸载挂载

如果之前待挂载的目录上已经有挂载了,则先卸载其挂载。这里卸载/mnt上的挂载。

[root@ip ~]# umount /mnt
umount: /mnt:未挂载

很明显,这里没有挂载。

转换格式并挂载

这里先将磁盘转换了格式:

mkfs.xfs -f /dev/nvme0n1

然后将其挂载到/mnt上:

mount /dev/nvme0n1 /mnt

然后,输入以下命令再次验证:

df -h

发现已经成功挂载:

文件系统        容量  已用  可用 已用% 挂载点
/dev/nvme0n1   1000G   33M 1000G    1% /mnt

时区设置

时间同步,通过tzselect来设置时区:

[root@ip ~]# tzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent or ocean.
 1) Africa
 2) Americas
 3) Antarctica
 4) Arctic Ocean
 5) Asia
 6) Atlantic Ocean
 7) Australia
 8) Europe
 9) Indian Ocean
10) Pacific Ocean
11) none - I want to specify the time zone using the Posix TZ format.

依次选择(5)Asia–>选择(9)China–>选择1) Beijing Time。输入上面括号内的编号即可。

然后,输入1,选择yes:

The following information has been given:

    China
    Beijing Time

Therefore TZ='Asia/Shanghai' will be used.
Local time is now:    Wed Nov  6 14:57:53 CST 2019.
Universal Time is now:    Wed Nov  6 06:57:53 UTC 2019.
Is the above information OK?
1) Yes
2) No
You can make this change permanent for yourself by appending the line
    TZ='Asia/Shanghai'; export TZ
to the file '.profile' in your home directory; then log out and log in again.

Here is that TZ value again, this time on standard output so that you
can use the /bin/tzselect command in shell scripts:
Asia/Shanghai

然后执行,cp操作,将/etc/localtime设置为Shanghai。

sudo cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

输入date进行验证:

[centos@ip-172-31-36-133 ~]$ date
2019年 11月 06日 星期三 15:00:23 CST

至此,关于磁盘挂载和本地日期同步已经完成。

aws linux服务器磁盘初始化、挂载、时间同步等操作插图3


aws linux服务器磁盘初始化、挂载、时间同步等操作插图4

关注公众号:程序新视界,一个让你软实力、硬技术同步提升的平台

除非注明,否则均为程序新视界原创文章,转载必须以链接形式标明本文链接

本文链接:http://choupangxia.com/2019/11/06/linux-init/