一、关闭SELinux功能

selinux功能太严苛,还是关闭了吧

法一:修改配置文件,永久生效

[root@web01 ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config   [root@web01 ~]# grep SELINUX=disabled /etc/selinux/config SELINUX=disabled

法二:临时关闭SELinux

[root@web01 ~]# getenforce Enforcing[root@web01 ~]# setenforce 0[root@web01 ~]# getenforce Permissive

二、精简系统开机自启动程序

系统运行过程中,很多无用的软件在后台启动,这些服务浪费了资源,而且也带来了安全隐患,因此要关闭。

需要保留的服务主要有

  • network:系统启动时,若想连接网络,必须要开启这个服务;
  • ssh:远程连接linux服务器是需要用到这个服务程序,所以必须要开启;
  • rsyslog:日志相关软件,排错很重要;
  • crontab:计划任务,生产场经常用到的软件;
  • sysstat:sysstat是一个软件包,包含监测系统性能及小路的一组工具,对于收集系统性能很有帮助;

法一:完全关闭所有服务,再开启需要保留的

[root@web01 ~]# LANG=en
[root@web01 ~]# :on|awk  $n off;done
[root@web01 ~]# chkconfig --list|grep :on
####没有结果,表示全部关闭了####
[root@web01 ~]#  $n on;done
[root@web01 ~]# chkconfig --list|grep :on
crond              :off    :off    :on    :on    :on    :on    :off
network            :off    :off    :on    :on    :on    :on    :off
rsyslog            :off    :off    :on    :on    :on    :on    :off
sshd               :off    :off    :on    :on    :on    :on    :off
sysstat            :off    :on    :on    :on    :on    :on    :off

法二:直接将所有启动的服务打印出来,去除需要开启的服务,其他服务全部关闭

[root@web02 ~]# :on|awk '{print $1}'|egrep -v "crond|network|sshd|rsyslog|sysstat");do chkconfig $n off;done
[root@web02 ~]# chkconfig --list|grep :on
crond              :off    :off    :on    :on    :on    :on    :off
network            :off    :off    :on    :on    :on    :on    :off
rsyslog            :off    :off    :on    :on    :on    :on    :off
sshd               :off    :off    :on    :on    :on    :on    :off
sysstat            :off    :on    :on    :on    :on    :on    :off

三、更改ssh服务端远程登陆的配置

ssh服务是知名服务,如果使用默认配置,容易被人暴力破解,在配置文件底部添加如下内容。

[root@web02 ~]# vim /etc/ssh/sshd_config
_______________split________________
Port 55525                    #修改默认端口
PermitRootLogin no                #禁止root远程登陆 
PermitEmptyPasswords no            #禁止密码为空的用户远程登陆
UseDNS no                     #禁用域名反向解析,启用会导致ssh连接慢的问题
GSSAPIAuthentication no            #解决linux之间使用ssh远程连接慢的问题ListenAddress 192.168.127.0:55525      #只监听内网ssh连接______________split_________________

四、调整系统的字符集设置

防止中文乱码,调整字符集,支持中文

[root@web01 ~]# echo $LANG
en_US.UTF-
[root@web01 ~]# cat /etc/sysconfig/i18n
LANG="en_US.UTF-8"
SYSFONT="latarcyrheb-sun16"
[root@web01 ~]# cp /etc/sysconfig/i18n  /etc/sysconfig/i18n.ori
[root@web01 ~]#echo ‘LANG=”zh_CN.UTF-”’>/etc/sysconfig/i18n
[root@web01 ~]#source /etc/sysconfig/i18n                #使其生效
[root@web01 ~]#echo $LANG
zh_CN.UTF-8[root@web01 ~]# LANG=en                          #临时修改英文字符集

五、服务器时间同步

[root@web01 ~]# ntpdate time.nist.gov
 May :: ntpdate[]: step time server 132.163.97.3 offset 87738.066880 sec
[root@web01 ~]# echo '*/5 * * * * /usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1' >>/var/spool/cron/root
[root@web01 ~]# crontab -l
*/ * * * * /usr/sbin/ntpdate time.nist.gov >/dev/>&

六、设置登陆超时及历史命令记录数

[root@web01 ~]# echo 'export TMOUT=300' >>/etc/profile
[root@web01 ~]# echo 'export HISTSIZE=5' >>/etc/profile
[root@web01 ~]# echo 'export HISTFILESIZE=5' >>/etc/profile
[root@web01 ~]# tail - /etc/profile
export TMOUT=300        #连接系统超过300秒,没有操作,自动退出系统
export HISTSIZE=5        #命令行的历史记录数量变量
export HISTFILESIZE=5      #历史记录文件的命令行数量(~/。bash_history)[root@web01 ~]# source /etc/profile

七、调整linux系统文件描述符数量

文件描述符是由无符号整数表示的句柄,进程使用它来标识打开的文件。文件描述符与包括相关信息(如文件的打开模式、文件的位置类型、文件的初始类型等)的文件对象相关联,这些信息被称为文件的上下文。

对于内核而言,所有打开的文件都是通过文件描述符引用的,当打开一个现有文件或者创建一个新文件时,内核向进程返回一个文件描述符。当读写一个文件时,使用open或creat返回的文件描述符标识该文件,并将其作为参数传递给read或write。

[root@web01 ~]# ulimit -n
1024                          #默认1024
[root@web01 ~]# echo '*    -    nofile    65535' >>/etc/security/limits.conf
[root@web01 ~]# tail - /etc/security/limits.conf
*    -    nofile
[root@web01 ~]# ulimit -n
65535  #调整为65535

八、linux服务器内核参数优化

[root@web01 ~]# cat>>/etc/sysctl.conf<<EOF
net.ipv4.tcp_fin_timeout = 2   #
net.ipv4.tcp_tw_reuse =
net.ipv4.tcp_tw_recycle =
net.ipv4.tcp_syncookies =
net.ipv4.tcp_keepalive_time =
net.ipv4.ip_local_port_range =
net.ipv4.tcp_max_syn_backlog =
net.ipv4.tcp_max_tw_buckets =
net.ipv4.route.gc_timeout =
net.ipv4.tcp_syn_retries =
net.ipv4.tcp_synack_retries =
net.core.somaxconn =
net.core.netdev_max_backlog =
net.ipv4.tcp_max_orphans = 16384#########以下为iptables防火墙优化,如果防火墙未开启,会提示报错,可以忽略################
net.nf_conntrack_max =
net.netfilter.nf_conntrack_max =
net.netfilter.nf_conntrack_tcp_timeout_established =
net.netfilter.nf_conntrack_tcp_timeout_time_wait =
net.netfilter.nf_conntrack_tcp_timeout_close_wait =
net.netfilter.nf_conntrack_tcp_timeout_fin_wait =
EOF[root@web01 maildrop]# sysctl -p  #手动生效

九、定时清理邮件服务器临时目录垃圾文件

centos默认安装postfix(5为sendmail),因此邮件临时存放地/var/spool/postfix/maildrop/(5为/var/spool/clientmqueue/),需要经常清理,不然容易被垃圾文件填满,导致系统的inode数量不够用。

[root@web01 maildrop]# find /var/spool/postfix/defer/ -type f|xargs rm -f  #可以放在脚本里,每天定时任务运行

十、隐藏linux版本信息

linux在本地登陆时,会显示系统的版本和内核

[root@web01 ~]# cat /etc/issue
CentOS release 6.5 (Final)
Kernel \r on an \m

[root@web01 ~]# >/etc/issue
[root@web01 ~]# cat /etc/issue

十一、锁定关键系统文件,防止被提权篡改

[root@web01 maildrop]# chattr +i /etc/passwd /etc/shadow /etc/group /etc/gshadow /etc/inittab  #上锁
[root@web01 maildrop]# chattr -i /etc/passwd /etc/shadow /etc/group /etc/gshadow /etc/inittab  #解锁

十二、升级具有典型漏洞的软件版本

如:openssl openssh bash

[root@web01 maildrop]# rpm -qa openssl openssh bash
openssl-.el6.x86_64
bash--.el6_4.x86_64
openssh-.3p1-.el6.x86_64
[root@web01 maildrop]# yum install openssl openssh bash -y
[root@web01 maildrop]# rpm -qa openssl openssh bash
openssl-.el6.x86_64
openssh-.3p1-.el6_9.x86_64
bash--.el6.x86_64

十三、配置yum更新源

[root@web01 maildrop]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
[root@web01 maildrop]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

本文非原创,摘自老男孩书籍,整理于此,权为记忆。

centos6基础优化的更多相关文章

  1. CentOS6.X 系统安装后的基础优化

    特别说明:克隆之后的网卡修改 1 编辑eth0的配置文件:vi /etc/sysconfig/network-scripts/ifcfg-eth0, 删除HWADDR地址那一行及UUID的行如下: H ...

  2. Centos6.5 64linux系统基础优化(二)

    1  操作的最小化原则 1)安装系统最小化 2)开启程序服务最小化原则 3)操作最小化原则 4)登陆最小化原则;平时没有需求不用root登陆,要用普通登陆. 2  更改ssh服务默认端口及常规配置 # ...

  3. Linux实战教学笔记06:Linux系统基础优化

    第六节 Linux系统基础优化 标签(空格分隔):Linux实战教学笔记-陈思齐 第1章 基础环境 第2章 使用网易163镜像做yum源 默认国外的yum源速度很慢,所以换成国内的. 第一步:先备份 ...

  4. Linux基础优化与安全归纳总结

    一名运维工程师在运维岗位上时间久了,就会发现Linux优化的重要性,同时会给运维工作带来很多的便利性.本人逐渐认识到了这一点,所以特意在工作闲暇之余,通过阅读Linux相关书籍及向同事.同行高手咨询, ...

  5. CentOS7.5基础优化与常用配置

    目录 最小化全新安装CentOS7基础优化 配置yum源 安装常用软件 关闭防火墙 关闭SELinux 优化ulimit 历史命令记录改为1万条 把命令提示符改为绿色 添加vim配置文件 添加一个普通 ...

  6. centos 6.x 系统基础优化简版

    Centos 6.x 系统基础优化 1.更换国内yum源 删除系统带的centos官方yum源 rm -rf /etc/yum.repos.d/* 使用国内阿里云源 curl -o /etc/yum. ...

  7. Linux学习之六-Linux系统的基础优化

    Linux系统的基础优化 何谓'优化'.顾名思义,优化就是采取某些措施使某个东西或者某事物变得更加优异,出色.对于Linux而言,在初期安装好系统之后,也需要对其进行一定的基础优化,可分为安全上的优化 ...

  8. 系统基础优化 vim

    系统基础优化 vim 1系统基础优化 (CPU-lscpu 内存-free 磁盘-df 负载-w/uptime) 1.1 系统基础优化 准备工作:如何查看系统的信息 (1)cat /etc/redha ...

  9. Linux 基础优化

    1.操作的最小化原则 1)安装系统最小化 一般情况下安装OS时,软件安装包组(Package Group)的选择: base--------------------------基本环境 editors ...

随机推荐

  1. An internal error occurred during: "Launching MVC on Tomcat 6.x". java.lang.NullPointerException

    有的时候打开Myeclispe莫名奇妙的就出现了这样的问题: An internal error occurred during: "Launching MVC on Tomcat  6.x ...

  2. 51nod 1190 最小公倍数之和 V2【莫比乌斯反演】

    参考:http://blog.csdn.net/u014610830/article/details/49493279 这道题做起来感觉非常奇怪啊--头一次见把mu推出来再推没了的-- \[ \sum ...

  3. 我理解的 js 异步成长总结

    本文是自己的理解,如果有错误的地方,还请各路大神指出 首先说下我最常用的 Promise getHandlePickupQrPromise() { // 定义返回 Promise对象 // Promi ...

  4. 给Ambari集群里安装基于Hive的大数据实时分析查询引擎工具Impala步骤(图文详解)

    不多说,直接上干货! Impala和Hive的关系(详解) 扩展博客 给Clouderamanager集群里安装基于Hive的大数据实时分析查询引擎工具Impala步骤(图文详解) 参考 horton ...

  5. QT如何发布程序

    QT如何发布程序转载 http://blog.csdn.net/iw1210/article/details/51253458

  6. D. Alyona and a tree 公式转换 + 分块暴力

    http://codeforces.com/problemset/problem/740/D 对于每一对<u, v>.设dis[u]表示root到点u的距离,那么dis<u去v> ...

  7. AJPFX分析Android退出应用最优雅的方式

    什么是RS式呢?即Receiver+singleTask .我们知道Activity有四种加载模式,而singleTask就是其中的一种,使用这个模式之后,当startActivity时,它先会在当前 ...

  8. Spring框架学习-搭建第一个Spring项目

    步骤一:下载Spring开发包. 官网:https://spring.io/           下载地址:https://repo.spring.io/libs-release-local/org/ ...

  9. sql server 2008 r2 无法定位到数据库文件目录

    像这样,选择数据库文件时, 无法定位到文件夹目录,子目录下的都不显示.明明选择的这个文件夹里还有很多子文件夹,却显示不了. 解决方法: 在此文件夹上右击,属性-安全 添加红框中的用户就可以了.

  10. Farseer.net轻量级ORM开源框架 V1.x 入门篇:视图的数据操作

    导航 目   录:Farseer.net轻量级ORM开源框架 目录 上一篇:Farseer.net轻量级ORM开源框架 V1.x 入门篇:视图实体类映射 下一篇:Farseer.net轻量级ORM开源 ...