阿里云DDNS搭建家用服务器

1. 概要

  1. 只需要一个公网备案域名: 在阿里云申请备案一个域名。
  2. 家用宽带需要找运营商调整为动态公网IP: 这样,通过公网域名就可以访问到家里的服务器了。
  3. 原理是通过调用阿里云的云解析 DNS对应的SDK,当家里的公网IP发生变动的时候, 就可以进行动态dns解析了。
  4. 本教程使用的运行环境是windows10
  5. 最终效果: 可以通过域名访问家里的服务器, 可以发布web服务等等

2. 如何获取动态的公网IP

方法有很多:

  1. 可以使用网上的ip接口,可以百度搜索一下,通过本地的定时脚本,循环获取下来。
  2. 我使用的是,自己路由器上暴露出来的wan口ip

3. 集成阿里云的SDK

  1. 阿里云地址: https://help.aliyun.com/document_detail/29771.html

首页
云解析 DNS
API文档
解析管理接口

  1. 使用idea + mvn 进行代码集成和打包, 到处jar包
  2. 通过batch脚本,设置定时任务,进行执行

4. 相关难点

参考:使用 Maven 生成 Jar 文件的三种方式 https://zhuanlan.zhihu.com/p/345268828

//主要难点:在于mvn使用的不是很熟练,下面是mvn构建的方式
<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <source>8</source>
                    <target>8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <filters>
                                <filter>
                                    <artifact>*:*</artifact>
                                    <excludes>
                                        <exclude>META-INF/*.SF</exclude>
                                        <exclude>META-INF/*.DSA</exclude>
                                        <exclude>META-INF/*.RSA</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>com.junge666.ddns.Main</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
···

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值