Centos 6.4 x86_64 最小化安装后的优化——还需要整理
1)更新yum官方源
2)关闭不需要的服务
3)关闭不需要的TTY
4)对TCP/IP网络参数进行调整
_4.1) 优化Linux下的内核TCP参数以提高系统性能
5)设置时间同步
6)优化最大文件数限制
7)关闭SELINUX
8)修改SSH登录配置
9)清理登陆的时候显示的系统及内核版本
10)删除不必要的系统用户和群组
11)关闭重启ctl-alt-delete组合键
12)设置一些全局变量
13)设置history历史记录
14)centos6.4最小化安装后启动网卡
15)添加普通用户,设置sudo权限
16)禁止root远程用户登录
17)sed修改远程端口
18)防火墙iptables配置
19)修改默认DNS
20)安装必要软件,更新yum源 [epel源]
21)更新内核和软件到最新版本
22)去除上次登录的信息
mkdir -p /etc/yum.repos.d/yum_bak
mv /etc/yum.repos.d/* /etc/yum.repos.d/yum_bak/ wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
2) 执行yum源更新,命令如下:
yum clean all
yum makecache
yum update
yum clean all #清除yum缓存
- crontab:自动计划任务。
- network:Linux系统的网络服务,很重要,若不开启此服务的话,服务器就不能联网。
- sshd:OpenSSH服务器守护进程。
- rsyslog:Linux系统的日志系统服务(Centos 5.8下此服务名称为syslog),必须要启动。
for sun in `chkconfig --list|grep :on|awk '{print $1}'`;do chkconfig --level $sun off;done
#或者
for sun in `chkconfig --list|grep :启用|awk '{print $1}'`;do chkconfig --level $sun off;done
for sun in crond rsyslog sshd network;do chkconfig --level $sun on;done
for sun in crond rsyslog sshd network iptables ip6tables;do chkconfig --level $sun on;done



[root@realserver1 ~]# vim /etc/sysctl.conf
net.ipv4.ip_forward =
net.ipv4.conf.default.rp_filter =
net.ipv4.conf.default.accept_source_route =
kernel.sysrq =
kernel.core_uses_pid =
net.ipv4.tcp_syncookies = #可以加强对抗SYN Flood的能力
kernel.msgmnb =
kernel.msgmax =
kernel.shmmax =
kernel.shmall =
net.ipv4.tcp_max_tw_buckets =
net.ipv4.tcp_sack =
net.ipv4.tcp_window_scaling =
net.ipv4.tcp_rmem =
net.ipv4.tcp_wmem =
net.core.wmem_default =
net.core.rmem_default =
net.core.rmem_max =
net.core.wmem_max =
net.core.netdev_max_backlog =
net.core.somaxconn =
net.ipv4.tcp_max_orphans =
net.ipv4.tcp_max_syn_backlog =
net.ipv4.tcp_timestamps =
net.ipv4.tcp_synack_retries =
net.ipv4.tcp_syn_retries =
net.ipv4.tcp_tw_recycle =
net.ipv4.tcp_tw_reuse =
net.ipv4.tcp_mem =
net.ipv4.tcp_fin_timeout =
net.ipv4.tcp_keepalive_time =
net.ipv4.ip_local_port_range =
[root@realserver1 ~]# sysctl -p #使配置生效
4.1 优化Linux下的内核TCP参数以提高系统性能
- 防止上一次连接中的包迷路后重新出现,影响新的连接(经过2MSL时间后,上一次连接中所有重复的包都会消失)。
- 为了可靠地关闭TCP连接。主动关闭方发送的最后一个ACK(FIN)有可能会丢失,如果丢失,被动方会重新发送FIN,这时如果主动方处于CLOSED状态,就会响应RST而不是ACK。所以主动方要处于TIME_WAIT状态,而不能是CLOSED状态。另外,TIME_WAIT并不会占用很大的资源,除非受到攻击。
netstat -n |awk '/^tcp/ {++S[$NF]} END{for(a in S) print a, S[a]}'
net.ipv4.tcp_fin_timeout =
net.ipv4.tcp_keepalive_time =
net.ipv4.tcp_syncookies =
net.ipv4.tcp_tw_reuse =
net.ipv4.tcp_tw_recycle =
net.ipv4.ip_local_port_range =
net.ipv4.tcp_max_syn_backlog =
net.ipv4.tcp_max_tw_buckets =
说明:
net.ipv4.tcp_syncookies =
net.ipv4.tcp_tw_reuse =
net.ipv4.tcp_tw_recycle =
net.ipv4.ip_local_port_range =
执行以下命令使配置生效:/sbin/sysctl -p
net.ipv4.tcp_fin_timeout =
net.ipv4.tcp_keepalive_time =
net.ipv4.tcp_tw_reuse =
net.ipv4.tcp_tw_recycle =
net.ipv4.ip_local_port_range =
kernel.shmmax =
yum install -y ntpdate
crontab -e
crontab -l */ * * * * /usr/sbin/ntpdate s2m.time.edu.cn &> /dev/null
系统时间更新和设定定时任务 第一种:更新时间并且写入BOIS
ntpdate s2m.time.edu.cn && hwclock -w && hwclock --systohc


