01-linux基础优化与安全重点总结

linux基础优化与安全重点总结java

1. 不用root 登陆,添加普通用户,用sudo受权管理

[root@centos6 ~]#useradd liuwei  添加用户

[root@centos6 ~]# vi /etc/sudoers

在第98行下面加入

root    ALL=(ALL)       ALL

liuwei   ALL=(ALL)      /bin/ls ,/bin/cat   //这个是给liuwei这个用户 添加  /bin/ls ,/bin/cat 这两个命令的执行权限

 

2.更改默认的远程链接SSH服务端口和禁止root远程登陆

[root@centos6 ~]# vi /etc/ssh/sshd_config

#       $OpenBSD: sshd_config,v 1.80 2008/07/02 02:24:18 djm Exp $

# This is the sshd server system-wide configuration file.  See

# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin

# The strategy used for options in the default sshd_config shipped with

# OpenSSH is to specify options with their default value where

# possible, but leave them commented.  Uncommented options change a

# default value.

#下面这是把22端口更改52113

Port 52113  

#这是不容许远程登陆

PermitRootLogin no

#这个不是不容许空密码

PermitEmptyPasswords no

#不用DNS

UseDNS no

GSSAPIAuthentication no

3.定时更新服务器时间

#confab -e
进入cronta编辑模式,使用方法同vi
输入 0 23 * * * ntpdate asia.pool.ntp.org >> /var/log/ntpdate.log
保存退出
这样就完成了你的系统到天天23:00去asia.pool.ntp.org 同步时间,并将同步的日志放到
/var/log/ntpdate.log



3、定时同步时间(在/etc/crontab中添加)

 * * * * * /usr/sbin/ntpdate 210.72.145.44 > /dev/null 2>&1

 

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

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

(若提示wget 命令不存在,则先使用yum install wget命令进行安装操做)node

5.关闭selinux关闭iptables(工做场景有wan ip 通常要开,高并发除外)

修改/etc/selinux/config 文件

将SELINUX=enforcing改成SELINUX=disabled

重启机器便可(注意:生产环境中通常不能随便重启机器)

setenforce 更改selinux状态

setenforce 0 #设置SELinux 成为permissive模式

setenforce 1 设置SELinux 成为enforcing模式

getenforce 也能够用这个命令检查



/etc/init.d/iptables status 会获得一系列信息,说明防火墙开着。

/etc/init.d/iptables stop 关闭防火墙

service iptables restart 重启iptables

/etc/init.d/iptables restart     重启iptables

1.重启后永久性生效:

  开启:chkconfig iptables on

  关闭:chkconfig iptables off

2. 即时生效,重启后失效:

  开启:service iptables start

  关闭:service iptables stop

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

[root@centos6 ~]# ulimit –n  查看描述符数量

65535

怎么调整

vim /etc/security/limits.cof

把下面一句加到文件的最后一行

*              -       nofile          65535

或者:

ech0 '*              -       nofile          65535'  >> /etc/security/limits.cof

7.定时清理 /var/spool/clientmquene/目录垃圾文件,防止inodes节点占满

8.精简开机启动服务(crod,sshd,network,rsyslog)

for name in ‘chkconfig --list | grep –vE “crond|sshd|network|rsyslog”|awk ‘{print $1}’’;

do chkconfig &name off;done

9.linux 内核参数优化 /etc/sysctl.conf,执行sysctl p 生效

 首先打开/etc/sysctl.conf文件,查看以下两行的设置值,这里是:

  kernel.shmall = 2097152

kernel.shmmax = 4294967295

 若是系统默认的配置比这里给出的值大,就不要修改原有配置。

同时在/etc/sysctl.conf文件最后,添加如下内容:

  fs.file-max = 6553600

  kernel.shmmni = 4096

  kernel.sem = 250 32000 100 128

  net.ipv4.ip_local_port_range = 1024 65000

  net.core.rmem_default = 4194304

  net.core.rmem_max = 4194304

  net.core.wmem_default = 262144

  net.core.wmem_max = 262144

  这里的“fs.file-max = 6553600”实际上是由“fs.file-max = 512 * PROCESSES”获得的,咱们指定PROCESSES的值为12800,即为“fs.file-max =512 *12800”。

  sysctl.conf文件修改完毕后,接着执行“sysctl -p”使设置生效。

10,更改字符集,支持中文,可是建议仍是用英文字符 防止乱码

解决中文问题

[liuwei@centos6 ~]$ vi /etc/sysconfig/i18n

改为这个

LANG=zh_CN.UTF-8

[liuwei@centos6 ~]$source /etc/sysconfig/i18n

 

11.锁定关键系统文件

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



[root@centos6 ~]# chattr +i /etc/passwd /etc/shadow 给这个两个文件加上锁

[root@centos6 ~]# useradd liu

useradd: cannot open /etc/passwd

[root@centos6 ~]# chattr -i /etc/passwd /etc/shadow     给这个两个文件加解锁

[root@centos6 ~]# useradd liu



[root@centos6 ~]# chattr -i /etc/passwd /etc/shadow   把这个加锁命令移动一下【由于你们都知道这个是解锁的命令】

-bash: /usr/bin/chattr: 没有那个文件或目录

[root@centos6 ~]# mv /usr/bin/liuwei /usr/bin/chattr

范例:linux

# chattr +i .bash_logout     ——>添加一个隐藏的“i”属性,后面再细讲vim

#lsattr -a             ——>将当前目录的文件或目录下的文件全部属性(包括隐藏属性)列出 centos

-------------- ./.安全

-------------- ./..bash

---i---------- ./.bash_logout服务器

-------------- ./.bash_profile并发

-------------- ./.bashrcssh

 

 

12,清空 /etc/issue ,去除系统以及内核版本登陆前的版本提示

[root@centos6 ~]# > /etc/issue    隐藏系统的版本信息

[root@centos6 ~]#

 

13.实战经验分享(属用性能调优) 
 

Linux 用户线程数限制致使的 java.lang.OutOfMemoryError: unable to create new native thread
异常
# vi /etc/security/limits.d/90-nproc.conf
# Default limit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning.
root soft nproc unlimited
* soft nproc 20480
相关文章
相关标签/搜索