① UID 当前用户uid信息
[root@oldboy59 ~]# id
uid=0(root) gid=0(root) groups=0(root) \\UID 当前用户uid信息
※② PATH 存放的是命令的位置/路径
[root@oldboy59 ~]# echo $PATH \\用$符号识别环境变量
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/u
sr/sbin:/usr/bin:/root/bin
/usr/sbin: ----->/sbin
/usr/bin: ----->/bin
※关闭PATH的后果 ---->所有命令不能使用(临时)
重启后恢复
[✡root@oldboy59 ~]# PATH= \\等于后面加一个空格
[✡root@oldboy59 ~]# ls
-bash: ls: No such file or directory \\没有这个目录
[✡root@oldboy59 ~]# find
-bash: find: No such file or directory \\没有这个目录
[✡root@oldboy59 ~]# touch
-bash: touch: No such file or directory \\没有这个目录
③我们在输入ls命令回车后发生了什么过程?
1.系统会在PATH里面进行查找
2.存在 运行(命令解释器)
3.不存在 command not found 命令找不到
2. $PS1修改环境变量的过程:
1.临时
export PS1='[\u@\h \w]\$'
\\小写w是显示完整的目录
2.永久
vim /etc/profile添加
[✡root@oldboy59 ~]# tail -n1 /etc/profile \\查看最后一行添加的变量
export PS1="[\[\e[36;1m\]✡\u@\[\e[0m\]\[\e[34;1m\]\H\[\e[0m\] \
[\e[33;1m\]\w\[\e[0m\]]\\$ "
3.检查
[root@oldboy59 ~]#echo $PS1
[\u@\h \W]\$
4.生效
[✡root@oldboy59 ~]# source /etc/profile
补充:颜色的变量修改
export PS1="[\[\e[36;1m\]\u@\[\e[0m\]\[\e[32;1m\]\H\[\e[0m\]
\[\e[35;1m\]\w\[\e[0m\]]\\$ "
四、关闭SElinux
1.先看看SElinux是干什么的?
增强型Linux(安全)
美国的NSA(安全局)用来限制root和普通用户权限的
2. 如何关闭SELinux
①永久关闭
修改配置文件 vim /etc/selinux/config
修改SELINUX=disabled 为永久关闭
SELinux=右边可以写什么:
SELINUX=enforcing SELinux 开启
SELINUX=permissive SELinux 禁用,有警告信息
SELINUX=disabled SELinux 禁用
[✡root@oldboy59 /tmp]# vim /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# 开启 enforced - SELinux security policy is enforced.
# 宽容模式 permissive - SELinux prints warnings instead of disabled.
# 关闭 disabled - No SELinux policy is loaded.
SELINUX=disabled //永久关闭
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are
protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted \\慎重修改
② 临时关闭
getenforce 查看
setenforce 修改 ,服务器重启后失效
getenforce 查看
[☆root@oldboy59 ~]# getenforce
Disabled
setenforce 修改 (0 )
[☆root@oldboy59 ~]# setenforce
usage: setenforce [ Enforcing | Permissive | 1 | 0 ]
[☆root@oldboy59 ~]# setenforce 0
setenforce: SELinux is disabled \\已经修改过
五、防火墙
firewalld (在CentOS 7中)
iptables (在CentOS 6&7中)
1.作用
根据设置规则 准许/禁止用户进出
2.是否需要开启?
①如果服务器有公网ip地址,则开启防火墙
②如果服务器没有公网ip 局域网或者并发访问量太高,则关闭防火墙
3.如何关闭呢
①防火墙临时关闭 systemctl stop firewalld
※服务器重启后会失效
[☆root@oldboy59 ~]# systemctl stop firewalld \\关闭防火墙
[☆root@oldboy59 ~]# systemctl status firewalld \\查看防火墙状态
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead) \\如果是active是运行中 如果是inactice则是关闭
Docs: man:firewalld(1)
Apr 15 11:19:33 oldboy59 systemd[1]: Stopping firewalld - dynamic firewa....
Apr 15 11:19:33 oldboy59 systemd[1]: Stopped firewalld - dynamic firewal....
Hint: Some lines were ellipsized, use -l to show in full.
②防火墙永久关闭 systemctl disable firewalld
[☆root@oldboy59 ~]# systemctl disable firewalld \\ disable 禁用
[☆root@oldboy59 ~]# systemctl status firewalld \\查看防火墙状态
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead) \\以禁用
Docs: man:firewalld(1)
Apr 15 11:19:33 oldboy59 systemd[1]: Stopping firewalld - dynamic firewa....
Apr 15 11:19:33 oldboy59 systemd[1]: Stopped firewalld - dynamic firewal....
Hint: Some lines were ellipsized, use -l to show in full.
③检查
systemctl status firewalld 查看防火墙状态
防火墙永久开启 enable
systemctl enable firewalld
服务器重启后生效
六、如何修改yum源
我们常见的mirror镜像网站有以下几种常用的软件下载仓库
阿里云仓库
清华仓库
修改yum方法
首先打开阿里云网站 https://opsx.alibaba.com (谷歌浏览器中ctrl+f可以直接搜索centos),接着点开centos的帮助
找到CentOS查看帮助
1,备份
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
2,修改yum源
下载新的CentOS-Base.repo到/etc/yum.repos.d/curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
3.查看yum源
①yum repolist
②cat /etc/yum.repos.d/CentOS-Base.repo(此方法不建议使用)
4.安装软件
yum install -y wget
5.检查是否安装
rpm -qa wget
※查看yum源 —>yum repolist
[☆root@oldboy59 ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
\* base: mirrors.aliyun.com ----->yum源已修改
\* extras: mirrors.aliyun.com
\* updates: mirrors.aliyun.com
repo id repo name status
base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com 10,019
epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 13,051
extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 385
updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 1,511
repolist: 24,966
这是清华的mirror镜像网站
https://mirrors.tuna.tsinghua.edu.cn
如何增加eple源
系统有默认yum源
base
extras
updates
增加eple源方法
打开阿里云网站https://opsx.alibaba.com (谷歌浏览器中ctrl+f可以直接搜索eple),接着点开eple的帮助
1.备份
mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup
2.添加eple源
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
3.查看系统默认yum源
[☆root@oldboy59 ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
\* base: mirrors.aliyun.com
\* extras: mirrors.aliyun.com
\* updates: mirrors.aliyun.com
repo id repo name status
base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com 10,019
epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 13,051 \\已添加
extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 385
updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 1,511
repolist: 24,966
我们还可以安装yum install -y cowsay sl
[✡root@oldboy59 /tmp]# cowsay Balabala
__________
< Balabala >
----------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||