# 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
重启生效,也可以不修改配置文件临时生效,但不建议这样设置,因为重启后会失效。
Port
Protocol
PermitRootLogin no
UseDNS no
cat /etc/redhat-release
cat /etc/issue
#清理登陆信息
echo >/etc/redhat-release
echo >/etc/issue
userdel adm
userdel lp
userdel sync
userdel shutdown
userdel halt
userdel news
userdel uucp
userdel operator
userdel games
userdel gopher
userdel ftp
#删除不必要的群组
groupdel adm
groupdel lp
groupdel news
groupdel uucp
groupdel games
groupdel dip
groupdel pppusers
#注释掉
#exec /sbin/shutdown -r now "Control-Alt-Deletepressed"
12、设置一些全局变量
#设置自动退出终端,防止非法关闭ssh客户端造成登录进程过多,可以设置大一些,单位为秒
echo "TMOUT=3600">> /etc/profile
#历史命令记录数量设置为100条
sed -i "s/HISTSIZE=1000/HISTSIZE=10/" /etc/profile
#立即生效
source /etc/profile
13、设置history历史记录
echo '
export HISTFILE=$HOME/.bash_history
export HISTSIZE=
export HISTFILESIZE=
export HISTTIMEFORMAT="%F %T `whoami` "
export PROMPT_COMMAND="history -a; history -c; history -r;"
shopt -s histappend
typeset -r PROMPT_COMMAND
typeset -r HISTTIMEFORMAT ' > /etc/profile.d/history.sh
source /etc/profile
14、centos6.4最小化安装后启动网卡
#centos6.x最小化安装后,网卡默认不是启动状态
ifup eth0
15、添加普通用户,设置sudo权限
username='zuoyang'
password='zuoyang2016'
useradd $username ; echo $password | passwd --stdin $username
sed -i "98 a$username ALL=(ALL) NOPASSWD: ALL" /etc/sudoers
16、禁止root远程用户登录
sed -i 's/#PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config
17、sed修改远程端口
sed -i 's/#Port 22/Port 9527/' /etc/ssh/sshd_config
/etc/init.d/sshd restart
18、防火墙iptables配置
/etc/init.d/iptables restart
iptables -F
iptables -X
iptables -Z
iptables -A INPUT -p icmp -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT
#允许某个IP段远程访问ssh
iptables -A INPUT -p tcp -m tcp --dport -s 192.168.64.0/ -j ACCEPT
#开启80端口
iptables -A INPUT -P tcp -m tcp --dropt -j ACCEPT
#允许某个IP的所有请求
iptables -A INPUT -p all -s 124.43.56.90/ -j ACCEPT
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
iptables -P FORWARD DROP
/etc/init.d/iptables save
/etc/init.d/iptables restart
19、修改默认DNS
echo "nameserver 223.5.5.5" > /etc/resolv.conf
echo "nameserver 223.6.6.6" >> /etc/resolv.conf
20、安装必要软件,更新yum源 [epel源]
#根据个人公司情况,这里只列举了自己常用的软件和yum源,根据实际情况更改yum源
yum -y install gcc gcc-c++ openssl-devel openssh-clients wget make lrzsz unzip zip xz ntpdate lsof telnet epel-release vim tree kernel-devel kernel
21、更新内核和软件到最新版本
yum -y upgrade
22、去除上次登录的信息
touch ~/.hushlogin
23、优化内核参数 [根据实际情况调整]
echo -e "net.core.somaxconn = 262144" >> /etc/sysctl.conf
echo -e "net.core.netdev_max_backlog = 262144" >> /etc/sysctl.conf
echo -e "net.core.wmem_default = 8388608" >> /etc/sysctl.conf
echo -e "net.core.rmem_default = 8388608" >> /etc/sysctl.conf
echo -e "net.core.rmem_max = 16777216" >> /etc/sysctl.conf
echo -e "net.core.wmem_max = 16777216" >> /etc/sysctl.conf
echo -e "net.ipv4.route.gc_timeout = 20" >> /etc/sysctl.conf
echo -e "net.ipv4.ip_local_port_range = 1024 65535" >> /etc/sysctl.conf
echo -e "net.ipv4.tcp_retries2 = 5" >> /etc/sysctl.conf
echo -e "net.ipv4.tcp_fin_timeout = 30" >> /etc/sysctl.conf
echo -e "net.ipv4.tcp_syn_retries = 1" >> /etc/sysctl.conf
echo -e "net.ipv4.tcp_synack_retries = 1" >> /etc/sysctl.conf
echo -e "net.ipv4.tcp_timestamps = 0" >> /etc/sysctl.conf
echo -e "net.ipv4.tcp_tw_recycle = 1" >> /etc/sysctl.conf
echo -e "net.ipv4.tcp_tw_reuse = 1" >> /etc/sysctl.conf
echo -e "net.ipv4.tcp_keepalive_time = 120" >> /etc/sysctl.conf
echo -e "net.ipv4.tcp_keepalive_probes = 3" >> /etc/sysctl.conf
echo -e "net.ipv4.tcp_keepalive_intvl = 15" >> /etc/sysctl.conf
echo -e "net.ipv4.tcp_max_tw_buckets = 36000" >> /etc/sysctl.conf
echo -e "net.ipv4.tcp_max_orphans = 3276800" >> /etc/sysctl.conf
echo -e "net.ipv4.tcp_max_syn_backlog = 262144" >> /etc/sysctl.conf
echo -e "net.ipv4.tcp_wmem = 8192 131072 16777216" >> /etc/sysctl.conf
echo -e "net.ipv4.tcp_rmem = 32768 131072 16777216" >> /etc/sysctl.conf
echo -e "net.ipv4.tcp_mem = 94500000 915000000 927000000" >> /etc/sysctl.conf
echo -e "net.ipv4.tcp_slow_start_after_idle = 0" >> /etc/sysctl.conf
echo -e "vm.swappiness = 0" >> /etc/sysctl.conf
echo -e "kernel.panic = 5" >> /etc/sysctl.conf
echo -e "kernel.panic_on_oops = 1" >> /etc/sysctl.conf
echo -e "kernel.core_pipe_limit = 0" >> /etc/sysctl.conf
#iptables 防火墙
echo -e "net.nf_conntrack_max = 25000000" >> /etc/sysctl.conf
echo -e "net.netfilter.nf_conntrack_max = 25000000" >> /etc/sysctl.conf
echo -e "net.netfilter.nf_conntrack_tcp_timeout_established = 180" >> /etc/sysctl.conf
echo -e "net.netfilter.nf_conntrack_tcp_timeout_time_wait = 120" >> /etc/sysctl.conf
echo -e "net.netfilter.nf_conntrack_tcp_timeout_close_wait = 60" >> /etc/sysctl.conf
echo -e "net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 120" >> /etc/sysctl.confo
注意:
[history历史记录设置]
有时候我们需要对线上用户操作记录进行历史记录待出现问题追究责任人,但Linux系统自带的history命令用户有自行删除权限,那怎么设置可以让用户的操作记录实时记录,并保证普通用户无权删除呢,具体参考上文history历史记录设置,这里我只列出部分需要注意的事项,后面还要待补充和整理:
. 首先root用户创建的HISTORY_FILE默认情况下只有root用户有rw权限,其它用户只有r的权限,这就导致其它用户的操作记录无法写入,需要将HISTORY_FILE赋予所有的读写权限。
. export PROMPT_COMMAND 如果将PROMPT_COMMAND导出到用户工作区,那么对于有经验的用户就可以做赋值操作 export PROMPT_COMMAND =“” ,简单的语法就会导致记录功能当前session端不可用,所以PROMPT_COMMAND必须设置成只读的属性,readonly PROMPT_COMMAND,但是这里只显示了命令,并没有显示执行命令的时间,因为保存历史命令的~/.bash_history里并没有保存时间。通过设置环境变量 export HISTTIMEFORMAT="%F %T `whoami` " 给history加上时间戳可以看到,历史命令的时间,用户已经加上了,但是.bash_history里并没有加上这个时间。
Centos 6.4 x86_64 最小化安装后的优化——还需要整理的更多相关文章
- Centos 6.4最小化安装后的优化(1)
一.更新yum官方源 Centos 6.4系统自带的更新源速度比较慢,相比各位都有所感受,国内的速度慢的让人受不了.为了让centos6.4系统使用速度更快的yum更新源,一般都会选择更换源,详细步骤 ...
- Centos 6.4最小化安装后的优化(2)
1.关闭不必要的服务 众所周知,服务越少,系统占用的资源就会越少,所以应当关闭不需要的服务器.首先可以先看下系统中存在哪些已经开启了的服务.查看命令如下: ntsysv 下面列出的是需要启动的服务器, ...
- 生产服务器环境最小化安装后 Centos 6.5优化配置[转]
内容目录 centos6.5最小化安装后配置网络: IP地址, 网关, 主机名, DNS 更新系统源并且升级系统 系统时间更新和设定定时任 创建普通用户并进行sudo授权管理 修改SSH端口号和屏蔽r ...
- CentOS 6,7最小化安装后再安装图形界面
CentOS 6.2最小化安装后再安装图形界面 在安装CentOS 6.2时发现它没有提示我要怎么安装,而是“自作主张”地给我选择了最小化安装,结果装完之后只有终端界面,因为有时候不得不用图形界面,所 ...
- 生产服务器环境最小化安装后 Centos 6.5优化配置备忘
生产服务器环境最小化安装后 Centos 6.5优化配置备忘 作者:Memory 发布于:2014-8-13 15:00 Wednesday 服务器 本文 centos 6.5 优化 的项有18处: ...
- 生产服务器环境最小化安装后Centos 6.5优化配置备忘
生产服务器环境最小化安装后 Centos 6.5优化配置备忘 本文 centos 6.5 优化 的项有18处,列表如下: 1.centos6.5最小化安装后启动网卡 2.ifconfig查询IP进行S ...
- 【深入学习linux】CentOS 7 最小化安装后的注意事项及一些必备组件的安装
转载:https://blog.csdn.net/F_Srion/article/details/54910943 在VM虚拟机中安装CentOS 7 时 有时候顾虑到电脑硬件性能,我们需要最小化安装 ...
- CentOS 7 最小化安装后的注意事项
http://blog.csdn.net/f_srion/article/details/54910943 在VM虚拟机中安装CentOS 7 时 有时候顾虑到电脑硬件性能,我们需要最小化安装,而最小 ...
- Centos 7最小化安装后配置
关闭SELINUX vi /etc/sysconfig/selinux SELINUX=disabled :wq 配置网卡(最小化安装后ifconfig无法使用),该配置的前提是采用 NAT模式 vi ...
随机推荐
- VS2010远程调试C#程序
场景: 客户的计算机运行程序出现异常,由于办公场所不在一起,无法直接在客户的机器上调试.此时希望可以直接在开发人员的计算机(本地机器)上远程调试客户机上的软件. 假设: 本地机器的系统账户为 GIS, ...
- 分布式任务队列 Celery —— 详解工作流
目录 目录 前文列表 前言 任务签名 signature 偏函数 回调函数 Celery 工作流 group 任务组 chain 任务链 chord 复合任务 chunks 任务块 mapstarma ...
- Nginx1.8源码包编译安装
1.下载解压Nginx,为方便管理下载包一般将下载包放在指定目录下 ,即/usr/local/src/下. wget http://nginx.org/download/nginx-1.8.0.tar ...
- 中国MOOC_零基础学Java语言_期末考试的编程题_1二进制的前导的零
期末考试的编程题 返回 这是期末考试的编程题,在60分钟内,你可以多次提交,直到正确为止. 温馨提示: 1.本次考试属于Online Judge题目,提交后由系统即时判分. 2.学生可以在考试截止 ...
- 干货 | 剑指offer系列文章汇总
下面是名企面试中经常会出现的面试题目,大家可以戳相应的题目查看题目细节,其答案会在紧接着的后一篇中出现 剑指offer系列 始 剑指offer—灯管问题(1) 剑指offer—10人电梯(2) ...
- 那些堪称神器的 Chrome 插件
Chrome 的简洁快速以及丰富的插件种类使得它在国内日益盛行,帮助了我们很多 Chrome 用户提升了工作效率,而今天要给大家推荐8款实用甚至堪称神器的 Chrome 插件,希望对提升大家的工作效率 ...
- vimiumC的下载、配置与节点个性化
vimium是chrome的一款扩展程序,正如其名:vim+chromium,它能让你在浏览网页时双手不离开键盘,是提上网高效率的神器. 最近在使用中,非常便捷高效,但关于节点的个性化资料比较少,自己 ...
- Windows.etc\hosts文件
ZC:就是将 后面的项 重定位到 前面的项 1.目录:"C:\Windows\System32\drivers\etc" 文件:"C:\Windows\System32\ ...
- C#银行卡号每隔4位数字加一个空格
1.填写银行卡号每隔4位数字加一个空格 Regex.Replace(dic["BankCardNo"].ToString(), @"(\d{4}(?!$))", ...
- linux--vm安装
网络排错图解 https://www.linuxidc.com/Linux/2017-03/141863.htm net模式 https://www.linuxidc.com/Linux/2017-0 ...