Linux之——CentOS6 最小化安装优化

转载请注明出处:https://blog.csdn.net/l1028386804/article/details/80188532

一:网络改成静态

vim /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0
HWADDR=00:0C:29:E4:2D:AD
TYPE=Ethernet
UUID=6a5e3936-04f3-479e-bfb2-4a282b8e01ee
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=xxxxx
NETMASK=255.255.255.0
GATEWAY=xxxxx
DNS1=202.98.96.68
DNS2=61.139.2.69重启网卡:

/etc/init.d/network restart

二:安装包组

安装包组,常用软件,升级系统(可选),更改为阿里源或者官方源地址
(1)更改为官网源地址或者阿里源

安装官方epel:

yum install epel-release -y
配置yum阿里源:
yum install -y wget
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
rpm –import /etc/pki/rpm-gpg/RPM-GPG-KEY*
yum clean all
yum makecache
(2)安装包组
如果安装过程落了部分包组或者其他伙伴安装时没选,再安装后可以按如下方式补上安装时未安装的包组:
yum groupinstall “Compatibility libraries” “Base” “Development tools”
yum groupinstall “debugging Tools” “Dial-up Networking Support"
可以通过yum groupinfo 包组查看具体安装的组件。
(3)查看选包的情况

下面安装6.5后登陆系统的时候查看选包的情况:

yum grouplist:
Installed Groups:
Base
Compatibility libraries
Debugging Tools
Development tools
(4)升级系统或者系统核心
yum upgrade -y
yum update -y
(5)安装常用软件
yum install lrzsz ntpdate sysstat nmap telnet vim-enhanced tree dos2unix nc-y

三:更改字符集为EN

sed -i ‘s#LANG=“zh_CN.UTF-8”#LANG=“en_US.UTF-8”#g’ /etc/sysconfig/i18n
source /etc/sysconfig/i18n
echo $LANG

四:优化开机启动项

for i in chkconfig --list|grep 3:on|egrep -v <span class="hljs-string">"network|crond|rsyslog|sshd|sysstat"</span>|awk <span class="hljs-string">'{print $1}'</span>;do chkconfig KaTeX parse error: Expected 'EOF', got '#' at position 223: …hljs-string">'s#̲SELINUX=enforci…(history 1 | { read x y; echo KaTeX parse error: Expected 'EOF', got '}' at position 4: y; }̲);logger <span …(whoami)]”:
     
     
      
       
        
        
          ( 
         
        
          w 
         
        
          h 
         
        
          o 
         
        
          a 
         
        
          m 
         
        
          i 
         
        
          ) 
         
        
          : 
         
        
          [ 
         
        
          ‘ 
         
        
          p 
         
        
          w 
         
        
          d 
         
        
          ‘ 
         
        
          ] 
         
        
          < 
         
        
          s 
         
        
          p 
         
        
          a 
         
        
          n 
         
        
          c 
         
        
          l 
         
        
          a 
         
        
          s 
         
        
          s 
         
        
          = 
         
        
          " 
         
        
          h 
         
        
          l 
         
        
          j 
         
        
          s 
         
        
          − 
         
        
          s 
         
        
          t 
         
        
          r 
         
        
          i 
         
        
          n 
         
        
          g 
         
        
          " 
         
        
          > 
         
        
          " 
         
        
       
         (who am i):[`pwd`]<span class="hljs-string">" 
        
      
     
     (whoami):[pwd]<spanclass="hljsstring">"msg"; }'
给grep增加颜色,给PS1添加颜色:
vim /etc/profile.d/oneinstack.sh
PS1="[\e[37;40m][[\e[32;40m]\u[\e[37;40m]@\h [\e[35;40m]\W[\e[0m]]\$ "

alias l=‘ls -AFhlt’
alias lh=‘l | head’
alias vi=vim

GREP_OPTIONS="–color=auto"
alias grep=‘grep --color’
alias egrep=‘egrep --color’
alias fgrep=‘fgrep --color’

source /etc/profile.d/oneinstack.sh

十:变更默认的ssh服务端口,禁止root用户远程连接

cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
vim /etc/ssh/sshd_config

Port 52113 #ssh连接默认的端口
PermitRootLogin no #root用户黑客都知道,禁止它远程登录
PermitEmptyPasswords no #禁止空密码登录
UseDNS no #不使用DNS

/etc/init.d/sshd reload #从新加载配置
netstat -lnt #查看端口信息
lsof -i tcp:52113

十一:锁定关键文件系统

chattr +i /etc/passwd
chattr +i /etc/inittab
chattr +i /etc/group
chattr +i /etc/shadow
chattr +i /etc/gshadow

十二:内核参数优化

说明:本优化适合apache,nginx,squid多种等web应用,特殊的业务也可能需要略作调整
vim /etc/sysctl.conf
#by sun in
net.ipv4.tcp_fin_timeout = 2
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_keepalive_time =600
net.ipv4.ip_local_port_range = 4000 65000
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.tcp_max_tw_buckets = 36000
net.ipv4.route.gc_timeout = 100
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_synack_retries = 1
net.core.somaxconn = 16384
net.core.netdev_max_backlog = 16384
net.ipv4.tcp_max_orphans = 16384
#一下参数是对iptables防火墙的优化,防火墙不开会有提示,可以忽略不理。
net.nf_conntrack_max = 25000000
net.netfilter.nf_conntrack_max = 25000000
net.netfilter.nf_conntrack_tcp_timeout_established = 180
net.netfilter.nf_conntrack_tcp_timeout_time_wait = 120
net.netfilter.nf_conntrack_tcp_timeout_close_wait = 60
net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 120
sysctl –p #使配置文件生效
6.4版本上
error: "net.nf_conntrack_max"isan unknown key
error: "net.netfilter.nf_conntrack_max"isan unknown key
error: "net.netfilter.nf_conntrack_tcp_timeout_established"isan unknown key
error: "net.netfilter.nf_conntrack_tcp_timeout_time_wait"isan unknown key
error: "net.netfilter.nf_conntrack_tcp_timeout_close_wait"isan unknown key
error: "net.netfilter.nf_conntrack_tcp_timeout_fin_wait"isan unknown key
这个错误可能是你的防火墙没有开启或者自动处理可载入的模块ip_conntrack没有自动载入,解决办法有二,一是开启防火墙,二是自动处理载入的模块ip_conntrack
modprobe nf_conntrack
echo “modprobe nf_conntrack”>> /etc/rc.local
6.4版本上
error: "net.bridge.bridge-nf-call-ip6tables"isan unknown key
error: "net.bridge.bridge-nf-call-iptables"isan unknown key
error: "net.bridge.bridge-nf-call-arptables"isan unknown key
这个错误是由于自动处理可载入的模块bridge没有自动载入,解决办法是自动处理载入的模块bridge
modprobe bridge
echo “modprobe bridge”>> /etc/rc.local

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值