linux老男孩 基础部分章节05-----系统优化操作说明

1.系统信息查看方法

1.1 查看系统名称信息

[root@xue/home/xuezy]# cat /etc/redhat-release 
CentOS Linux release 7.9.2009 (Core) --- 获得系统发行版本和具体系统版本信息

1.2 查看系统内核版本

[root@xue/home/xuezy]# uname -r
3.10.0-1160.11.1.el7.x86_64
[root@xue/home/xuezy]# uname -a
Linux xue 3.10.0-1160.11.1.el7.x86_64 #1 SMP Fri Dec 18 16:34:56 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

2.添加系统普通用户

2.1添加用户命令useradd

#useradd  oldgirl

2.2设置用户密码
设置的密码信息不能明文显示

# passwd oldgirl

2.3用户如何切换

[oldgirl@oldboyedu ~]$ su - root
    Password: 
    Last login: Mon Apr  8 09:04:09 CST 2019 from 10.0.0.1 on pts/1

2.4普通用户如何查看身份

 a 查看用户是否存在
[root@oldboyedu ~]# id oldboy
    uid=1000(oldboy) gid=1000(oldboy) groups=1000(oldboy)
[root@oldboyedu ~]# id old
    id: old: no such user
 b 查看此时用户身份
[oldboy@oldboyedu ~]$ whoami
    oldboy

3.操作系统优化---命令提示符优化

    优化方法: 修改PS1环境变量
    默认配置: 

    [root@oldboyedu oldboy]# echo $PS1
    [\u@\h \W]\$

    \u    --- 显示当前登录用户名称
    \h    --- 显示系统主机名称
    \W    --- 显示当前所在目录信息(目录结构的最后结尾信息)    
    
    修改优化方法:


    01. 修改命令提示符的内容:

    [root@oldboyedu.com /etc/sysconfig/network-scripts]# tail -5 /etc/profile
    export PS1='[\u@\H \w]\$ '

4. 命令提示符如何修改颜色

   

export PS1='\[\e[32;1m\]   [\u@\h \W]\$   \[\e[0m\]'
            设置颜色       内容                结束     
带颜色的:
export PS1='\[\e[36;1m\][\[\e[0m\]\[\e[31;1m\]\u\[\e[0m\]\[\e[32;1m\]@\h\[\e[0m\]\[\e[35;1m\]\w\[\e[0m\]\[\e[36;1m\]]\[\e[0m\]\$ '

 

    export PS1='\[\e[30;1m\][\u@\h \W]\$ \[\e[0m\]'  -- 黑色提示符
    export PS1='\[\e[31;1m\][\u@\h \W]\$ \[\e[0m\]'  -- 红色提示符
    export PS1='\[\e[32;1m\][\u@\h \W]\$ \[\e[0m\]'  -- 绿色提示符
    export PS1='\[\e[33;1m\][\u@\h \W]\$ \[\e[0m\]'  -- 黄色提示符
    export PS1='\[\e[34;1m\][\u@\h \W]\$ \[\e[0m\]'  -- 蓝色提示符
    export PS1='\[\e[35;1m\][\u@\h \W]\$ \[\e[0m\]'  -- 粉色提示符
    export PS1='\[\e[36;1m\][\u@\h \W]\$ \[\e[0m\]'  -- 浅蓝提示符
    export PS1='\[\e[37;1m\][\u@\h \W]\$ \[\e[0m\]'  -- 白色提示符

5.操作系统优化---yum下载源优化

 yum软件优势: 简单 快捷
    01. 不需要到官方网站单独下载软件包(yum仓库)
    02. 可以解决软件的依赖关系
    
    yum优化方法:
    01. 优化基础的yum源文件
    通过阿里镜像源进行优化:
https://developer.aliyun.com/mirror/centos?spm=a2c6h.13651102.0.0.3e221b11Gx4CsE

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

   通过网易镜像源进行优化:http://mirrors.163.com/.help/centos.html

   

1.下载对应版本repo文件
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo

2. 放入/etc/yum.repos.d/(操作前请做好相应备份)
mv ./CentOS7-Base-163.repo   /etc/yum.repos.d/

 通过清华镜像源进行优化:https://mirror.tuna.tsinghua.edu.cn/help/centos/

02. 优化扩展的yum源文件


    通过阿里镜像源进行优化:   

Epel 镜像 https://developer.aliyun.com/mirror/epel?spm=a2c6h.13651102.0.0.3e221b11zInxnm

    wget -O /etc/yum.repos.d/epel.repo 

[root@xue/home/xuezy]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
--2021-02-22 01:16:59--  http://mirrors.aliyun.com/repo/epel-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 144.123.31.232, 58.58.80.174, 144.123.31.228, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|144.123.31.232|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 664 [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/epel.repo’

