day15-Linux的优化_linux15个优化

本文详细介绍了Linux系统中的PATH查找机制,环境变量PS1的临时和永久修改方法,如何关闭和配置SElinux,防火墙firewalld的使用,以及如何修改yum源,包括阿里云和清华仓库的镜像。还提及了《Linux从入门到精通》系列教程的相关内容。
摘要由CSDN通过智能技术生成
1.系统会在PATH里面进行查找
2.存在 运行(命令解释器)
3.不存在 command not found 命令找不到

2. $PS1修改环境变量的过程:

image.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

找到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

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 >
![](https://img-blog.csdnimg.cn/img_convert/9a8cb5f8c0ec69e6499adead0da6e95b.png)



最全的Linux教程,Linux从入门到精通

======================

1.  **linux从入门到精通(第2版)**

2.  **Linux系统移植**

3.  **Linux驱动开发入门与实战**

4.  **LINUX 系统移植 第2版**

5.  **Linux开源网络全栈详解 从DPDK到OpenFlow**



![华为18级工程师呕心沥血撰写3000页Linux学习笔记教程](https://img-blog.csdnimg.cn/img_convert/59742364bb1338737fe2d315a9e2ec54.png)



第一份《Linux从入门到精通》466页

====================

内容简介

====

本书是获得了很多读者好评的Linux经典畅销书**《Linux从入门到精通》的第2版**。本书第1版出版后曾经多次印刷,并被51CTO读书频道评为“最受读者喜爱的原创IT技术图书奖”。本书第﹖版以最新的Ubuntu 12.04为版本,循序渐进地向读者介绍了Linux 的基础应用、系统管理、网络应用、娱乐和办公、程序开发、服务器配置、系统安全等。本书附带1张光盘,内容为本书配套多媒体教学视频。另外,本书还为读者提供了大量的Linux学习资料和Ubuntu安装镜像文件,供读者免费下载。



![华为18级工程师呕心沥血撰写3000页Linux学习笔记教程](https://img-blog.csdnimg.cn/img_convert/9d4aefb6a92edea27b825e59aa1f2c54.png)



**本书适合广大Linux初中级用户、开源软件爱好者和大专院校的学生阅读,同时也非常适合准备从事Linux平台开发的各类人员。**

> 需要《Linux入门到精通》、《linux系统移植》、《Linux驱动开发入门实战》、《Linux开源网络全栈》电子书籍及教程的工程师朋友们劳烦您转发+评论




**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**

**[需要这份系统化的资料的朋友,可以点击这里获取!](https://bbs.csdn.net/topics/618542503)**

**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**
  • 5
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值