当前位置: 首页 > news >正文

linux 优化


title: linux 优化
tags: linux,优化,新装


linux 优化

1 登录安全

清空/etc/issue,/etc/issue.net,/etc/motd。因为issue文件是系统的版本号信息,当登录到系统的时候会进行提示,motd文件在登录时会显示里面的字符串,可能包含敏感字符。

[root@server tmp]# > /etc/motd
[root@server tmp]# >/etc/issue
[root@server tmp]# >/etc/issue.net

2 更改主机名:

临时更改:hostname maiyat
永久更改: vi /etc/sysconfig/network
主机名和ip做好映射:vi /etc/hosts
DNS地址在/etc/resolv.conf,但是因为它是全局的,因此优先级比网卡的配置文件低一点。

[root@server tmp]# cat /etc/hosts
#127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1       server
192.168.50.1    server
192.168.50.2    lamp02
192.168.50.3    lamp01
[root@server tmp]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=server
[root@server tmp]# hostname server
[root@server tmp]# cat /etc/resolv.conf 
; generated by /sbin/dhclient-script
search localdomain
nameserver 192.168.211

3 安装时最小化安装,及启动必要的服务

因为系统安装最小化安装,所以以下包请注意安装:
yum install tree telnet dos2unix sysstat lrzsz vim man
以下5项服务建议开机启动:systat,rsyslog,sshd,crond,network,其余服务一并关闭,待需要的时候在打开。

[root@server tmp]# for n in `chkconfig --list |grep 3:on|awk -F " " '{print $1}'`; do chkconfig $n off;done && for n in sysstat rsyslog sshd crond network;do chkconfig $n on;done
[root@server tmp]# 
[root@server tmp]# 
[root@server tmp]# chkconfig --list |grep 3:on
crond           0:off   1:off   2:on    3:on    4:on    5:on    6:off
network         0:off   1:off   2:on    3:on    4:on    5:on    6:off
rsyslog         0:off   1:off   2:on    3:on    4:on    5:on    6:off
sshd            0:off   1:off   2:on    3:on    4:on    5:on    6:off
sysstat         0:off   1:on    2:on    3:on    4:on    5:on    6:off
或者
[root@server tmp]# for n in `chkconfig --list |grep 3:on|egrep -v "sysstat|rsyslog|sshd|crond|network"|awk -F " " '{print $1}'`;do chkconfig $n off;done 

4 最好把/etc/rc.local当作系统开机启动的档案管理

因为相对于chkconfig --list管理的启动项有很多是系统的,但是rc.local里的启动都是用户自己添加进去的,当一个公司的运维把设备上的服务启动都追加到rc.local里,并注释清楚,这样当该运维离职后,后面来的人只要看一下rc.local里就可以清楚的知道该服务器启动了一什么服务了。

[root@server tmp]# /etc/init.d/smb start >> /etc/rc.local
[root@server tmp]# /etc/init.d/dhcpd start >> /etc/rc.local
[root@server tmp]# /etc/init.d/rpcbind start >> /etc/rc.local  [root@server tmp]# /etc/init.d/nfs start >> /etc/rc.local   

5 关闭selinux

[root@server tmp]# cp /etc/selinux/config /etc/selinux/config.org
[root@server tmp]# sed -i 's#SELINUX=enforcing#SELINUX=disable#g' /etc/selinux/config
[root@server tmp]# grep SELINUX=disable /etc/selinux/config
SELINUX=disable

因为关闭selinux需要重启系统,因此可以临时更改如

[root@server tmp]# setenforce 0
[root@server tmp]# getenforce 
Permissive

5 重要文件加锁(防止***黑进系统后提权)

[root@server ~]# chattr +i /etc/passwd /etc/shadow /etc/group /etc/gshadow       
[root@server ~]# chattr -i /etc/passwd /etc/shadow /etc/group /etc/gshadow
[root@server ~]# mv /usr/bin/chattr ~/cha

6 文件描述符(ulimit -n)

当一个进程启用就会占用一个文件描述符,一般最大有65535个,而系统默认只有1024个
临时设置: [root@server ~]# ulimit -SHn 65535
永久设置:

[root@server ~]# echo ' * - nofile 65535 ' >> /etc/security/limits.conf 
[root@server ~]# ulimit -n
65535

7 字符集,配置文件在/etc/sysconfig/i18n

LANG="en_US.UTF-8" 或 "LANG=zh_CN.UTF-8"

8 同步时钟:

yum install ntp -y
ntpdate 1.cn.pool.ntp.org
crontab -e
*/20 * * * * ntpdate 1.cn.pool.ntp.org
crontab -l
其中crontab的配置文件在/var/spool/cron/root
因此可以:
echo '*/20 * * * * ntpdate 1.cn.pool.ntp.org' >>/var/spool/cron/root

9 及时清理sendmail临邮件存放目录

find /var/spool/clientmqueue -type f |xargs rm -f

10 设置300秒不使用进入超时