100%[=====================================================================================================================================================>] 664         --.-K/s   in 0s      

2021-02-22 01:16:59 (55.3 MB/s) - ‘/etc/yum.repos.d/epel.repo’ saved [664/664]

    03.检查可用的yum源信息
    yum repolist

[root@xue/home/xuezy]# yum repolist
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                                    | 3.6 kB  00:00:00     
epel                                                                                                    | 4.7 kB  00:00:00     
extras                                                                                                  | 2.9 kB  00:00:00     
updates                                                                                                 | 2.9 kB  00:00:00     
(1/5): epel/x86_64/group_gz                                                                             |  95 kB  00:00:00     
(2/5): epel/x86_64/updateinfo                                                                           | 1.0 MB  00:00:00     
(3/5): extras/7/x86_64/primary_db                                                                       | 224 kB  00:00:01     
(4/5): epel/x86_64/primary_db                                                                           | 6.9 MB  00:00:01     
(5/5): updates/7/x86_64/primary_db                                                                      | 5.6 MB  00:00:02     
repo id                                      repo name                                                                   status
base/7/x86_64                                CentOS-7 - Base - mirrors.aliyun.com                                        10,072
epel/x86_64                                  Extra Packages for Enterprise Linux 7 - x86_64                              13,522
extras/7/x86_64                              CentOS-7 - Extras - mirrors.aliyun.com                                         451
updates/7/x86_64                             CentOS-7 - Updates - mirrors.aliyun.com                                      1,640
repolist: 25,685

04.实际下载软件

$yum install sl cowsay -y  --- 需要优化epel扩展源
    $sl                    --- 一个火车
    $cowsay    oldboy-sz-01--- 一个牛叫
    $animalsay oldboy-sz-01--- 动物叫

       补充: linux和windows软件安装程序区别
       xxx.exe -- windows 安装程序
       xxx.rpm -- linux   安装程序

05. 如何确认软件是否安装
       a 重新再yum安装一遍
       b 利用rpm命令也可以管理检查软件是否安装
查看软件是否安装: 

    [root@oldboyedu ~]# rpm -qa sl   -q表示查询query   -a表示所有
         sl-5.02-1.el7.x86_64

查看软件包中有哪些信息

   [root@oldboyedu ~]# rpm -ql cowsay  -l表示列表显示
         /usr/bin/animalsay
         /usr/bin/cowsay
         /usr/bin/cowthink

[root@xue/home/xuezy]# rpm -ql sl
/usr/bin/sl
/usr/share/doc/sl-5.02
/usr/share/doc/sl-5.02/LICENSE
/usr/share/doc/sl-5.02/README.ja.md
/usr/share/doc/sl-5.02/README.md
/usr/share/man/ja/man1/sl.1.ja.gz
/usr/share/man/man1/sl.1.gz

查看文件信息属于哪个软件大礼包

PS: 有些命令名称和软件包的名称是不相同的

[root@oldboyedu ~]# which ssh
         /usr/bin/ssh
[root@oldboyedu ~]# rpm -qf /usr/bin/ssh    #需要绝对路径,根据which查找出来
         openssh-clients-7.4p1-16.el7.x86_64

[root@xue/home/xuezy]# rpm -ql openssh-clients
/etc/ssh/ssh_config
/usr/bin/scp
/usr/bin/sftp
/usr/bin/slogin
/usr/bin/ssh
.....
.....
.....


综上:一行可以搞定的方法
[root@oldboyedu ~]# rpm -qf `which ssh`
         openssh-clients-7.4p1-16.el7.x86_64

其它yum命令

yum list       --- 可以安装和已安装的所有软件
yum grouplist  --- 可以安装的和已安装的所有软件包组信息
yum groupinstall -y Development Tools   --- 安装软件包组的方法

包组:

基础作业:
01. 如何每次登陆系统都提示小牛信息
02. 课程内容命令总结 快捷方式 符号

扩展作业:
01. 如何实现提示符是彩色
    用户信息是红色  主机名信息是绿色  目录信息是蓝色的

基础作业:
01. 一个软件安装好了,如何利用rpm命令进行卸载

    如何卸载软件:
    01. yum erase cowsay -y      --- 极其不建议
    erase          Remove a package or packages from your system
    02. rpm -e 软件名称  --nodeps  --- 推荐使用

扩展作业:
01. 如何创建多个用户(创建50个用户 oldboy1..oldboy100)

创建用户: useradd 
       方法一: 创建多个用户(借助nodepad++)
       alt+c功能: 可以生成数字序列

先回车10行     

