#使用system进行管理关机重启操作 [root@qls ~]# systemctl reboot[root@qls ~]# systemctl poweroff #如何设置主机名[root@qls ~]# hostname
qls
[root@qls ~]# hostnamectl
Static hostname: qls
Icon name: computer-vm
Chassis: vm
Machine ID: 6b11e94f1fe04eb89579c1c41f6f5307
Boot ID: 783be43c5a44420ead4bd26792a6d22c
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-957.el7.x86_64
Architecture: x86-64
[root@qls ~]# hostnamectl set-hostname web01[root@qls ~]# logout
Connection closing...Socket close.
Connection closed by foreign host.
Disconnected from remote host(虚拟机-10.0.0.100) at 09:54:12.
Type `help' to learn how to use Xshell prompt.
[C:\~]$
Connecting to 10.0.0.100:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
Last login: Wed Aug 5 17:51:59 2020 from 10.0.0.1
[root@web01 ~]#
[root@web01 ~]# cat /etc/hostname
web01
Centos-6修改 临时生效
[root@web01 ~]# hostname qls
[root@web01 ~]# logout
Connection closing...Socket close.
Connection closed by foreign host.
Disconnected from remote host(虚拟机-10.0.0.100) at 09:55:10.
Type `help' to learn how to use Xshell prompt.
[C:\~]$
Connecting to 10.0.0.100:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
Last login: Wed Aug 5 09:54:16 2020 from 10.0.0.1
[root@qls ~]# cat /etc/hostname
web01
#如何修改字符集
[root@qls ~]# echo$LANG
en_US.UTF-8
[root@qls ~]# localectl set-locale LANG=zh_CN.UTF-8
[root@qls ~]# logout
Connection closing...Socket close.
Connection closed by foreign host.
Disconnected from remote host(虚拟机-10.0.0.100) at 09:57:21.
Type `help' to learn how to use Xshell prompt.
[C:\~]$
Connecting to 10.0.0.100:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
Last login: Wed Aug 5 09:55:13 2020 from 10.0.0.1
[root@qls ~]# [root@qls ~]# cat /etc/locale.conf
LANG=zh_CN.UTF-8
[root@qls ~]# yum install -y sl
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
软件包 sl-5.02-1.el7.x86_64 已安装并且是最新版本
无须任何处理
#临时修改变量 [root@qls ~]# export LANG=en_US.UTF-8[root@qls ~]# echo $LANG
en_US.UTF-8
#系统日志管理[root@qls ~]# journalctl -xe #查看当前服务的日志 [root@qls ~]# tail /var/log/messages
Aug 5 10:01:32 qls systemd: Stopped The nginx HTTP and reverse proxy server.
Aug 5 10:01:32 qls systemd: Starting The nginx HTTP and reverse proxy server...
Aug 5 10:01:32 qls nginx: nginx: [emerg] unknown directive "isten"in /etc/nginx/nginx.conf:39
Aug 5 10:01:32 qls nginx: nginx: configuration file /etc/nginx/nginx.conf test failed
Aug 5 10:01:32 qls systemd: nginx.service: control process exited, code=exited status=1
Aug 5 10:01:32 qls systemd: Failed to start The nginx HTTP and reverse proxy server.
Aug 5 10:01:32 qls systemd: Unit nginx.service entered failed state.
Aug 5 10:01:32 qls systemd: nginx.service failed.
Aug 5 10:02:01 qls systemd: Started Session 19 of user root.
Aug 5 10:03:01 qls systemd: Started Session 20 of user root.
#查看日志的最后20行内容[root@qls ~]# journalctl -n 20#实时查看日志的输出[root@qls ~]# journalctl -f#显示日志的级别日志[root@qls ~]# journalctl -p
alert crit debug emerg err info notice warning
[root@qls ~]# journalctl -p err
-- Logs begin at Wed 2020-08-05 17:51:37 CST, end at Wed 2020-08-05 10:05:01 CST. --
Aug 05 17:51:41 qls kernel: sd 2:0:0:0: [sda] Assuming drive cache: write through
Aug 05 17:51:41 qls kernel: sd 2:0:1:0: [sdb] Assuming drive cache: write through
Aug 05 17:51:41 qls kernel: sd 2:0:2:0: [sdc] Assuming drive cache: write through
Aug 05 17:51:44 qls kernel: piix4_smbus 0000:00:07.3: SMBus Host Controller not enabled!
Aug 05 09:54:13 web01 sshd[7162]: error: Received disconnect from 10.0.0.1 port 50011:0:
Aug 05 09:55:11 qls sshd[7333]: error: Received disconnect from 10.0.0.1 port 50033:0:
Aug 05 09:57:22 qls sshd[7369]: error: Received disconnect from 10.0.0.1 port 50041:0:
Aug 05 09:59:29 qls sshd[7419]: error: Received disconnect from 10.0.0.1 port 50067:0:
Aug 05 10:00:51 qls sshd[7473]: error: Received disconnect from 10.0.0.1 port 50097:0:
Aug 05 10:01:32 qls systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
#只查看某个服务的日志 [root@qls ~]# journalctl -u sshd
-- Logs begin at Wed 2020-08-05 17:51:37 CST, end at Wed 2020-08-05 10:06:01 CST. --
Aug 05 17:51:56 qls systemd[1]: Starting OpenSSH server daemon...
Aug 05 17:51:56 qls sshd[6981]: Server listening on 0.0.0.0 port 22.
Aug 05 17:51:56 qls sshd[6981]: Server listening on :: port 22.
Aug 05 17:51:56 qls systemd[1]: Started OpenSSH server daemon.
Aug 05 17:51:59 qls sshd[7162]: Accepted password for root from 10.0.0.1 port 50011 ssh2
Aug 05 09:54:16 web01 sshd[7333]: Accepted password for root from 10.0.0.1 port 50033 ssh2
Aug 05 09:55:12 qls sshd[7369]: Accepted password for root from 10.0.0.1 port 50041 ssh2
Aug 05 09:57:26 qls sshd[7419]: Accepted password for root from 10.0.0.1 port 50067 ssh2
Aug 05 09:59:31 qls sshd[7473]: Accepted password for root from 10.0.0.1 port 50097 ssh2
Aug 05 10:00:52 qls sshd[7525]: Accepted password for root from 10.0.0.1 port 50111 ssh2
5. 单用户模式
忘记root密码
开机在grub界面输入 e
在linux16开头的行的最后面输入 init=/bin/bash enforcing=0
按 ctrl键 + x
重新挂载根分区 mount -o rw,remount /
修改密码
重启 exec /sbin/init
#运行级别被设置为重启[root@web01 ~]# systemctl set-default reboot.target
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/reboot.target.
[root@web01 ~]# systemctl get-default
reboot.target
开机在grub界面输入 e
在linux16开头的行的最后面输入 rd.break
按 ctrl键 + x
重新挂载根分区 mount -o rw,remount /sysroot
赋予权限 chroot /sysroot
修改运行级别
exitreboot