系统优化开机 linux,linux系统优化配置

更新国内镜像源

国内速度较快的常用更新源如下:

[root@greymouster ~]# cd /etc/yum.repos.d/[root@greymouster yum.repos.d]# ll

total16

-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

yumupdate 把系统的更新到最新

yumgrouplist 查看系统都安装了那些安装包

安装后的基本调优及安全设置

1.关闭selinux

6f15a31956dbcbc8ff5ecd2abd5e974d.png

2.设定runlevel为3

[root@greymouster ~]# grep 3:initdefault /etc/inittab

id:3:initdefault:

[root@greymouster~]# init 3

3.精简开机系统启动的服务为:

32c147b084648b8ad6302714f2828de3.png

[root@greymouster ~]# LANG=en

[root@greymouster~]# chkconfig --list|grep "3:on"[root@greymouster~]# for test in `chkconfig --list|grep "3:on"|awk '{print $1}'`;dochkconfig $test off;done

[root@greymouster~]# for test in crond network rsyslog sshd;dochkconfig $test on;done

[root@greymouster~]# chkconfig --list|grep "3:on"

或者

[root@greymouster ~]# for test in `chkconfig --list|grep "3:on"|awk '{print $1}'|grep -vE"crond|network|rsyslog|sshd"`;do chkconfig $test off;done

4.更改ssh服务远程登录的配置

[root@greymouster ~]# cp /etc/ssh/sshd_config /etc/ssh/sshd_config.ori

[root@greymouster~]# vi /etc/ssh/sshd_config

4d82a71b9749ed07dd124ce2217b6350.png

5.将普通帐号加入到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] passwordforgreymouster:

[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 ~]$

6.修改中文显示

5dc94d6ddb08267e630228e081b2043b.png

7.服务器时间同步

002d4e90ad0487025cde22851aa3a6ca.png

[root@greymouster ~]# /usr/sbin/ntpdate time.nist.gov25 Mar 15:19:50 ntpdate[29421]: step time server 128.138.141.172 offset 248182.140419sec

[root@greymouster~]# date

2017年 03月 25日 星期六15:20:07CST

[root@greymouster~]# echo '#time sync by greymouster at 2017-3-25' >> /var/spool/cron/root

[root@greymouster ~]# echo '*/5 * * * * /usr/sbin/ntpdate time.nist.gov > /dev/null 2>&1'>>/var/spool/cron/root

[root@greymouster~]# crontab -l

#time sync by greymouster at2017-3-25

*/5 * * * * /usr/sbin/ntpdate time.nist.gov > /dev/null 2>&1

8.加大服务器的文件描述符

b471a21c260fba4940bc0ff34f81d5a0.png

9.调整内核参数文件 /etc/sysctl.conf

vim /etc/sysctl.conf  shift+g 切换到底部添加

net.ipv4.tcp_fin_timeout = 2net.ipv4.tcp_tw_reuse= 1net.ipv4.tcp_tw_recycle= 1net.ipv4.tcp_syncookies= 1net.ipv4.tcp_keepalive_time= 600net.ipv4.ip_local_port_range= 4000 65000net.ipv4.tcp_max_syn_backlog= 16384net.ipv4.tcp_max_tw_buckets= 36000net.ipv4.route.gc_timeout= 100net.ipv4.tcp_syn_retries= 1net.ipv4.tcp_synack_retries= 1net.core.somaxconn= 16384net.core.netdev_max_backlog= 16384net.ipv4.tcp_max_orphans= 16384

防火墙的优化则添加以下,在6.4上是,如下:

net.nf_conntrack_max = 25000000net.netfilter.nf_conntrack_max= 25000000net.netfilter.nf_conntrack_tcp_timeout_established= 180net.netfilter.nf_conntrack_tcp_timeout_time_wait= 120net.netfilter.nf_conntrack_tcp_timeout_close_wait= 60net.netfilter.nf_conntrack_tcp_timeout_fin_wait= 120

[root@greymouster ~]# sysctl -p //生效

10、锁定关键文件系统

[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

11、去除系统及内核版本登录前的屏幕显示

[root@greymouster ~]# /etc/redhat-release

[root@greymouster~]# cat /dev/null >/etc/issue

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值