Centos 7 配置记录

注意:本文最后更新于 2071 天前,有关的内容可能已经发生变化,请参考使用。

因为一些原因新装了几台CentOS7的VPS,把安装过程记录一下备查。

centos.jpg


安装新内核

添加elrepo源后,通过源安装

    rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
    
    rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
    
    yum --enablerepo=elrepo-kernel install kernel-ml -y

修改启动内核

CentOS 7 默认使用了Grub 2,这个原来直接修改menu.lst文件不太一样,查看当前启动菜单和查看当前启动内核可以分别用下列命令

    awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
    grub2-editenv list

显示如下

    [root@localhost etc]# awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
    0 : CentOS Linux 7 Rescue 6bffded1054b4477ba68dcb8d2eb719d (4.11.6-1.el7.elrepo.x86_64)
    1 : CentOS Linux (4.11.6-1.el7.elrepo.x86_64) 7 (Core)
    2 : CentOS Linux 7 Rescue 68270a9645584c1db16653929cadafc4 (3.10.0-514.21.1.el7.x86_64)
    3 : CentOS Linux (3.10.0-514.21.1.el7.x86_64) 7 (Core)
    4 : CentOS Linux (3.10.0-123.4.2.el7.x86_64) 7 (Core)
    5 : CentOS Linux, with Linux 3.10.0-123.el7.x86_64
    6 : CentOS Linux, with Linux 0-rescue-11264912be38456483e63dfd21d402f4
    [root@localhost etc]# grub2-editenv list
    saved_entry=CentOS Linux (3.10.0-514.21.1.el7.x86_64) 7 (Core)
    [root@localhost etc]#

默认启动项一般是saved,指的是上次选中的内核,这里可以通过grub2-set-default来修改,例如修改使用4.11的内核来启动:

    [root@localhost etc]# grub2-set-default 1
    [root@localhost etc]# grub2-editenv list
    saved_entry=1
    [root@localhost etc]#

1指的是留意上面 awk 指令输出的第一个项目的编号。

启用BBR

sysctl.conf额外添加下列内容启用BBR


    net.core.default_qdisc=fq
    net.ipv4.tcp_congestion_control=bbr

我根据情况额外的调整如下,仅供参考


    fs.file-max = 51200
    
    net.ipv4.tcp_tw_reuse = 1
    net.ipv4.tcp_tw_recycle = 0
    net.ipv4.tcp_fin_timeout = 15
    net.ipv4.tcp_keepalive_time = 1200
    net.ipv4.ip_local_port_range = 10000 65000
    net.ipv4.tcp_max_syn_backlog = 10240
    net.ipv4.tcp_max_tw_buckets = 5000
    net.ipv4.tcp_mtu_probing=1
    net.ipv4.tcp_fastopen=3

将 firewall 服务替换回 iptables

CentOS 7 默认使用firewall服务来管理iptables,虽然firewall服务有诸多优点,但是为了节约学习成本,我还是决定将iptables的管理服务换回iptables.services。

    systemctl stop firewalld
    
    systemctl disable firewalld
    
    systemctl mask firewalld

安装iptables.services


    yum install -y iptables-services

    systemctl start iptables
    
    systemctl enable iptables

iptables的配置文件为/etc/sysconfig/iptables。

修改 SELinux 放行 SSH 端口

因为SELinux默认是打开的,所以需要增加SSH的放行端口。要修改 SELinux 的设置,需要使用 semanage 命令,而系统本身默认没有安装这个管理工具的,需要先安装再修改相应的端口,这里以修改为4869为例。


    yum install policycoreutils-python -y
    
    semanage port -a -t ssh_port_t -p tcp 4869

之后运行 semanage port -l | grep ssh 就可以看到刚才添加的端口了。如果修改SELinux设置,在sshd_config修改SSH端口重启SSH服务后会报错“error: Bind to port 4869 on 0.0.0.0 failed: Permission denied.”

安装ocserv

用源安装就比较简单了,配置直接从老版本中copy过来即可,相关证书沿用老系统中的。


    yum install ocserv -y

启用rc.local

CentOS 7的自定义启动脚本需要放在/etc/rc.d/rc.local中,并赋予脚本执行权限才可以运行。


「倘若有所帮助,不妨酌情赞赏!」

Holmesian

感谢您的支持!

使用微信扫描二维码完成支付

发表新评论
已有 2 条评论
  1. 学习笔记Blog

    阿里云ECS 有必要启用BBR嘛?

    学习笔记Blog 回复
  2. 锋少

    good gril!

    锋少 回复