linux 07系统重要目录
1、系统目录
重要的这几个
/etc : 系统配置目录
/bin -> /usr/bin : 保存常用命令的目录
/root : 超级管理员目录
/home : 普通管理员目录
/usr : 存放应用程序的目录
/boot : 存放系统启动文件
/dev : 存放硬件相关信息
/proc : 存放系统运行的信息
/mnt : 临时挂载目录
/opt : 相当于下载目录
/usr/local : 安装第三方软件的目录
/tmp : 临时文件
/var : 存放日志的目录
/run : 存放应用程序运行时产生的临时文件
命令
lsblk 查看磁盘分区信息
df -h 查看挂载
fdisk 创建分区
free -m 查看内存
lscpu 查看cpu
mount 挂载
umount 取消挂载
ifdown 关闭网卡
ifup 开启网卡
systemctl restart network 重启网卡
系统重要目录
1 、查看当前系统ip
ip addr = > ip a
ifconfig
nmtui :NetworkManager is not running.
lo 第一个网卡为回还网络,代表的自己
ipconfig : 查看windows主机的网卡
2 、网卡配置文件
/ etc/ sysconfig/ network- scripts/ ifcfg- [ 网卡的名称]
[ root@localhost ~ ]
[ root@localhost ~ ]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TYPE= Ethernet
PROXY_METHOD= none
BROWSER_ONLY= no
BOOTPROTO= none
DEFROUTE= yes
IPV4_FAILURE_FATAL= no
IPV6INIT= yes
IPV6_AUTOCONF= yes
IPV6_DEFROUTE= yes
IPV6_FAILURE_FATAL= no
IPV6_ADDR_GEN_MODE= stable- privacy
NAME= eth0
UUID= 1fb1523f - a6ce- 4689 - 886d - ed22c115218b
DEVICE= eth0
ONBOOT= yes
IPADDR= 192.168 .15 .222 ip可以在这修改
PREFIX= 24
GATEWAY= 192.168 .15 .2 网关
DNS1= 114.114 .114 .114 DNS
IPV6_PRIVACY= no
3 、判断网络是否通畅
ping 192.168 .15 .100
ping www. baidu. com
4 、管理网络
两个同时开启上不了网,只能开启一个,先关闭一个 一般关闭networkmanager
network
NetWorkManager ( 关闭 )
虚拟网络编辑器 查看是否在一个网段
5 、公网DNS,解析配置文件
linux里面的DNS :/ etc/ hosts
都是通过公网DNS解析,本地DNS不会放很多网站的解析
cat / etc/ resolv. conf 查看DNS
114.114 .114 .114 中国电信
223.5 .5 .5 阿里云
8.8 .8 .8 谷歌
本机相关配置文件:/ etc/ resolv. conf :临时修改 重启网卡就没了
[ root@localhost ~ ]
nameserver 114.114 .114 .114
search localdomain
永久修改DNS信息需要网卡配置文件
[ root@localhost ~ ] $ vim / etc/ sysconfig/ network- scripts/ ifcfg- eth0
可以加多个dns dns1= 114.114 .114 .114 dns2= 8.8 .8 .8
[ root@localhost ~ ] $ cat / etc/ resolv. conf
nameserver 223.5 .5 .5
search localdomain
[ root@localhost ~ ] $ systemctl restart network 重启网卡
[ root@localhost ~ ] $ cat / etc/ resolv. conf 用于设置DNS服务器的IP地址公网的
search localdomain
nameserver 114.114 .114 .114
nameserver 8.8 .8 .8
主机名
1 . 主机名:主机的名称,改了主机名不需要ip了
[ root@localhost ~ ]
PING localhost ( 127.0 .0 .1 ) 56 ( 84 ) bytes of data.
64 bytes from localhost ( 127.0 .0 .1 ) : icmp_seq= 1 ttl= 64 time= 0.010 ms
ip是127.0 .0 .1 本机地址
在这里面配置的localhost
[ root@localhost ~ ]
127.0 .0 .1 localhost localhost. localdomain localhost4 localhost4. localdomain4
: : 1 localhost localhost. localdomain localhost6 localhost6. localdomain6
修改主机名 :hostnamectl set - hostname [ 主机名] 新开个窗口 立即生效
还可以这么改: vim / etc/ hostname 重启 重启后生效
修改主机名是为了 :区分主机,大规模集群中方便连接
通过网络传输文件 :scp
格式: scp [ 当前主机的文件路径] [ 传输到的系统的用户名] @[ ip或者主机名] : [ 路径]
scp 12138 root @python : / root/
ansible : 主机清单 - - > 主机组 以后会学
磁盘挂载(临时挂载,永久挂载)
/ etc/ fstab 文件是配置磁盘挂载的配置文件
1 、永久挂载
第一种方式:(做快照!!!)
将挂载信息配置到/ etc/ fstab中。
/ dev/ mapper/ centos- root / xfs defaults 0 0
分区的路径(sdb1,sdb2),挂载的目录的路径,挂载的分区文件系统的类型 权限 是否备份,是否检测
/ dev/ sdb1 / mnt xfs defaults 0 0
注:当挂载信息出现问题时,linux主机将无法正常开机
在添加完配置信息之后,一定要检测语法是否正确,记住检查
第二种方式:
在开机自启动脚本中增加挂载命令
1 、添加挂载命令到:/ etc/ rc. local
mount / dev/ sdb1 / mnt
2 、添加可执行权限
[ root@python ~ ] $ chmod + x / etc/ rc. d/ rc. local
3 、重启
reboot
使用单用户模式更改root密码
忘记root密码,进入单用户模式,安全的无网络
init 六种模式
0 关机 poweroff
1 单用户模式 rescue
2 多用户模式 没有NFS 也就是没有网络 multi- user
3 完全多用户模式 multi- user
4 . 未使用
5 . 图形界面模式 graphical
6 . 重启 reboot
执行runlevel 查看在那个级别
[ root@linux ~ ]
N 3
1 、关闭selinux(必须是永久关闭)
2 、重启
3 、在启动界面上,按e键,进入单用户模式
4 、在包含linux16这一行, 将ro修改为rw,并且在其后面增加 init= / sysroot/ bin / sh ( 让单用户模式默认进入sh命令)
5 、按Ctrl + x 键,重新引导系统
6 、执行 chroot / sysroot/ 切换到原来的系统中
7 、修改root密码
passwd [ 指定需要修改密码的用户]
8 、使密码生效
创建一个文件
touch / . autorelabel
9 、重启
在命令行中修改密码
[ root@python ~ ] $ passwd root
Changing password for user root.
New password:
BAD PASSWORD: The password is a palindrome
Retype new password:
passwd: all authentication tokens updated successfully.
查看当前系统运行模式
runlevel : 数字模式
[ root@python ~ ] $ systemctl get- default : 查看的是全称
multi- user. target
systemctl set - default [ 模式名称] : 修改系统运行模式
[ root@python ~ ] $ systemctl set - default graphical 上面有级别的英文
变量加载文件
/ etc/ profile 国法 文件 : 初始化一些系统变量 最重要的
/ etc/ bashrc 国法 文件
/ etc/ profile. d/ 目录
~ / . bashrc 家法 文件
~ / . bash_profile 家法 文件
su 切换用户相当于换一个用户, 切换用户不切换目录
切换用户立即生效 放在下面这两个文件任选其一 全局立即生效放在/ etc/ bashrc
: ~ / . bashrc > / etc/ bashrc
su - 切换用户相当于重新登录一个用户 切换目录
/ etc/ profile
~ / . bash_profile
~ / . bashrc
/ etc/ bashrc
exit退出登录
开机提示
/ etc/ motd : 在登录之后显示
/ etc/ issue :在登录之前显示
文件里\S
文件里Kernel \r on an \m
实际登录这样显示
实际:Centos linux(core)
文件里\s
文件里 Kernel 3.10 - 0 - 1160.e17 . x86_64 on an x86_64
实际: Kernel \r on an \m