按住Alt键 选中10行,写入useradd oldboy,再   Alt+c,插入数字。再复制全部的,放到shell中。

 方法二: 借助sed命令创建多个用户?

  方法三: 利用shell脚本的 循环语句

       [root@oldboyedu ~]# for num in {01..20};do useradd oldgirl$num;done
       [root@oldboyedu ~]# for num in {01..20};do id oldgirl$num;done
       uid=1021(oldgirl01) gid=1021(oldgirl01) groups=1021(oldgirl01)
       uid=1022(oldgirl02) gid=1022(oldgirl02) groups=1022(oldgirl02)
       uid=1023(oldgirl03) gid=1023(oldgirl03) groups=1023(oldgirl03)
       uid=1024(oldgirl04) gid=1024(oldgirl04) groups=1024(oldgirl04)
....
       创建用户同时,设置用户密码信息
       useradd olddog01 ;echo 123456|passwd --stdin olddog01

6. 系统安全相关优化(将一些安全服务进行关闭)

6.1 防火墙服务程序

centos6
 查看防护墙服务状态

    /etc/init.d/iptables status

临时关闭防火墙服务

       /etc/init.d/iptables stop
       /etc/init.d/iptables status

 永久关闭防火墙服务

       chkconfig iptables off/on

  centos7
查看防火墙服务状态

systemctl status firewalld

 临时关闭防火墙服务

       systemctl stop firewalld
       systemctl status firewalld  -- 操作完确认

永久关闭防火墙服务

    systemctl disable firewalld

 补充: 查看服务状态信息简便方法

       systemctl is-active firewalld   --- 检查服务是否正常运行
       systemctl is-enabled firewalld  --- 检查确认服务是否开机运行

6.2系统的selinux服务程序

       selinux服务对root用户权限进行控制
       很多企业中:selinux服务默认关闭


       centos6==centos7 
       临时关闭:
       检查确认: 

      getenforce    --- 确认selinux服务是否开启或是关闭的

     如何关闭: 

       [root@oldboyedu ~]# setenforce 
       usage:  setenforce [ Enforcing | Permissive | 1 | 0 ]
       Enforcing   1  --- 临时开启selinux
       Permissive  0  --- 临时关闭selinux
       
       setenforce 0   --- 临时关闭selinux服务

       永久关闭:

     [root@oldboyedu ~]# vi /etc/selinux/config
       SELINUX=disabled

       enforcing     - SELinux security policy is enforced.  
                      selinux服务处于正常开启状态
       permissive     - SELinux prints warnings instead of enforcing.
                      selinux服务被临时关闭了
       disabled     - No SELinux policy is loaded.
                      selinux服务彻底关闭

 PS: 如果想让selinux配置文件生效,重启系统
       

7.字符编码优化

    什么是字符编码: 可以实现对非英文字符的支持
    计算机操作系统是谁发明的?  --美国人--英语    
    支持中文比较好的编码:
    UTF-8 比较通用
    GBK   比较国际通用
    
    出现乱码的原因:
    01. 系统字符集设置有问题 
    02. 远程软件字符集设置有问题
    03. 文件编写字符集和系统查看的字符集不统一
    
    系统中字符集编码设置方法
    centos6 
    查看默认编码信息:

    [root@oldboyedu ~]# echo $LANG   --- LANG用于设置字符编码信息
    en_US.UTF-8

 临时修改:

    [root@oldboyedu ~]# echo $LANG
    en_US.UTF-8
    LANG=XXX

 永久修改:

方法一:
    [root@oldboyedu ~]# tail -5 /etc/profile
    export LANG='en_US.UTF-8'
    
方法二:
    vi /etc/sysconfig/i18n
    LANG='en_US.UTF-8
    source /etc/sysconfig/i18n

 centos7 
    查看默认编码信息

  [root@oldboyedu ~]# echo $LANG
    en_US.UTF-8

   临时修改:

    [root@oldboyedu ~]# echo $LANG
    en_US.UTF-8
    LANG=XXX

    永久修改:

  方法一: 更加有先
    [root@oldboyedu ~]# tail -5 /etc/profile
    export LANG='en_US.UTF-8'
  方法二:
    [root@oldboyedu ~]# cat /etc/locale.conf 
    LANG="zh_CN.UTF-8"

    补充:一条命令即临时设置,又永久设置

    localectl set-locale LANG=zh_CN.GBK

8.使xshell软件远程连接速度加快

    第一个步骤:修改ssh服务配置文件
    vi /etc/ssh/sshd_config
    79  GSSAPIAuthentication no
    115 UseDNS no
    
    第二个步骤:修改hosts文件
    [root@oldboyedu ~]# vi /etc/hosts
    10.0.0.200  oldboyedu.com
    
    第三个步骤:重启ssh远程服务
    systemctl restart sshd

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值