首页 > 其他 > 详细

24_开机流程,单用户,优化

时间:2020-11-30 15:35:27      阅读:27      评论:0      收藏:0      [点我收藏+]

开机启动流程

1. 按下电源
2. BIOS自检  
3. MBR引导  
4. 进入GRUB菜单   
5. 加载内核 Kernel
6. systemd      init进程
7. 读取运行级别   
[root@qls ~]# ll  /etc/systemd/system/default.target
lrwxrwxrwx 1 root root 37 Jul  6 02:16 /etc/systemd/system/default.target -> /lib/systemd/system/multi-user.target
[root@qls ~]# ll  /usr/lib/systemd/system/runlevel*.target
lrwxrwxrwx. 1 root root 15 Jul  6 02:14 /usr/lib/systemd/system/runlevel0.target -> poweroff.target
lrwxrwxrwx. 1 root root 13 Jul  6 02:14 /usr/lib/systemd/system/runlevel1.target -> rescue.target
lrwxrwxrwx. 1 root root 17 Jul  6 02:14 /usr/lib/systemd/system/runlevel2.target -> multi-user.target
lrwxrwxrwx. 1 root root 17 Jul  6 02:14 /usr/lib/systemd/system/runlevel3.target -> multi-user.target
lrwxrwxrwx. 1 root root 17 Jul  6 02:14 /usr/lib/systemd/system/runlevel4.target -> multi-user.target
lrwxrwxrwx. 1 root root 16 Jul  6 02:14 /usr/lib/systemd/system/runlevel5.target -> graphical.target
lrwxrwxrwx. 1 root root 13 Jul  6 02:14 /usr/lib/systemd/system/runlevel6.target -> reboot.target
8. 初始化系统 
[root@qls ~]# ll  /usr/lib/systemd/system/sysinit.target
-rw-r--r--. 1 root root 518 Oct 31  2018 /usr/lib/systemd/system/sysinit.target
9. 并行启动开机自启动的服务         串行启动  
10. 运行getty文件,显示登陆界面 
[root@qls ~]# ll  /usr/lib/systemd/system/getty.target 
-rw-r--r--. 1 root root 460 Oct 31  2018 /usr/lib/systemd/system/getty.target

Centos-6  和 Centos-7的区别
init管理进程		 systemd管理进程
串行启动服务			并行启动服务
启动效率慢,容易故障	 启动效率高,不容易出现故障 

系统运行级别

[root@qls ~]# ll  /usr/lib/systemd/system/runlevel*.target
lrwxrwxrwx. 1 root root 15 Jul  6 02:14 /usr/lib/systemd/system/runlevel0.target -> poweroff.target
lrwxrwxrwx. 1 root root 13 Jul  6 02:14 /usr/lib/systemd/system/runlevel1.target -> rescue.target
lrwxrwxrwx. 1 root root 17 Jul  6 02:14 /usr/lib/systemd/system/runlevel2.target -> multi-user.target
lrwxrwxrwx. 1 root root 17 Jul  6 02:14 /usr/lib/systemd/system/runlevel3.target -> multi-user.target
lrwxrwxrwx. 1 root root 17 Jul  6 02:14 /usr/lib/systemd/system/runlevel4.target -> multi-user.target
lrwxrwxrwx. 1 root root 16 Jul  6 02:14 /usr/lib/systemd/system/runlevel5.target -> graphical.target
lrwxrwxrwx. 1 root root 13 Jul  6 02:14 /usr/lib/systemd/system/runlevel6.target -> reboot.target

0		poweroff       #关机 
1		rescue		   #单用户模式  
2		multi-user		#多用户模式 
3		multi-user		#多用户模式
4		multi-user		#多用户模式 
5		graphical		#图形界面模式  桌面模式
6		reboot			#重启 

#如何查看系统运行级别 
Centos-6  
[root@qls ~]# runlevel 
N 3
[root@qls ~]# init  5
[root@qls ~]# runlevel 
3 5
[root@qls ~]# init  3

Centos-7
[root@qls ~]# systemctl  get-default
multi-user.target
#修改运行级别
[root@qls ~]# systemctl  set-default   graphical.target 
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/graphical.target.
[root@qls ~]# systemctl  get-default
graphical.target
[root@qls ~]# systemctl  set-default   multi-user.target 
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/multi-user.target.
[root@qls ~]# systemctl  get-default
multi-user.target

system介绍

