Linux之系统优化配置
Linux系统优化配置
更新国内镜像源
国内速度快的常用更新源如下:
[root@greymouster ~]# cd /etc/yum.repos.d/
[root@greymouster yum.repos.d]# ll
total 16
-rw-r--r--. 1 root root 1926 Nov 27 2013 CentOS-Base.repo
-rw-r--r--. 1 root root 638 Nov 27 2013 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 630 Nov 27 2013 CentOS-Media.repo
-rw-r--r--. 1 root root 3664 Nov 27 2013 CentOS-Vault.repo
[root@greymouster yum.repos.d]# cp CentOS-Base.repo CentOS-Base.repo.ori
[root@greymouster yum.repos.d]# wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
[root@greymouster yum.repos.d]# cp CentOS6-Base-163.repo CentOS-Base.repo
安装必要的软件包
yum install tree telnet dos2unix sysstat lrzsz -y
yum grouplist 查看系统安装了哪些安装包
关闭selinux
# 该命令永久将selinux关闭,但是必须要重启系统
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config # 临时修改命令(不用重启系统)
setenforce 0 # 查看selinux当前状态
getenforce
设定开机运行级别为3
[root@greymouster ~]# grep 3:initdefault /etc/inittab
id:3:initdefault:
[root@greymouster ~]# init 3
精简开机系统启动的服务
# 先关闭所有开机自启动服务
for i in `chkconfig --list|grep 3:on|awk '{print $1}'`;do chkconfig --level 3 $i off;done # 然后再开启指定开机自启动服务
for i in crond network rsyslog sshd;do chkconfig --level 3 $i on;done
更改ssh服务远程登陆的配置
[root@greymouster ~]# cp /etc/ssh/sshd_config /etc/ssh/sshd_config.ori
[root@greymouster ~]# vi /etc/ssh/sshd_config
#Port 22 #ssh连接默认端口22
#PermitRootLogin no # root用户是否禁止远程登录
#PermitEmptyPasswords no #禁止空密码登录
#UseDNS no #不使用DNS
#GSSAPIAuthentication no #让ssh连接更快
[root@greymouster ~]# /etc/init.d/sshd restart
[root@greymouster ~]# /etc/init.d/iptables stop //临时关闭防火墙
将普通账号加入sudo管理
[root@greymouster ~]# visudo
98gg //定位到98行 root ALL=(ALL) ALL
greymouster ALL=(ALL) /usr/sbin/useradd
或者这样修改:拥有全部的权限但不需要密码
greymouster ALL=(ALL) NOPASSWD:ALL %用户组 机器=(授权那个角色的权利) /usr/sbin/useradd [root@greymouster ~]# su - greymouster
[greymouster@greymouster ~]$ useradd kkk
-bash: /usr/sbin/useradd: Permission denied
[greymouster@greymouster ~]$ sudo useradd kkk
[sudo] password for greymouster:
[greymouster@greymouster ~]$ tail -1 /etc/passwd
kkk:x:502:502::/home/kkk:/bin/bash
[greymouster@greymouster ~]$ netstat -lntup|grep ssh
(No info could be read for "-p": geteuid()=501 but you should be root.)
[greymouster@greymouster ~]$ sudo netstat -lntup|grep ssh
tcp 0 0 0.0.0.0:60222 0.0.0.0:* LISTEN 28683/sshd
tcp 0 0 :::60222 :::* LISTEN 28683/sshd
[greymouster@greymouster ~]$
服务器时间同步
# 系统方法
[root@PLF ~]# /usr/sbin/ntpdate time.nist.gov
27 May 20:08:05 ntpdate[25792]: step time server 132.163.97.2 offset 95.328349 sec
[root@PLF ~]# echo "# time sync" >>/var/spool/cron/root
[root@PLF ~]# echo '*/5 * * * * /usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1' >>/var/spool/cron/root
[root@PLF ~]# crontab -l
# time sync
*/5 * * * * /usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1
[root@PLF ~]#加大服务器的文件描述符
echo '* soft nofile 65535' >>/etc/security/limits.conf
echo '* hard nofile 65535' >>/etc/security/limits.conf
调整内核参数文件/et/sysctl.conf
net.ipv4.tcp_fin_timeout = 2
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_keepalive_time = 600
net.ipv4.ip_local_port_range = 4000 65000
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.tcp_max_tw_buckets = 36000
net.ipv4.route.gc_timeout = 100
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_synack_retries = 1
net.core.somaxconn = 16384
net.core.netdev_max_backlog = 16384
net.ipv4.tcp_max_orphans = 16384 # 防火墙的优化则添加以下,在6.4上是,如下:
net.nf_conntrack_max = 25000000
net.netfilter.nf_conntrack_max = 25000000
net.netfilter.nf_conntrack_tcp_timeout_established = 180
net.netfilter.nf_conntrack_tcp_timeout_time_wait = 120
net.netfilter.nf_conntrack_tcp_timeout_close_wait = 60
net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 120 [root@greymouster ~]# sysctl -p //生效
锁定关键文件系统
[root@greymouster ~]# chattr +i /etc/passwd
[root@greymouster ~]# chattr +i /etc/inittab
[root@greymouster ~]# chattr +i /etc/group
[root@greymouster ~]# chattr +i /etc/shadow
[root@greymouster ~]# chattr +i /etc/gshadow # 使用chattr命令后,为了安全我们需要将其改名
[root@greymouster ~]# /bin/mv /usr/bin/chattr /usr/bin/任意名称 # 查看枷锁:
lsattr /etc/passwd
去除系统及内核版本登陆前的屏幕显示
[root@greymouster ~]# /etc/redhat-release
[root@greymouster ~]# cat /dev/null >/etc/issue
Linux之系统优化配置的更多相关文章
- Linux基础 - 系统优化及常用命令
目录 Linux基础系统优化及常用命令 Linux基础系统优化 网卡配置文件详解 ifup,ifdown命令 ifconfig命令 ifup,ifdown命令 ip命令 用户管理与文件权限篇 创建普通 ...
- Linux基础系统优化及常用命令
# Linux基础系统优化及常用命令 [TOC] ## Linux基础系统优化 Linux的网络功能相当强悍,一时之间我们无法了解所有的网络命令,在配置服务器基础环境时,先了解下网络参数设定命令. - ...
- Linux基本系统优化
Linux基本系统优化 Linux Linux的网络功能相当强悍,一时之间我们无法了解所有的网络命令, 在配置服务器基础环境时,先了解下网络参数设定命令. ifconfig 查询.设置网卡和ip等参 ...
- Linux操作系统优化
figure:first-child { margin-top: -20px; } #write ol, #write ul { position: relative; } img { max-wid ...
- 在Linux虚拟机下配置tomcat
1.到Apache官网下载tomcat http://tomcat.apache.org/download-80.cgi 博主我下载的是tomcat8 博主的jdk是1.8 如果你们的jdk是1.7或 ...
- 在Linux虚拟机下配置jdk的环境变量
1.到Oracle公司的官网里下载好jdk,网址 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133 ...
- Linux网络属性配置
目录 IP地址分类 如何将Linux主机接入到网络中 网络接口的命名方式 ifcfg系列命令 如何配置主机名 如何配置DNS服务器指向 iproute2系列命令 Linux管理网络服务 永久生效配置路 ...
- 阿里云服务器Linux CentOS安装配置(零)目录
阿里云服务器Linux CentOS安装配置(零)目录 阿里云服务器Linux CentOS安装配置(一)购买阿里云服务器 阿里云服务器Linux CentOS安装配置(二)yum安装svn 阿里云服 ...
- 阿里云服务器Linux CentOS安装配置(九)shell编译、打包、部署
阿里云服务器Linux CentOS安装配置(九)shell编译.打包.部署 1.查询当前目录以及子目录下所有的java文件,并显示查询结果 find . -name *.java -type f - ...
随机推荐
- c++写入注册表
一.说明: 注册表是Windows重要组成部分,注册表记录了大量有关电脑软硬件的信息.注册表中的值通过其名称标识.值名称由与键名相同的字符组成.值本身可以是字符串.二进制数据或者是32位无符 ...
- oracle 密码过期问题
密码过期问题: ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;
- dom4j+反射实现bean与xml的相互转换
由于目前在工作中一直用的dom4j+反射实现bean与xml的相互转换,记录一下,如果有不正确的地方欢迎大家指正~~~ 一.反射机制 在此工具类中使用到了反射技术,所以提前也看了一些知识点,例如:ht ...
- spring security 方法权限使用
前面我们讲过了使用<security:intercept-url>配置url的权限访问,下面我们讲解一下基于方法的权限使用默认情况下, Spring Security 并不启用方法级的安全 ...
- centos 6.5 升级到 python2.7
准备 centos6.5的python版本默认是2.6.6,可能有的时候我们需要升级到更高的版本,那就来动手升级下吧.我这里以2.7.8版本为例,根据实际需要选择升级版本即可. yum install ...
- Steam 游戏 《Sudoku Universe(数独宇宙)》——[数独基本局分析]
日期:2020.02.12 博客期:152 星期三 老师给的任务都做完了,15篇博客也都写好了,剩下的几天居然还要每天写一篇~唉~为难我 PH ,剩下的几天就把 我的数独要义分享一下吧! 1.基本局规 ...
- 例题3_1 TeX中的引号(TeX Quotes,UVa 272)
在TeX中,左双引号是“``”,右双引号是“''”.输入一篇包含双引号的文章,你的任务是把它转换成TeX的格式. 样例输入: "To be or not to be,"quoth ...
- 二叉树性质 n0=n2+1
假设树的节点个数为n,那么n=n0+n1+n2,并且边的个数等于n-1,那么 n-1=n22+n1 则 n0+n1+n2-1=n22+n1,即n0=n2+1.
- 整合SSM
SSM整合:Spring - SpringMVC - MyBatis 1.Spring - MyBatis : 需要整合:将MyBatis的SqlSessionFactory 交给Spr ...
- ES6-const定义常量
在es5中我们一般将变量名大写来表明这是一个常量,但其实它是可以修改的. 在es6中可以用const来定义常量,它定义的常量不能修改. const NAME = 'tom'; NAME ...