zoukankan      html  css  js  c++  java
  • linux新装系统初始化

    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 配置生效 
  • 相关阅读:
    JDBC 复习4 批量执行SQL
    JDBC 复习3 存取Oracle大数据 clob blob
    Oracle复习
    Linux命令(1)grep
    JDBC 复习2 存取mysql 大数据
    JDBC 复习1 DBUtil
    php 环境搭建问题
    Windows 批处理 bat 开启 WiFi 菜单选项 设置ID PWD
    Bat 批处理启动和停止Oracle 服务
    docker 学习1 WSL docker ,Windows docker
  • 原文地址:https://www.cnblogs.com/chacha51/p/11216927.html
Copyright © 2011-2022 走看看