前言,在拥有一台服务器的时候,首先第一件事就要根据自己的需求进行初期的优化(装好系统了),以下是关于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. how computer boot up?

    The power button activates the power supply in the PC, sending power to the motherboard and other co ...

  2. java使用iText生成pdf表格

    转载地址:http://www.open-open.com/code/view/1424011530749 首先需要你自己下载itext相关的jar包并添加引用,或者在maven中添加如下引用配置: ...

  3. 聊一聊PV和并发、以及计算web服务器的数量的方法【转】

    聊一聊PV和并发.以及计算web服务器的数量的方法 站长之家 2016-08-17 09:40 最近和几个朋友,聊到并发和服务器的压力问题.很多朋友,不知道该怎么去计算并发?部署多少台服务器才合适? ...

  4. linq中first() firstordefault() last() lastOrDefault() single() singleOrDeafult

    一.firstordefault() 和 first() class Program { static void Main(string[] args) { List<Emp> list ...

  5. 使用内链接(A a inner join B b on a.xx = b.xx)查询2个表中某一列的相同的字段。

    这里一句代码就是查询2个表中某一列的相同,可是查询出来之后B表因为有很多重复的id数据,然而查询出来的数据需要插入到临时表中,临时表的oid是不允许有重复的, 因此需要用到 distinct 函数来取 ...

  6. 用GeneratedKeyHolder获得新建数据主键值

    public User createUser(final User user) { final String sql = "insert into sys_users(username, p ...

  7. Lua 迭代器

    第一种:lua迭代器的实现依赖于闭包(closure)特性 1.1 第一个简单的写法 --迭代器写法 function self_iter( t ) local i = 0 return functi ...

  8. Debian 安装Nvidia显卡驱动

    1.到nvidia官方网站下载自己显卡对应型号得驱动,如果不知道显卡型号,可以使用如下命令来查看 lspci | grep VGA 2.安装显卡驱动所必需得工具 apt-get install bui ...

  9. linux视频学习5(top, 网络监控

    top命令的详解: 1. top :动态监控进程. 第一行:当前系统时间:  up  4days :服务器启动后的持续时间. 5 user 当前服务器上的用户数目 ; load average :负载 ...

  10. jquery 控制文本输入的字数

    <textarea maxlength="200" id="remarks" onkeyup="title_len();">&l ...