前言,在拥有一台服务器的时候,首先第一件事就要根据自己的需求进行初期的优化(装好系统了),以下是关于linux系统的基本优化,内容来源与网络,自己整理了以下,忘记来自哪个网址了,

centos 系统优化
1、内核参数优化

[root@wulaoer ~]# cat /etc/sysctl.conf #末尾添加如下参数
net.ipv4.tcp_syncookies = #1是开启SYN Cookies,当出现SYN等待队列溢出时,启用Cookies来处,理,可防范少量SYN攻击,默认是0关闭
net.ipv4.tcp_tw_reuse = #1是开启重用,允许讲TIME_AIT sockets重新用于新的TCP连接,默认是0关闭
net.ipv4.tcp_tw_recycle = #TCP失败重传次数,默认是15,减少次数可释放内核资源
net.ipv4.ip_local_port_range = #应用程序可使用的端口范围
net.ipv4.tcp_max_tw_buckets = #系统同时保持TIME_WAIT套接字的最大数量,如果超出这个数字,TIME_WATI套接字将立刻被清除并打印警告信息,默认180000
net.ipv4.tcp_max_syn_backlog = #进入SYN宝的最大请求队列,默认是1024
net.core.netdev_max_backlog = #允许送到队列的数据包最大设备队列,默认300
net.core.somaxconn = #listen挂起请求的最大数量,默认128
net.core.wmem_default = #发送缓存区大小的缺省值
net.core.rmem_default = #接受套接字缓冲区大小的缺省值(以字节为单位)
net.core.rmem_max = #最大接收缓冲区大小的最大值
net.core.wmem_max = #发送缓冲区大小的最大值
net.ipv4.tcp_synack_retries = #SYN-ACK握手状态重试次数,默认5
net.ipv4.tcp_syn_retries = #向外SYN握手重试次数,默认4
net.ipv4.tcp_tw_recycle = #开启TCP连接中TIME_WAIT sockets的快速回收,默认是0关闭
net.ipv4.tcp_max_orphans = #系统中最多有多少个TCP套接字不被关联到任何一个用户文件句柄上,如果超出这个数字,孤儿连接将立即复位并打印警告信息
net.ipv4.tcp_mem =
net.ipv4.tcp_mem[]:低于此值,TCP没有内存压力;
net.ipv4.tcp_mem[]:在此值下,进入内存压力阶段;
net.ipv4.tcp_mem[]:高于此值,TCP拒绝分配socket。内存单位是页,可根据物理内存大小进行调整,如果内存足够大的话,可适当往上调。上述内存单位是页,而不是字节。

2、同步系统时间