systemd			system   daemon  
#主配置文件目录 
[root@qls ~]# ll  /etc/systemd/system/  -d
drwxr-xr-x. 12 root root 4096 Aug  5 09:05 /etc/systemd/system/
#系统服务配置文件 
[root@qls ~]# ll /usr/lib/systemd/system/  -d
drwxr-xr-x. 26 root root 12288 Jul 30 19:51 /usr/lib/systemd/system/
#程序,进程运行时产生的一些文件 
[root@qls ~]# ll  /run/systemd/system/  -d
drwxr-xr-x 5 root root 160 Aug  5 09:30 /run/systemd/system/

#启动 
[root@qls ~]# systemctl   start   nginx
#停止 
[root@qls ~]# systemctl   stop   nginx
#状态
[root@qls ~]# systemctl   status   nginx
#重启
[root@qls ~]# systemctl  restart   nginx
#平滑重启   
[root@qls ~]# systemctl  reload   nginx
#禁用某个服务 
[root@qls ~]# systemctl  mask   nginx
#解除禁用
[root@qls ~]# systemctl  unmask   nginx
#开机自启动
[root@qls ~]# systemctl  enable   nginx
#取消开机自启动
[root@qls ~]# systemctl  disable  nginx

status状态
active (running)		#运行 
Active: inactive (dead)	#不在运行
disabled				#开机不自启
enabled					#开机自启
failed					#失败

#显示当前运行级别下开机自启动的服务
[root@qls ~]# systemctl   list-unit-files 

system设置

#使用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

单用户模式

忘记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
修改运行级别  
exit
reboot

救援模式

#系统损坏了,数据很重要    需要把数据拷贝出来 
#MBR引导坏掉  
dd  if=/dev/zero  of=/dev/sda  bs=1  count=446
#修复MBR 
grub2-install   /dev/sda   
grub2-mkconfig   -o   /boot/grub2/grub.cfg

网卡命名规则

biosdevname=0
net.ifnames=1    设置为0  
规则1:如果Firmware或者BIOS提供的设备索引信息可用就用此命名。比如eno1。否则使用规则2
规则2:如果Firmware或Bios的PCI-E扩展插槽可用就用此命名。比如ens1,否则使用规则3
规则3:如果硬件接口的位置信息可用就用此命名。比如enp2s0
规则4:根据MAC地址命名,比如enx7d3e9f。默认不开启。
规则5:上述均不可用时回归传统命名方式
上面的所有命名规则需要依赖于一个安装包:biosdevname
#命令行修改网卡命名规则
mv /etc/sysconfig/network-scripts/ifcfg-ens33   /etc/sysconfig/network-scripts/ifcfg-eth0
NAME=ens33
DEVICE=ens33
修改 
NAME=eth0
DEVICE=eth0

grub2-mkconfig   -o  /boot/grub2/grub.cfg
reboot

系统优化

[root@qls ~]# ifconfig   eth1   172.16.1.100/24
[root@qls ~]# cp  /etc/sysconfig/network-scripts/ifcfg-eth0  /etc/sysconfig/network-scripts/ifcfg-eth1
[root@qls ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
TYPE=Ethernet
BOOTPROTO=none
NAME=eth1
DEVICE=eth1
ONBOOT=yes
IPADDR=172.16.1.100
PREFIX=24
#更新源
[root@qls ~]# rm -rf /etc/yum.repos.d/*
[root@qls ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
[root@qls ~]# curl  -o   /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@qls ~]# ll  /etc/yum.repos.d/
total 8
-rw-r--r--. 1 root root 2523 Aug  5 20:09 CentOS-Base.repo
-rw-r--r--. 1 root root  664 Aug  5 20:09 epel.repo
#关闭firewalld及selinux
[root@qls ~]# systemctl  stop firewalld
[root@qls ~]# systemctl  disable  firewalld
[root@qls ~]# setenforce  0
[root@qls ~]# vi  /etc/sysconfig/selinux 
[root@qls ~]# grep  ‘SELINUX‘  /etc/sysconfig/selinux
# SELINUX= can take one of these three values:
SELINUX=disabled
#关闭NetworkManager网络
[root@qls ~]# systemctl   stop NetworkManager
[root@qls ~]# systemctl   disable   NetworkManager
#同步时间
[root@qls ~]# crontab -l
* * * * *  /usr/bin/ntpdate  ntp.aliyun.com  &> /dev/null
#配置文件介绍
<domain> <type>  <item>  <value>
<domain>表示要限制的用户
<type>设定类型
<item>表示可选的资源
<value>表示要限制的值
#加大文件描述符
[root@qls ~]# echo ‘*               -       nofile          65535 ‘ >>/etc/security/limits.conf 
#检查结果
[root@qls ~]# tail -1 /etc/security/limits.conf

24_开机流程,单用户,优化

原文:https://www.cnblogs.com/future1/p/14060607.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!