linux运维、架构之路-linux基础优化

时间:2023-03-08 23:27:26
linux运维、架构之路-linux基础优化

1、查看linux版本

cat /etc/redhat-release 
#CentOS release 6.9 (Final) ————>查看版本号
uname -m
#x86_64 ————>查看系统64位/32位
uname -r
#2.6.-.el6.x86_64 ——————>内核版本

2、关闭selinux和iptables

sed -i 's#=enforcing#=disabled#g' /etc/selinux/config
setenforce #——————>临时关闭
getenforce /etc/init.d/iptables stop
chkconfig iptables off

3、更改字符集,支持中文,但不建议最好用英文字符集,防止乱码问题

echo $LANG
en_US.UTF- #——————>查看系统字符集是否正确 LANG=en
export LANG=en_US.utf8 #—————>临时生效解决中文乱码
echo "LANG=en_US.utf8" >/etc/sysconfig/i18n #——————>永久生效
source /etc/sysconfig/i18n #——————>立即让配置文件生效

4、精简开机自启动服务

export LANG=en
chkconfig|egrep -v "crond|sshd|network|rsyslog|sysstat"|awk '{print "chkconfig",$1,"off"}'|bash
chkconfig --list|grep :on

5、时间同步

echo '#time sync by yan* at 2017-01-01' >>/var/spool/cron/root
echo '*/5 * * * * /usr/sbin/ntpdate pool.ntp.org >/dev/null 2>&1' >>/var/spool/cron/root
crontab -l

6、更改yum源

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

7、加大文件描述符

echo '*               -       nofile          65535 ' >>/etc/security/limits.conf

8、linux内核优化

cat >>/etc/sysctl.conf<<EOF
net.ipv4.tcp_fin_timeout =
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 =
#以下参数是对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
sysctl -p

9、SSH连接速度优化

sed -i.bak 's@#UseDNS yes@UseDNS no@g;s@^GSSAPIAuthentication yes@GSSAPIAuthentication no@g'  /etc/ssh/sshd_config
/etc/init.d/sshd reload

10、常用小工具安装

yum install lrzsz nmap tree dos2unix nc telnet -y

11、通过sudo提权普通用户管理

useradd oldboy
echo |passwd --stdin oldboy
\cp /etc/sudoers /etc/sudoers.ori
echo "oldboy ALL=(ALL) NOPASSWD: ALL " >>/etc/sudoers
tail - /etc/sudoers
visudo -c