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 "network|crond|rsyslog|sshd|sysstat"|awk '{print $1}'`;do chkconfig $i off;done

五:关闭selinux,清空iptables

(1)关闭selinux

sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
setenforce 0
getenforce 0

(2)清空iptables

/etc/init.d/iptables stop
iptables -F
/etc/init.d/iptables save

六:调整文件描述符大小

echo -e "*               soft    nofile          65535\n*               hard    nofile          65535" >>/etc/security/limits.conf
ulimit -SHn 65535
ulimit -n

七:时间同步

/usr/sbin/ntpdate time.nist.gov
echo '*/5 * * * * /usr/sbin/ntpdate time.nist.gov >/dev/null 2 >&1' >>/var/spool/cron/root

八:更改主机名

hostname nginx-centos6
echo -e 'NETWORKING=yes\nHOSTNAME=nginx-centos6' >/etc/sysconfig/network

九:更改PS1显示颜色

vim /etc/bashrc 
export PROMPT_COMMAND='{ msg=$(history 1 | { read x y; echo $y; });logger "[euid=$(whoami)]":$(who am i):[`pwd`]"$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

猜你喜欢

转载自blog.csdn.net/l1028386804/article/details/80188532