9.28 linux系统基础优化

  • 关闭SELinux(是美国安全局对强制访问的实现)功能
[[email protected] ~]# sed -i ‘s#SELINUX=enforcing#SELINUX=disabled#g‘ /etc/selinux/config            #使用sed + i 命令修改
[[email protected] ~]# grep "SELINUX=disabled" /etc/selinux/config                                    #grep查看
SELINUX=disabled
[[email protected] ~]# cat /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted
以上重启生效,生产环境不能重启

用以下命令不用重启 
[[email protected] ~]# getenforce
Enforcing
[[email protected] ~]# setenforce
usage: setenforce [ Enforcing | Permissive | 1 | 0 ]
[[email protected] ~]# setenforce 0
[[email protected] ~]# getenforce
Permissive
  • 运行级别

[[email protected] ~]# cat /etc/inittab
# inittab is only used by upstart for the default runlevel.
#
# ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# System initialization is started by /etc/init/rcS.conf
#
# Individual runlevels are started by /etc/init/rc.conf
#
# Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf
#
# Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf,
# with configuration in /etc/sysconfig/init.
#
# For information on how to write upstart event handlers, or how
# upstart works, see init(5), init(8), and initctl(8).
#
# Default runlevel. The runlevels used are:
#   0 - halt (Do NOT set initdefault to this)
#   1 - Single user mode
#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)
#   3 - Full multiuser mode
#   4 - unused
#   5 - X11                   #桌面
#   6 - reboot (Do NOT set initdefault to this)
#
id:3:initdefault:

[[email protected] ~]# grep 3:initdefault /etc/inittab          #调整运行级别,默认3,可以调成其他
id:3:initdefault:
[[email protected] ~]# runlevel                #查看当前级别
N 3
[[email protected] ~]# init 0                   #切换运行级别

  • 关机
shutdown(halt) init0
参数
-r reboot after shutdown
-h halt or power off after shutdown       

shutdown -h 10    #10分钟后关闭
shutdown now     #马上
poweroff                #关闭电源

*关闭防火墙
[[email protected] ~]# /etc/init.d/iptables stop                     #临时关闭
iptables:将链设置为政策 ACCEPT:filter             [确定]
iptables:清除防火墙规则:                                [确定]
iptables:正在卸载模块:                                   [确定]
[[email protected] ~]# /etc/init.d/iptables status                   #查看状态
iptables:未运行防火墙。
[[email protected] ~]# /etc/init.d/iptables restart                  # 重启防火墙
iptables:应用防火墙规则:                                [确定]
[[email protected] ~]# chkconfig iptables off                         #开机也不启动了
  • linux中文显示设置等
*中文显示设置
[[email protected] ~]# echo ‘LANG="zh_CN.UTF-8“‘ > /etc/sysconfig/i18n
[[email protected] ~]# cat /etc/sysconfig/i18n
LANG="zh_CN.UTF-8“
[[email protected] ~]# echo $LANG
zh_CN.UTF-8
同时调整ssh客户端

*设置账号超时时间
[[email protected] ~]# export TMOUT=5      #5秒后关机  (临时生效)
[[email protected] ~]# timed out waiting for input: auto-logout

*设置命令行历史记录
[[email protected] ~]# history -c         #清除所有历史记录
[[email protected] ~]# history             #查看历史记录
    1  history
[[email protected] ~]# echo  1
1
[[email protected] ~]# echo  2
2
[[email protected] ~]# echo  3
3
[[email protected] ~]# echo  4
4
[[email protected] ~]# echo  5
5
[[email protected] ~]# history -d 3        #删除指定行记录
[[email protected] ~]# history
    1  history
    2  echo  1
    3  echo  3
    4  echo  4
    5  echo  5
    6  history -d 3
    7  history
[[email protected] ~]# !6                 #执行某行历史命令
history -d 3

[[email protected] ~]# export HISTSIZE=5        #控制历史记录记录数量(临时生效)#永久生效放在/etc/profile文件下,然后source以下/etc/profile
[[email protected] ~]# history
    5  history
    6  echo
    7  history -d 3
    8  export HISTSIZE=5
    9  history
[[email protected] ~]# cat ~/.bash_history         #即使控制了在根目录下还有
[[email protected] ~]# export HISTORYSIZE=5    #命令行命令对应文件的记录数

*隐藏版本信息
[[email protected] ~]# cat /etc/issue
CentOS release 6.7 (Final)
Kernel \r on an \m

[[email protected] ~]# > /etc/issue
[[email protected] ~]# cat /etc/issue.net
CentOS release 6.7 (Final)
Kernel \r on an \m
[[email protected] ~]# >/etc/issue.net
[[email protected] ~]# cat /etc/issue
[[email protected] ~]#
时间: 2025-01-03 16:23:32

9.28 linux系统基础优化的相关文章

linux系统基础优化