export TMOUT=300
echo "export TMOUT=300" >>/etc/profile

11 平时登录系统时使用普通用户

当权限不够时使用su - 进行切换,平时设置可以配置sudo,其中配置文件为 /etc/sudoers ,编辑时最好使用visudo

## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
ouyan   ALL=(ALL)       ALL
ouyan   ALL=(ALL)       NOPASSWD: ALL
test    ALL=(ALL)       NOPASSWD: /usr/sbin/useradd, /usr/bin/passwd
root    ALL=(ALL)       ALL
root    ALL=(ALL)       ALL

[root@server ~]# visudo -c

其中visudo检查visudo的语法,其中 NOPASSWD: buxu
不需要密码,/usr/sbin/useradd可以使用的命令,如果是ALL,则可以shiy使用所有命令

12 升级最新补丁

yum update
yum install openssl  bash -y

注意yum update是全部升级,一定要新装系统才可以执行这个

13 注意/proc里查看系统信息

[root@server proc]# ls -l meminfo cpuinfo mounts loadavg ioports filesystems devices 
-r--r--r--. 1 root root  0 May 18 01:12 cpuinfo
-r--r--r--. 1 root root  0 May 18 01:12 devices
-r--r--r--. 1 root root  0 May 18 01:12 filesystems
-r--r--r--. 1 root root  0 May 18 01:12 ioports 正在使用的端口
-r--r--r--. 1 root root  0 May 18 01:12 loadavg 负载信息
-r--r--r--. 1 root root  0 May 18 01:12 meminfo
lrwxrwxrwx. 1 root root 11 May 18 01:12 mounts -> self/mounts

14 禁ping

不过要小心处理,虽然可以防止ping***,但是自己调试也不方便,一般用防火墙
echo " net.ipv4.icmp_eth0_ignore_all=1" &gt;&gt;/etc/sysctl.conf<br/>sysctl -p 配置生效

转载于:https://blog.51cto.com/ouyangtao/2120673

相关文章:

  • [Pyhton]weakref 弱引用
  • python之线程和进程(并发编程)
  • Linux系统小技巧(3):sar、last和dmesg的时间戳选项
  • Hibernate-ORM:07.Hibernate中的参数绑定
  • 老男孩教育每日一题-第96天-网站并发知识点:pv-并发与架构设计基础知识
  • Notepad++ 添加MarkdownViewerPlusPlus插件
  • ORACLE查询树型关系start with connect by prior
  • CentOS7安装Python3
  • 漂亮的css
  • 文件操作
  • fetch 从初识到应用
  • oreo自适应图标
  • 容器服务--如何在阿里云容器服务上运行基于TensorFlow的Alexnet
  • centos6.x完全禁用IPv6的方法
  • 细说地方门户网站运营的六大经验
  • 《网管员必读——网络组建》(第2版)电子课件下载
  • 【node学习】协程
  • 08.Android之View事件问题
  • 2017 年终总结 —— 在路上
  • Bytom交易说明(账户管理模式)
  • Javascripit类型转换比较那点事儿,双等号(==)
  • JavaScript 事件——“事件类型”中“HTML5事件”的注意要点
  • Js基础——数据类型之Null和Undefined
  • LeetCode算法系列_0891_子序列宽度之和
  • 不用申请服务号就可以开发微信支付/支付宝/QQ钱包支付!附:直接可用的代码+demo...
  • 基于阿里云移动推送的移动应用推送模式最佳实践
  • 两列自适应布局方案整理
  • 前端面试之闭包
  • 如何正确配置 Ubuntu 14.04 服务器?
  • 通过git安装npm私有模块
  • 优秀架构师必须掌握的架构思维
  • 字符串匹配基础上
  • ​LeetCode解法汇总2182. 构造限制重复的字符串
  • ​MySQL主从复制一致性检测
  • #pragma data_seg 共享数据区(转)
  • $ is not function   和JQUERY 命名 冲突的解说 Jquer问题 (
  • (C语言)字符分类函数
  • (分布式缓存)Redis哨兵
  • (附源码)基于ssm的模具配件账单管理系统 毕业设计 081848
  • (三)uboot源码分析
  • (四)图像的%2线性拉伸
  • (一)Dubbo快速入门、介绍、使用
  • (一)pytest自动化测试框架之生成测试报告(mac系统)
  • (一)RocketMQ初步认识
  • (转)es进行聚合操作时提示Fielddata is disabled on text fields by default
  • (转)关于pipe()的详细解析
  • ***检测工具之RKHunter AIDE
  • **PHP分步表单提交思路(分页表单提交)
  • .NET 依赖注入和配置系统
  • .NET(C#) Internals: as a developer, .net framework in my eyes
  • .NET面试题解析(11)-SQL语言基础及数据库基本原理
  • .NET企业级应用架构设计系列之结尾篇
  • @EnableWebMvc介绍和使用详细demo
  • @RestController注解的使用
  • [2013][note]通过石墨烯调谐用于开关、传感的动态可重构Fano超——