day15-Linux的优化_linux15个优化

echo 123456|passwd --stdin oldboy
从标准输入获取密码(从管道获取密码)
非交互式设置密码

※如果在普通用户下修改密码是不可以的,只有root用户可以使用非交互式设置密码
[oldboy@oldboy59 ~]$ echo 199625|passwd --stdin oldboy \在普通用户下
Only root can do that.
\只有根用户可以这样做。
※只有root用户运行passwd 后面能加用户名
[oldboy@oldboy59 ~]$ passwd oldboy \普通用户下
passwd: Only root can specify a user name.
\只有根用户可以指定一个用户名

root用户下修改oldboy用户密码成功
[✡root@oldboy59 ~]# passwd oldboy \root用户下
Changing password for user oldboy.
New password:
passwd: all authentication tokens updated successfully. \密码修改成功


## 三、修改环境变量



> 
> .#系统设置 创建 显示或配置系统特性  
>  .#名字大写  
>  .#可以再linux下面随处使用 含义一样
> 
> 
> 


###### 1.常见的环境变量----->PATH


① UID 当前用户uid信息



[root@oldboy59 ~]# id
uid=0(root) gid=0(root) groups=0(root) \UID 当前用户uid信息


###### ※② PATH 存放的是命令的位置/路径



[root@oldboy59 ~]# echo P A T H 用 PATH \\用 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修改环境变量的过程:


![image.png](https://img-blog.csdnimg.cn/img_convert/af2aa0d791289e57c22453fa31d30018.png)



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的帮助  
 ![image.png](https://img-blog.csdnimg.cn/img_convert/bec9391ded88332561f1a5123690cf06.png)


###### 找到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的帮助  
 ![image.png](https://img-blog.csdnimg.cn/img_convert/6aca6088126081e1a390474e8f405167.png)



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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值