zoukankan      html  css  js  c++  java
  • 安装系统后的简单调优

    安装系统后的简单调优

    1关闭SELINUX

    SELinux 是美国安全局NSA对于强制访问控制的安全工具,控制比较严格,生产环境不用。

     

     

    1. [root@oldboy ~]# cat /etc/selinux/config #查看SELINUX配置文件
    2.  
    3. # This file controls the state of SELinux on the system.
    4. # SELINUX= can take one of these three values:
    5. #     enforcing - SELinux security policy is enforced.
    6. #     permissive - SELinux prints warnings instead of enforcing.
    7. #     disabled - No SELinux policy is loaded.
    8. SELINUX=enforcing
    9. # SELINUXTYPE= can take one of these two values:
    10. #     targeted - Targeted processes are protected,
    11. #     mls - Multi Level Security protection.
    12. SELINUXTYPE=targeted 
    13.  
    14. [root@oldboy ~]# sed  's#SELINUX=enforcing#SELINUX=disabled#g'  /etc/selinux/config   #修改SELINUX配置文件
    15.  
    16. # This file controls the state of SELinux on the system.
    17. # SELINUX= can take one of these three values:
    18. #     enforcing - SELinux security policy is enforced.
    19. #     permissive - SELinux prints warnings instead of enforcing.
    20. #     disabled - No SELinux policy is loaded.
    21. SELINUX=disabled
    22. # SELINUXTYPE= can take one of these two values:
    23. #     targeted - Targeted processes are protected,
    24. #     mls - Multi Level Security protection.
    25. SELINUXTYPE=targeted 
    26.  
    27.  
    28. [root@oldboy ~]# sed -'s#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config       
    29. [root@oldboy ~]# getenforce  #查看SELINUX运行状态
    30. Enforcing
    31. [root@oldboy ~]# setenforce  #设置SELINUX运行状态
    32. usage:  setenforce [ Enforcing | Permissive | 1 | 0 ]
    33. [root@oldboy ~]# setenforce  0 #设置SELINUX运行状态permissive
    34. [root@oldboy ~]# getenforce 
    35. Permissive
     

     

     

    注意:修改配置文件后必须要重启生效,而 setenforce设置SELINUX运行状态只是保证现在生效。两者结合起来保证SELINUX关闭永久生效。

     

     

    2设置LINUX运行级别

     1)运行级别是什么:runlevel linux运行时的一种状态标识用数字表示。

     0 halt                          关机状态

     1 single user                    单用户

     2 multisuser without nfs           多用户没有NFS网络文件系统

     3 fullmutiuser mode              文本模式 (工作模式)

     4 unused                       保留

     5 x11                          图形,桌面

     6 reboot                       重启

     

    2)如何查看当前系统的运行级别

    [root@oldboy ~]# runlevel  #查看LINUX运行级别

    N 3                        #第一个为前一次的运行级别 第二个为当前的运行级别

     

    3)查看LINUX启动时候的LINUX级别

     

    1. [root@oldboy ~]# cat /etc/inittab 
    2. # inittab is only used by upstart for the default runlevel.
    3. #
    4. # ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
    5. #
    6. # System initialization is started by /etc/init/rcS.conf
    7. #
    8. # Individual runlevels are started by /etc/init/rc.conf
    9. #
    10. # Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf
    11. #
    12. # Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf,
    13. # with configuration in /etc/sysconfig/init.
    14. #
    15. # For information on how to write upstart event handlers, or how
    16. # upstart works, see init(5), init(8), and initctl(8).
    17. #
    18. # Default runlevel. The runlevels used are:
    19. #   0 - halt (Do NOT set initdefault to this)
    20. #   1 - Single user mode
    21. #   2 - Multiuser, without NFS (The same as 3, if you do not have networking)
    22. #   3 - Full multiuser mode
    23. #   4 - unused
    24. #   5 - X11
    25. #   6 - reboot (Do NOT set initdefault to this)
    26. id:3:initdefault:  #设置LINUX开机运行级别为3
     

     

    3.精简自启动服务 (预习补充)

    1>设置开机自启动

      节省开机时间,加快启动速度节省资源开销,减少安全隐患(服务越少漏洞越少)。

       

    2>需要保留的开机自启动服务

    1.SSHD

    2.rsyslog 

       是操作系统提供的一种机制,系统的守护程序通常会使用rsyslog将各种信息写到各个系统日志文件中。

    3.network

    4.crond

       周期性处理一些重复的问题计划任务服务。

    5.Sysstat

       是一个软件包,包括监控系统性能及效率的一组工具包括了iostat mpstat sar

      

    3>设置开机自启动服务的常见方法

    1.setup>system service在弹出来的窗口进行设置

     

    2.执行ntsysv,在弹出来的窗口进行设置

     

    3.chkconfig 保证必须的服务开启就可以了      

    [root@oldboy ~]# chkconfig --list |grep "3:on"|awk '{print$1}'|grep -EV "sshd|rsyslog|network|crond|sysstat"|sed -r 's#(.*)#chkconfig 1 off#g'|bash

    chkconfig --list 查看开启的服务 

    chkconfig ntp on 开启ntp服务  

    grep 3:on  (匹配3级别下开启的)。

    awk {print $1} (打印第一列 即服务的名字)。

    grep -Ev sshd|rsyslog|network|crond|sysstat (-E 同时过滤 -v 排除)。

    sed -r s#(.*)#chkconfig 1 off#g |bash r表示支持正则  后面是sed的一个后向引用)。

    也可以用 awk {print chkconfig  $1  off} |bash 来替代sed

     

    4 shell for 循环

     

    4.关闭防火墙

     

    1. [root@oldboy ~]# /etc/init.d/iptables stop   #临时关闭
    2. iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
    3. iptables: Flushing firewall rules:                         [  OK  ]
    4. iptables: Unloading modules:                               [  OK  ]
    5. [root@oldboy ~]# /etc/init.d/iptables status  #查看状态
    6. iptables: Firewall is not running.
    7. [root@oldboy ~]# chkconfig iptables off       #开机也不启动
    8.  

    跟关闭SELINUX一样,关闭防火墙也是修改配置文件和设置临时关闭两者结合起来保证防火墙永久关闭。

     

    5.LINUX 中文显示

    调整字符集为UTF-8既可。

     

    1. [root@oldboy ~]# cat /etc/sysconfig/i18n #查看当前字符集设置
    2. LANG="en_US.UTF-8"
    3. SYSFONT="latarcyrheb-sun16"
    4. [root@oldboy ~]# echo 'LANG="zh_CN.UTF-8"'  >/etc/sysconfig/i18n #修改设置
    5. [root@oldboy ~]# . /etc/sysconfig/i18n        #执行配置文件
    6. [root@oldboy ~]# cat /etc/sysconfig/i18n
    7. LANG="zh_CN.UTF-8"               

    客户端上CRT的字符串配置也要修改

     

     

     

    6.历史记录数及登录超时环境变量设置

     

    1设置闲置帐号超时时间

     

     

    1. export TMOUT=10
    2. [root@oldboy ~]# export TMOUT=10   #设置超时时间为10秒
    3. [root@oldboy ~]# timed out waiting for input: auto-logout  #10秒后超时提示
     

     

    不过这个配置仅临时生效要想永久生效需要

    export TMOUT=10 加入到/etc/profile

     

    1. [root@oldboy ~]# echo "export TMOUT=10" >> /etc/profile
    2. [root@oldboy ~]# . /etc/profile
    3. [root@oldboy ~]# timed out waiting for input: auto-logout
     

    设置LINUX命令行历史记录数

     

    export HISTSIZE=5

     

    1. [root@oldboy ~]# export HISTSIZE=5  #设置历史记录只记录5个
    2. [root@oldboy ~]# history 
    3.   529  . /etc/profile
    4.   530  echo "export TMOUT=910" >> /etc/profile
    5.   531  . /etc/profile
    6.   532  export HISTSIZE=5
    7.   533  history 
    8.  
     

    不过这个配置仅临时生效要想永久生效需要

    export HISTSIZE=5

     加入到/etc/profile

     

    1. [root@oldboy ~]# echo "export HISTSIZE=5" >> /etc/profile
    2. [root@oldboy ~]# . /etc/profile 
     

     

    linux特殊变量

    临时生效 

    export TMOUT=10    连接的时间时间控制变量

    export HISTSIZE=5    命令行历史记录数量

    export HISTFILESIZE=5 命令行命令对应文件的记录数

    永久生效

    将上述的命令追加到/etc/profile

     

    1. [root@oldboy ~]# source /etc/profile #使配置文件生效
    2. 或者
    3. [root@oldboy ~]# . /etc/profile       
     

    7.隐藏LINUX版本信息

     

     

    1. [root@oldboy ~]# cat /etc/issue
    2. CentOS release 6.7 (Final)
    3. Kernel   on an m
    4. [root@oldboy ~]# >/etc/issue.net       #清空/etc/issue.net  内容
    5. [root@oldboy ~]# > /etc/issue       
    6. [root@oldboy ~]# cat /etc/issue.net  
     

     

    网络状态说明及优化命令和优化细节参考资料请看:
    http://yangrong.blog.51cto.com/6945369/1321594 

    老男孩教育的优秀学生博文
    http://oldboy.blog.51cto.com/2561410/1336488 

     





  • 相关阅读:
    第五章 kubernetes常见故障排错
    第二十五章 Centos7下二进制安装Mysql-5.7.34
    第二十四章 MySQL导入数据常见报错解决
    第二十三章 Centos7 下 Mysql 8.0.24编译安装
    第二十二章 Centos7下 Mysql 8.0.24 二进制安装
    第二十一章 MySQL数据库优化
    Sqoop导入数据到mysql数据库报错:ERROR tool.ExportTool: Error during export: Export job failed!
    python读取csv、excel、mysql内容
    WTF表单验证
    Flask_WTF实现表单
  • 原文地址:https://www.cnblogs.com/yangliheng/p/5691837.html
Copyright © 2011-2022 走看看