Ubuntu_系统优化

来源:互联网 发布:虚拟软件官网 编辑:程序博客网 时间:2024/06/05 05:24
  1. 关闭SELinux功能()

      #vi /etc/selinux/config  SELINUX=disabled

    查看SELinux的状态:

    getenforce

    使SELinux生效:

    setenforce 0     (1 启用;0 不启用)
  2. 运行级别

    查看当前级别:

    runlevel

    查看运行级别:

    tail /etc/inittab

    级别切换:

    innit 数字
  3. 精简开机启动服务

    sshd(用于远程连接)
    rsyslog(系统的守护程序将系统日志写入其中)
    network(网络)
    crond(周期性地执行系统及用户配置的任务计划)
    sysstat(包含检测系统性能及效率的一组工具)
    查看level3级别中处于on的程序:chkconfig –list|grep 3:on

  4. 关闭iptables防火墙(没有外网连接的话)

    查看防火墙状态:

    iptables -L -N

    关闭防火墙:

    /etc/init.d/iptables stop
  5. Linux最小化原则:

    ① 最小化Linux系统,yum安装软件包也要最小化
    ② 操作命令最小化
    ③ 登录用户最小化,平时不用root登录
    ④ 普通用户授权最小化
    ⑤ 文件及目录权限最小化

  6. SSH服务端远程登录配置

    ① Windows服务器的默认远程管理端口是3389;Linux为22号端口,用户是root
    ② SSH配置文件:

    /etc/ssh/sshd_config    (服务器端)/etc/ssh/ssh_config      (客户端)

    修改SSH配置文件:

    vi  /etc/ssh/sshd_config    port --- ; listenaddress --- ; permitrootlogin no; usedns no ; GSSAPIAuthentication no 

    重启SSH配置:

    /etc/init.d/sshd restart
  7. 利用sudo设置用户权限
    配置sudo文件:

    visudoregan  AAL=(ALL)   /bin/touch,/usr/sbin/useradd

    普通用户以root权限执行命令:

    sudo 命令  

    环境变量:PATH 系统路径变量,执行ls,cp等非内置命令时,系统查找PATH对应路径
    里的命令,如果没有就报告没有该命令
    当执行which查看命令所在路径时,也是从PATH变量去搜索
    临时修改export PATH=”/tmp:$PATH”
    永久修改,将以上命令放入/etc/profile下,用source /etc/profile使修改立即生效

  8. 字符集
    GBK ; UTF-8
    字符集配置文件:/etc/sysconfig/il8n

  9. 时间同步
    date 显示时间
    date -s “2017/01/30 22:00” 设置时间
    同步互联网时间:ntpdate time.nist.gov (仅一次生效)
    在任务计划中写入同步互联网时间的程序:

     echo “*/ 5 * * * */usr/sbin/ntpdate time.nist.gov > /dev/null 2>&1” >>/var/spool/cron/root

    /dev/null 空设备,黑洞

     1>/dev/null 2>/dev/null==>/dev/null 2>&1==&>/dev/null  

    为CRT终端设置超时时间:

    export TMOUT=10 

    使超时时间永久生效:

    echo “export TMOUT=10” >>/etc/profilesource /etc/profile
  10. 历史记录
    设置历史记录条数:

    export HISTSIZE=10

    使历史记录条数的修改永久生效:

    echo “export HISTSIZE=10”>>/etc/profilesource /etc/profile

    显示历史命令记录:

    history

    清空history:

    history -c

    删除某一行(43)history:

    history -d 43
  11. 加大文件描述符
    查看文件描述符:

    ulimit -n

    设置文件描述符大小:

    ulimit -SHn 65535

    使设置永久生效:

    echo “* - nofile 65535”>>/etc/security/limits.conf
  12. 调整内核参数
    设置配置文件:/usr/lib/sysctl.d/00-system.conf

    net.ipv4.tcp_fin_timeout=2 (连接超时)net.ipv4.tcp_tw_reuse=1net.ipv4.tcp_tw_recycle=1net.ipv4.tcp_max_tw_buckets=16384 (控制TIME-WAIT数量)net.ipv4.tcp_syncookies=1    (1表示开启)net.ipv4.tcp_tw_keepalive_time=600net.ipv4.ip_local_port_range=4000 65000net.ipv4.tcp_synack_retries=1net.ipv4.tcp_tw_syn_retries=1net.core.netdev_max_backlog=

    使修改生效:

    sysctl -p
  13. 隐藏Linux版本信息
    查看Linux版本信息:

    cat /etc/issue.net

    清空Linux版本信息:

    > /etc/issue.net   cat /dev/null > /etc/issue

    设置登录版本信息:

    vi /etc/moth
  14. 锁定系统文件
    锁定文件:

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

    解除文件锁定:

    chattr -i /etc/passwd /etc/shadow /etc/group /etc/gshadow /etc/inittab
  15. grub引导菜单加密
    设置grub密码:

    /sbin/grub-md5-crypt

    禁止系统被Ping:

    echo “net.ipv4.icmp_echo_ignore_all=1”>>/etc/sysctl.conf