[root@wulaoer ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime  #设置Shanghai时区,这两个文件是同一个文件。
[root@wulaoer ~]# ntpdate cn.pool.ntp.org && hwclock -w #同步时间并写入blos硬件时间
[root@wulaoer ~]# crontab -e #设置任务计划每天零点同步一次
0 * * * * /usr/sbin/ntpdate cn.pool.ntp.org ; hwclock -w

更多crontab的使用方法参考,猛点这里  

3、修改history记录

[root@wulaoer ~]# vi /etc/profile #修改记录100个
HISTSIZE=100

4、去除系统相关信息

[root@wulaoer ~]# echo "Welecome to Server" > /etc/issue
[root@wulaoer ~]# echo "Welecome to Server" > /etc/redhat-release

5、调整文件描述符大小

[root@wulaoer ~]# ulimit -n   #默认是65535 -u最大进程
65535
[root@wulaoer ~]# echo "ulimit -SHn 102400" >> /etc/rc.local #设置开机自动生效

表 1. ulimit 参数说明

选项 [options] 含义 例子

-H    设置硬资源限制,一旦设置不能增加。    ulimit – Hs ;限制硬资源,线程栈大小为 64K。
-S 设置软资源限制,设置后可以增加,但是不能超过硬资源设置。 ulimit – Sn ;限制软资源, 个文件描述符。
-a 显示当前所有的 limit 信息。 ulimit – a;显示当前所有的 limit 信息。
-c 最大的 core 文件的大小, 以 blocks 为单位。 ulimit – c unlimited; 对生成的 core 文件的大小不进行限制。
-d 进程最大的数据段的大小,以 Kbytes 为单位。 ulimit -d unlimited;对进程的数据段大小不进行限制。
-f 进程可以创建文件的最大值,以 blocks 为单位。 ulimit – f ;限制进程可以创建的最大文件大小为 blocks。
-l 最大可加锁内存大小,以 Kbytes 为单位。 ulimit – l ;限制最大可加锁内存大小为 Kbytes。
-m 最大内存大小,以 Kbytes 为单位。 ulimit – m unlimited;对最大内存不进行限制。
-n 可以打开最大文件描述符的数量。 ulimit – n ;限制最大可以使用 个文件描述符。
-p 管道缓冲区的大小,以 Kbytes 为单位。 ulimit – p ;限制管道缓冲区的大小为 Kbytes。
-s 线程栈大小,以 Kbytes 为单位。 ulimit – s ;限制线程栈的大小为 Kbytes。
-t 最大的 CPU 占用时间,以秒为单位。 ulimit – t unlimited;对最大的 CPU 占用时间不进行限制。
-u 用户最大可用的进程数。 ulimit – u ;限制用户最多可以使用 个进程。
-v 进程最大可用的虚拟内存,以 Kbytes 为单位。 ulimit – v ;限制最大可用的虚拟内存为 Kbytes。

6、关闭重启ctl-alt-delete组合键

[root@wulaoer ~]# vi /etc/init/control-alt-delete.conf
#exec /sbin/shutdown -r now "Control-Alt-Deletepressed" #注释掉

7、删除不必要的系统用户

[root@wulaoer ~]# userdel 用户名
[root@wulaoer ~]# groupdel 组名
[root@wulaoer ~]# usermod -G
[root@wulaoer ~]# vi /etc/group #找到GROUP1那一行,删除 A 或者用命令 gpasswd -d A GROUP
[root@wulaoer ~]# vi /etc/shadow
[root@wulaoer ~]# vi /etc/passwd

8、关闭不必要开机自启动服务

chkconfig --list | grep 3:on#查看开机自启动服务
chkconfig 服务名称 off #关闭自动的服务

9、禁用root远程登录

[root@wulaoer ~]# vi /etc/ssh/sshd_config
PermitRootLoginno
PermitEmptyPasswords no #禁止空密码登录
UseDNSno #关闭DNS查询

10、添加普通用户并进行sudo授权管理

[root@wulaoer ~]# useradd user
[root@wulaoer ~]# echo "123456" | passwd --stdin user #设置密码
[root@wulaoer ~]# vi /etc/sudoers #或visudo打开,添加user用户所有权限
root ALL=(ALL) ALL
user ALL=(ALL) ALL

11、清空防火墙并设置规则

[root@wulaoer ~]# iptables -F #清楚防火墙规则
[root@wulaoer ~]# iptables -L #查看防火墙规则
[root@wulaoer ~]# iptables -A INPUT -p tcp --dport 80 -j ACCEPT #允许通过的端口
[root@wulaoer ~]# iptables -A INPUT -p tcp --dport 22 -j ACCEPT
[root@wulaoer ~]# iptables -A INPUT -p tcp --dport 53 -j ACCEPT
[root@wulaoer ~]# iptables -A INPUT -p udp --dport 53 -j ACCEPT
[root@wulaoer ~]# iptables -A INPUT -p udp --dport 123 -j ACCEPT
[root@wulaoer ~]# iptables -A INPUT -p icmp -j ACCEPT
[root@wulaoer ~]# iptables -P INPUT DROP
[root@wulaoer ~]# /etc/init.d/iptables save #保存设置

12、关闭SELinux

[root@wulaoer ~]# vi /etc/selinux/config
SELINUX=disabled
[root@wulaoer ~]# setenforce #临时生效
[root@wulaoer ~]# getenforce #查看selinux状态

13、主机名设置

[root@wulaoer ~]# vi /etc/sysconfig/network
HOSTNAME=wulaoer
[root@wulaoer ~]# hostname wulaoer #临时生效

14、禁止无用服务

#! /bin/bash
service acpid off
service atd stop
service auditd stop
service avahi-daemon stop
service avahi-dnsconfd stop
service bluetooth stop
service conman stop
service cpuspeed stop
service cups stop
service dnsmasq stop
service dund stop
service firstboot stop
service hidd stop
service httpd stop
service ibmasm stop
service ip6tables stop
service irda stop
service kdump stop
service lm_sensors stop
service mcstrans stop
service messagebus stop
service microcode_ctl stop
service netconsole stop
service netfs stop
service netplugd stop
service nfs stop
service nfslock stop
service nscd stop
service ntpd stop
service oddjobd stop
service pand stop
service pcscd stop
service portmap stop
service psacct stop
service rdisc stop
service restorecond stop
service rpcgssd stop
service rpcidmapd stop
service rpcsvcgssd stop
service saslauthd stop
service sendmail stop
service setroubleshoot stop
service smb stop
service vncserver stop
service winbind stop
service wpa_supplicant stop
service xfs stop
service ypbind stop
service yum-updatesd stop
chkconfig acpid off
chkconfig atd off
chkconfig auditd off
chkconfig avahi-daemon off
chkconfig avahi-dnsconfd off
chkconfig bluetooth off
chkconfig conman off
chkconfig cpuspeed off
chkconfig cups off
chkconfig dnsmasq off
chkconfig dund off
chkconfig firstboot off
chkconfig hidd off
chkconfig httpd off
chkconfig ibmasm off
chkconfig ip6tables off
chkconfig irda off
chkconfig kdump off
chkconfig lm_sensors off
chkconfig mcstrans off
chkconfig messagebus off
chkconfig microcode_ctl off
chkconfig netconsole off
chkconfig netfs off
chkconfig netplugd off
chkconfig nfs off
chkconfig nfslock off
chkconfig nscd off
chkconfig ntpd off
chkconfig oddjobd off
chkconfig pand off
chkconfig pcscd off
chkconfig portmap off
chkconfig psacct off
chkconfig rdisc off
chkconfig restorecond off
chkconfig rpcgssd off
chkconfig rpcidmapd off
chkconfig rpcsvcgssd off
chkconfig saslauthd off
chkconfig sendmail off
chkconfig setroubleshoot off
chkconfig smb off
chkconfig vncserver off
chkconfig winbind off
chkconfig wpa_supplicant off
chkconfig xfs off
chkconfig ypbind off
chkconfig yum-updatesd off

Linux:系统的基本优化的更多相关文章

  1. Linux学习之六-Linux系统的基础优化

    Linux系统的基础优化 何谓'优化'.顾名思义,优化就是采取某些措施使某个东西或者某事物变得更加优异,出色.对于Linux而言,在初期安装好系统之后,也需要对其进行一定的基础优化,可分为安全上的优化 ...

  2. Linux系统kernel参数优化

    目录 iptables相关 单进程最大打开文件数限制 内核TCP参数方面 内核其他TCP参数说明 众所周知在默认参数情况下Linux对高并发支持并不好,主要受限于单进程最大打开文件数限制.内核TCP参 ...

  3. linux系统基础的优化以及常用命令

    编辑网卡配置文件 vim /etc/sysconfig/network-scripts/ifcfg-eth0 修改配置参数 ONBOOT= yes启动或者关闭ipsystemctl restart/s ...

  4. linux系统的基础优化

    目录 前言 网络优化 在虚拟软件中配置虚拟局域网 接着可以配置自己windows主机的网络连接配置 在虚拟软件中虚拟机添加网卡 虚拟机中的系统基础优化 前言 在自己做linux的相关服务实验时,是没有 ...

  5. Redis在linux系统中的优化

    通常来看,Redis开发和运维人员更加关注的是Redis本身的一些配置优化,例如AOF和RDB的配置优化.数据结构的配置优化等,但是对于操作系统是否需要针对Redis做一些配置优化不甚了解或者不太关心 ...

  6. 阿里云Linux系统基线检查优化

    1.用户权限配置文件的权限优化 描述:设置用户权限配置文件的权限 操作时建议做好记录或备份 chown root:root /etc/passwd /etc/shadow /etc/group /et ...

  7. linux系统使用和优化的原则

  8. Linux 系统学习梳理_【All】

    第一部分---基础学习 00.Linux操作系统各版本ISO镜像下载 00.Linux系统下安装Vmware(虚拟机) 00.Linux 系统安装[Redhat] 00.Linux 系统安装[Cent ...

  9. 原创:四种Linux系统开机启动项优命令超给力超详细详解

    老葵花哥哥又开课了 接下来是你们的齐天大圣孙悟空给你们带来的详细版Linux系统开机启动优化四种命令 第一种方法是很正常的 第二种有点难理解 第三种来自我的一个奇思妙想 本文档秉承 不要钱也不要臀部的 ...

随机推荐

  1. LeetCode OJ 66. Plus One

    Given a non-negative number represented as an array of digits, plus one to the number. The digits ar ...

  2. 百度前端面试题-类似slack的在线聊天室

    别人国庆出去玩,我在家写代码的感觉也是很不错哒. 首先介绍一下技术架构吧! 使用了js框架:FFF,zepto,jquery,md5.min.js 前端框架:Bootstrap 后端:野狗,部分PHP ...

  3. Head First - 01.策略模式(Strategy Pattern)

    策略模式定义了算法族,分别封装起来,让它们之间可以互相替换,此模式让算法的变化独立于使用算法的客户. 当你需要给朋友留下深刻印象,或是影响关键主管的决策时,请使用“这个”定义!  设计原则: 1.找出 ...

  4. for in 的各种坑

    for in方法用来遍历数组或者对象的显性属性,就是说我们自己定义的属性都是可以遍历的,而对象固有的属性,比如Object.prototype.toString是遍历不出来的. for in方法简洁好 ...

  5. 1.4 测试各阶段(单元、集成、系统 、Alpha、Beta、验收)

    单元测试:单元测试是对软件基本组成单元(软件设计的最小单位)进行正确性检验的测试工作,如函数.过程(function,procedure)或一个类的方法(method).单元测试是一个方法层面上的测试 ...

  6. auto_ptr浅析

    auto_ptr是C++标准库中(<utility>)为了解决资源泄漏的问题提供的一个智能指针类模板(注意:这只是一种简单的智能指针) auto_ptr的实现原理其实就是RAII,在构造的 ...

  7. AJax的异步请求

    AJax的处理过程 1、传统的Web请求过程: 一般的 Web 应用程序中,用户填写表单字段并单击 Submit 按钮.然后整个表单发送到服务器,服务器将它转发给处理表单的脚本(通常是 PHP 或 J ...

  8. Spring Boot 系列教程17-Cache-缓存

    缓存 缓存就是数据交换的缓冲区(称作Cache),当某一硬件要读取数据时,会首先从缓存中查找需要的数据,如果找到了则直接执行,找不到的话则从内存中找.由于缓存的运行速度比内存快得多,故缓存的作用就是帮 ...

  9. iOS字符串转化成CGFloat

    NSString *str = @"abc"; [str floatValue];

  10. Tinyxml封装类COperatorXml

    OperatorXml.h头文件 #ifndef _OPERATOR_XML_H_ #define _OPERATOR_XML_H_ #include <string> class TiX ...