# 手把手教你自建VPS科学上网

By [qunzhong.eth](https://paragraph.com/@qunzhong) · 2022-09-12

---

**一、支持的操作系统 （CentOS 7+、Ubuntu 16+、Debian 8+）**

**二、准备工作**

因为非root用户执行命令都要在前面加上sudo，为了方便可以用以下命令切换为root用户：

1.修改root账户密码：sudo passwd root

2.切换root账户：su root

**三、具体操作步骤**

*   **开启防火墙**
    
    iptables -P INPUT ACCEPT
    
    iptables -P FORWARD ACCEPT
    
    iptables -P OUTPUT ACCEPT
    
    iptables -F
    
    apt-get purge netfilter-persistent
    
*   （**CentOS 将apt-get替换为yum install**）
    
    reboot 重启服务器
    
*   **申请SSL证书**
    
    *   **\# Debian/Ubuntu 命令**
        
    
    apt update -y      
    
    apt install -y curl
    
    apt install -y socat 
    
    *   **#CentOS 命令**
        
    
    yum update -y       
    
    yum install -y curl 
    
    yum install -y socat
    
*   curl [https://get.acme.sh](https://get.acme.sh) | sh
    
    ~/.acme.sh/acme.sh --register-account -m **email**
    
    (email填自己具体的邮箱地址，真实邮箱成功率上升)
    
*   ~/.acme.sh/acme.sh --issue -d **域名** --standalone
    
    （该域名需要给自己的服务器IP做解析，推荐使用阿里云做解析）
    
*   ~/.acme.sh/acme.sh --installcert -d **域名** --key-file /root/private.key --fullchain-file /root/cert.crt
    
*   **更换你的解析域名，此步完成后会在VPS root目录下**
    
    **看到证书公钥/root/cert.crt及验证文件/root/private.key**
    
    公钥：/root/cert.crt
    
    私钥：/root/private.key
    
*   **安装X-ui面板**
    
    bash <(curl -Ls [https://raw.githubusercontent.com/vaxilu/x-ui/master/install.sh)](https://raw.githubusercontent.com/vaxilu/x-ui/master/install.sh\))
    
*   **安装BBR加速**
    
    wget -N --no-check-certificate "[https://raw.githubusercontent.com/chiakge/Linux-NetSpeed/master/tcp.sh](https://raw.githubusercontent.com/chiakge/Linux-NetSpeed/master/tcp.sh)" && chmod +x tcp.sh && ./tcp.sh
    
*   **安装V2ray，下载链接**
    
    [https://github.com/2dust/v2rayN/releases](https://github.com/2dust/v2rayN/releases)
    
    **四、参考文献**
    
*

---

*Originally published on [qunzhong.eth](https://paragraph.com/@qunzhong/vps)*
