关机,重启,注销
关机:
shutdown -h now #立刻关机重启
shutdown -h +1 #1分钟后关机
init 0
halt #立即停止系统,需要人工关闭电源
halt -p
poweroff #立即停止系统,并且关闭电源
重启:
reboot
shutdown -r now #工作中常用
shutdown -r +1 #一分钟后重启
init 6
注销:
logout
exit
ctrl+d
修改主机名
1.查看主机名
例如:
[root@lysc ~]# hostname
lysc
[root@lysc ~]# hostnamectl
Static hostname: lysc
Icon name: computer-vm
Chassis: vm
Machine ID: 20200914151302543507749550121287
Boot ID: 4aaac2a9f68342a3a56d3faa4acd84b9
Virtualization: kvm
Operating System: CentOS Linux 8 (Core)
CPE OS Name: cpe:/o:centos:centos:8
Kernel: Linux 4.18.0-193.14.2.el8_2.x86_64
Architecture: x86-64
[root@lysc ~]#
2.修改主机名
有临时修改和永久修改2种方式,都需要刷新重新加载,永久修改会修改文件,永久修改命令:
hostnamectl set-hostname 主机名
例如:
[root@minikube ~]# hostname
minikube
[root@minikube ~]# hostname ly
[root@minikube ~]# su - root
上一次登录:二 3月 9 20:31:32 CST 2021pts/0 上
[root@ly ~]# cat /etc/hostname
minikube #临时修改未改变文件
[root@ly ~]# hostnamectl set-hostname lysc
[root@ly ~]# su - root
上一次登录:二 3月 9 20:32:59 CST 2021pts/0 上
[root@lysc ~]# cat /etc/hostname
lysc #永久修改改变文件
时间同步
需要时间同步一般是装centos-8 比较新的版本,默认设置的时间同步服务器不好使。
1.本地搭建chrony服务器+所有客户端同步服务器时间
# 安装
yum install -y chrony
# 启动
systemctl start chronyd
# 注册成开机启动
systemctl enable chronyd
2.配置文件的修改
vim /etc/chrony.conf
# 使用pool.ntp.org项目中的公共服务器。以server开,理论上你想添加多少时间服务器都可以。
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
# 注释掉 server 0.centos.pool.ntp.org iburst
# 新增
server cn.ntp.org.cn iburst
server ntp.aliyun.com iburst
ntp服务器推荐:
server ntp.aliyun.com
server cn.pool.ntp.org
server cn.ntp.org.cn
server asia.pool.ntp.org
server time.asia.apple.com
server time.windows.com
server time.google.com
3.查看时间
# 查看
timedatectl
不一定需要这步
# 删除 localtime
rm /etc/localtime
# 从/usr/share/zoneinfo/中创建软连接以替换当前的时区信息
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# 再次查看系统时间
timedatectl