Linux系统一些基础优化

Linux基础优化小结:

01)不用root,添加普通用户,通过sudo授权管理

02)更改默认的远程连接ssh服务端口及禁止root用户远程连接

03)定时自动更新服务器时间

04)配置yum更新源,从国内更新下载安装rpm包

05)关闭selinux及iptables(有外网需要打开iptables)

06)调整文件描述符的数量,进程及文件的打开都会消耗文件描述符

07)精简开机启动服务(只保留crond,sshd,network,rsyslog等重要的服务)

08)Linux内核参数优化/etc/sysctl.conf,执行sysctl -p生效

09)更改字符集,支持中文,但是建议用英文字符集,防止乱码问题。

10)锁定关键的系统文件

11)清空/etc/issue 去除内核版本登陆前的屏幕信息


1.修改sshd_config

修改sshd_config配置文件,端口0-65535之间

vim /etc/ssh/sshd_config

set nu(行号加gg或者加G,直接定位到指定行)

修改或添加Port 加端口号

PermitRootLogin yes改为no #不让root登陆sshd

PermitEmptyPasswords no 取消#注释,禁止空秘密

UseDNS yes     取消#,改yes为no

GSSAPIAuthentication yes改为no


或者可以不用修改,直接添加内容以下内容

(提醒:首先要创建好普通用户,端口号要需要在防火墙放行,或者关闭防火墙)

Port 52113

PermitRootLogin no

PermitEmptyPasswords no

UseDNS no

GSSAPIAuthentication no


2.修改visudo==/etc/sudoers

root    ALL=(ALL)       ALL

在这root下添加相应用户权限

比如

shnne  ALL=(ALL)   /usr/sbin/useradd,/usr/sbin/userdel


3.临时设置PATH

PATH=/shnne/:$PATH

永久全局生效生效

1)echo 'export PATH="/shnne/:$PATH"' >> /etc/profile

2)直接编辑/etc/profile 添加路径,分号分隔,如  export PATH="$PATH:/shnne"

source /etc/profile 生效

普通用户生效

vim ~/.bash_profile 后面添加或者~/.bashrc添加PATH="$PATH:/shnne"


4.Linux默认的字符集路径

永久生效

/etc/sysconfig/i18n   是数字1

source /etc/sysconfig/i18n 生效

临时生效

echo $LANG

LANG=en_US.UTF-8


5.ntp时间同步服务

可以创建定时的计划任务crond

ntpdate cn.pool.ntp.org 


6.加大文件描述符

ulimit -n 查看

ulimit -HSn 65535 临时生效

vim /etc/security/limits.conf 最后添加

nofile 65535


7.调整内核参数文件/etc/sysctl.conf

net.ipv4.tcp_syn_retries = 1

net.ipv4.tcp_synack_retries = 1

net.ipv4.tcp_keepalive_time = 600

net.ipv4.tcp_keepalive_probes = 3

net.ipv4.tcp_keepalive_intvl =15

net.ipv4.tcp_retries2 = 5

net.ipv4.tcp_fin_timeout = 2

net.ipv4.tcp_max_tw_buckets = 36000

net.ipv4.tcp_tw_recycle = 1

net.ipv4.tcp_tw_reuse = 1

net.ipv4.tcp_max_orphans = 32768

net.ipv4.tcp_syncookies = 1

net.ipv4.tcp_max_syn_backlog = 16384

net.ipv4.tcp_wmem = 8192 131072 16777216

net.ipv4.tcp_rmem = 32768 131072 16777216

net.ipv4.tcp_mem = 786432 1048576 1572864

net.ipv4.ip_local_port_range = 1024 65000

net.ipv4.ip_conntrack_max = 65536

net.ipv4.netfilter.ip_conntrack_max=65536

net.ipv4.netfilter.ip_conntrack_tcp_timeout_established=180

net.core.somaxconn = 16384

net.core.netdev_max_backlog = 16384

sysctl -p  #生效


8.隐藏系统版本

cat /etc/issue

> /etc/issue

或者

cat /dev/null > /etc/issue


9.锁定关键系统文件

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

解锁

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

chattr +a 只能追加,不能做其他操作

lsattr 查看


分享到:
关键词:Linux运维

网友留言(0 条)

发表评论