1.Linux系统基础优化 一.关闭SELinux功能 Selinux是什么? 安全工具,控制太严格,生产环境不用它,使用其他安全手段. 简介: SELinux带给Linux的主要价值是:提供了一个灵活的,可配置的MAC机制. Security-Enhanced Linux (SELinux)由以下两部分组成: 1) Kernel SELinux模块(/kernel/security/selinux) 2) 用户态工具 SELinux是一个安全体系结构,它通过LSM(Linux Security

Linux 系统基础优化和常用命令

目录 Linux 系统基础优化和常用命令 软连接 tar解压命令 gzip命令 netstart命令 ps命令 kill命令 killall命令 SELinux功能 iptables防火墙 Linux中文显示设置(防止中文乱码) df 命令 tree命令 设置主机名 DNS 查看Linux的dns, 唯一配置文件 本地强制dns解析文件 /etc/hosts nslookup命令 计划任务crond服务 软件包管理 windows程序 macos程序 RPM软件包管理器 实例 rpm安装软件 r

linux系统基础优化和安全重点小结

本文描述一些基本的系统优化知识点,为适应批量配置,所有代码为非交互式配置方法,可在crt中通过命令窗口做简单的批量处理. 不用root登录管理系统,而以普通用户登录通过sudo授权管理.作为一个例子这里新建一个用户,并做sudo提权 useradd gotimmygo echo 123456|passwd --stdin gotimmygo \cp /etc/sudoers{,ori} echo "gotimmygo ALL=(ALL) NOPASSWD:ALL">>/et

Linux系统基础优化及常用命令

Linux基础系统优化 引言没有,只有一张图. Linux的网络功能相当强悍,一时之间我们无法了解所有的网络命令,在配置服务器基础环境时,先了解下网络参数设定命令. ifconfig 查询.设置网卡和ip等参数 ifup,ifdown    脚本命令,更简单的方式启动关闭网络 ip 符合指令,直接修改上述功能 在我们刚装好linux的时候,需要用xshell进行远程连接,那就得获取ip地址,有时候网卡默认是没启动的,Linux也就拿不到ip地址,因此我们得手动启动网卡 #编辑网卡配置文件 vim

8,Linux系统基础优化及常用命令

Linux基础系统优化 引言没有,只有一张图. Linux的网络功能相当强悍,一时之间我们无法了解所有的网络命令,在配置服务器基础环境时,先了解下网络参数设定命令. ifconfig 查询.设置网卡和ip等参数 ifup,ifdown    脚本命令,更简单的方式启动关闭网络 ip 符合指令,直接修改上述功能 在我们刚装好linux的时候,需要用xshell进行远程连接,那就得获取ip地址,有时候网卡默认是没启动的,Linux也就拿不到ip地址,因此我们得手动启动网卡 #编辑网卡配置文件 vim

linux系统基础优化16条知识汇总

优化的总结: 1.不用root管理,以普通用户的名义通过sudo授权管理. 2.更改默认的远程连接SSH服务端口,禁止root用户远程连接,甚至 要更改只监听内网IP. 3.定时自动更新服务区时间,使其和互联网时间同步. 4.配置yum跟新源,从更新源下载安全软件包. 5.关闭seLinux及iptables(在工作场景中,如果有外部IP一般要打开 6.调整文件描述符的数量,进程及文件的打开都会消耗文件描述. 7.定时自动清理邮件目录垃圾文件,防止inodes节点被占满 (注意Centos6和C

Linux系统基础优化以及常用命令

Linux基础系统优化 Linux的网络功能相当强悍, 一时之间我们无法了解所有的网络命令, 在配置服务器基础环境是, 先俩接下网络参数设定命令 : ifconfig 查询, 设置网卡和ip等参数 ifip, ifdown 脚本命令, 更简单的方式启动和关闭网络 ip 符合指令, 直接修改上述功能 在我们刚装好linux的时候, 需要用xshell进行远程连接, 那就得获取ip地址, 有时候网卡默认是没有起动的, linux也就拿不到IP地址, 因此我们必须要手动启动网卡. # 编辑网卡配置文件

Linux系统基础优化脚本--安装完操作系统必做的操作

#!/bin/sh ###open iptables service, allow this ports access 80, 3307, 21#### function firewall() {         service iptables start         for Port in 21 80 3307            do                  iptables -I INPUT 5  -m state --state NEW -m tcp -p tcp --

Linux服务器企业集群架构部署搭建(一)----环境配置要求与系统基础优化

命运是大海,当你能够畅游时,你就要纵情游向你的所爱,因为你不知道狂流什么会到来,卷走一切希望与梦想. 本文作者:燁未央_Estelle版权声明:测试学习,不足之处,欢迎指正.允许转载,转载时请务必以超链接形式标明文章原始出处.作者信息和本声明 第一章 集群架构搭建部署目标1.1 本次架构部署配置概况提示,本次集群架构所使用的服务器均为VM虚拟机进行模拟搭建测试及学习. ①两台linux服务器作为负载均衡服务器(LVS-01/LVS-02),基本模式:LVS-DR+keepalived.负责分发所