linux新装系统初始化

摘要:
初始化新的Linux系统1。登录安全2。更改主机名:并启动必要的服务4。最好使用/etc/rc.local作为系统启动5的文件管理。关闭selinux 6。锁定重要文件(防止***进入系统,然后授予权限)7。文件描述符(ulimit-n)8。字符集,
linux新装系统初始化

系统新装的时候建议进行的初始化,以及以后每个主机安装系统的模版设置,比如最小化安装及启动必要的服务,统一的sudo配置,比如利用/etc/rc.local当作系统开机启动的档案管理等等。

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

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

[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

7. 文件描述符(ulimit -n)

当一个进程启用就会占用一个文件描述符,一般最大有65535个,而系统默认只有1024个
临时设置:

[root@server ~]# ulimit -SHn 65535

永久设置:

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

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

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

9. 同步时钟:

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

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

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

11. 设置300秒不使用进入超时

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

12. 平时登录系统时使用普通用户

当权限不够时使用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使用所有命令

13. 升级最新补丁

yum update
yum install openssl  bash -y

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

14. 注意/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

15. 禁ping

不过要小心处理,虽然可以防止ping***,但是自己调试也不方便,一般用防火墙

echo " net.ipv4.icmp_eth0_ignore_all=1" >>/etc/sysctl.conf
sysctl -p 配置生效 

免责声明:文章转载自《linux新装系统初始化》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇SQL Server常用语句windows时间函数下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

yii2 下的redis常用命令集合

<?php Yii::$app->redis->set('user','aaa'); Yii::$app->redis->set('user2','bbb'); Yii::$app->redis->set('user3','ccc'); Yii::$app->redis->set('us...

element-ui 树形表格多选

如题element-ui 2.13.2版本支持树形结构tabel,多层级折叠显示 但是没有多选 + 树形tabel, 业务需求的情况下必须要实现,操作勾选数据编辑 这里我们可以用两个事件来实现:   @select:用户勾选某行触发事件,第一个参数selection:所有选中的数据, 第二参数row:勾选的这行数据)   @select-all : 表头的...

【Vue入门】利用VueCli搭建基本框架--在Home页实现上左右基本布局(五)

上一节讲了简单封装Http请求并调用登陆的Api接口 这节主要说Home的布局展示 一、设置布局代码   Home页布局参考Elementui中的布局代码(采用上,左右结构)  当然也可以用其他的布局 <el-container> <el-header>Header</el-header> <el-cont...

Python读取大文件的"坑“与内存占用检测

Python高级教程- Python进阶|Scrapy教程|Python高级|Python深入 (pythontab.com) python读写文件的api都很简单,一不留神就容易踩”坑“。笔者记录一次踩坑历程,并且给了一些总结,希望到大家在使用python的过程之中,能够避免一些可能产生隐患的代码。 1.read()与readlines()随手搜索pyt...

Myeclipse安装svn插件

Myeclipse安装svn插件 演示版本 myeclipse——myeclipse8.6 svn——subeclipse-site-1.6.5.zip(对应Myeclipse版本,要有对应的svn插件版本) 方法一: 1.解压svn插件到Myeclipse安装目录下(新建一个目录myplugins,并删除所有的配置文件(xml文件) 2.在Myeclip...

Fastdfs文件系统删除重复的文件

环境:centos、fastdfs Fastdfs文件系统删除重复的文件 问题:fastdfs文件系统磁盘空间疯狂扩展。 原因:fastdfs产生了很多的文件备份,要找到重复文件,排除在使用的文件删除其他的文件。 根源可能是程序反复上传原因,开发进行跟中 删除不需要文件思路: 1、查看文件重复情况 2、列出所有文件系统文件,和从数据库找到所有在用的文件名称...