id: e853d1d520f64646bbef1d387664017a
parent_id: 
item_type: 1
item_id: c66e5c631aea4812a799327b313efa44
item_updated_time: 1764345477985
title_diff: "[{\"diffs\":[[1,\"AWS EC2打造自己的省钱VPN\"]],\"start1\":0,\"start2\":0,\"length1\":0,\"length2\":17}]"
body_diff: "[{\"diffs\":[[1,\"<html>\\\r\\\n<head>\\\r\\\n  <title>AWS EC2打造自己的省钱VPN</title>\\\r\\\n  <basefont face=\\\"微软雅黑\\\" size=\\\"2\\\" />\\\r\\\n  <meta http-equiv=\\\"Content-Type\\\" content=\\\"text/html;charset=utf-8\\\" />\\\r\\\n  <meta name=\\\"exporter-version\\\" content=\\\"YXBJ Windows/608924 (zh-CN, DDL); Windows/10.0.0 (Win64); EDAMVersion=V2;\\\"/>\\\r\\\n  <meta name=\\\"application-data:2525275\\\" content=\\\"6692893/s30/bb9b0046-e191-4060-bbf6-b02fffa43dfd/app.yinxiang.com\\\"/>\\\r\\\n  <style>\\\r\\\n\\tbody, td {\\\r\\\n\\t  font-family: 微软雅黑;\\\r\\\n\\t  font-size: 12pt;\\\r\\\n\\t}\\\r\\\n  </style>\\\r\\\n</head>\\\r\\\n<body>\\\r\\\n<a name=\\\"10948\\\"></a>\\\r\\\n<h1>AWS EC2打造自己的省钱VPN</h1>\\\r\\\n\\\r\\\n<div><span><div style=\\\"-evernote-webclip:true\\\"><br/><div style=\\\"font-size: 16px\\\"><div style=\\\"font-size:100%;text-size-adjust:100%;-webkit-tap-highlight-color:transparent;\\\"><div style=\\\"font-size:14px;line-height:20px;color:rgb(85, 85, 85);background-color:white;font-family:&quot;lucida grande&quot;, &quot;lucida sans unicode&quot;, lucida, helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;\\\"><div><div><div><div><div>\\\n          <div style=\\\"padding-bottom:15px;margin-bottom:30px;border-bottom:1px solid rgb(238, 238, 238);overflow:hidden;font-size:12px;color:rgb(153, 153, 153);\\\">\\\n              <div style=\\\"border-width:1px;display:inline-block;margin-bottom:0px;background:rgb(73, 190, 56);box-shadow:none;text-align:center;vertical-align:middle;cursor:pointer;color:white;text-shadow:none;padding:2px 10px;border-style:solid;border-color:rgb(73, 190, 56);border-image:initial;border-radius:50px;line-height:22px;font-family:&quot;lucida grande&quot;, &quot;lucida sans unicode&quot;, lucida, helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-weight:normal;font-size:12px;float:right;margin-top:10px;\\\">\\\n    <a href=\\\"http://www.jianshu.com/sign_in\\\" style=\\\"text-decoration:none;color:white;\\\"><i style=\\\"line-height:1;display:inline-block;font-variant:normal;font-weight:normal;font-stretch:normal;font-style:normal;font-family:FontAwesome;font-size:inherit;text-rendering:auto;-webkit-font-smoothing:antialiased;transform:translate(0px, 0px);\\\"><span style=\\\"font-style:normal;font-variant:normal;font-weight:normal;line-height:1;font-family:FontAwesome;font-size:inherit;\\\"></span></i>  <span style=\\\"padding-left:7px;margin-left:3px;border-left:1px solid rgb(217, 217, 217);\\\">添加关注</span></a>\\\n  </div>\\\n\\\n            <a href=\\\"http://www.jianshu.com/users/137f3f825a45\\\" style=\\\"color:rgb(85, 85, 85);text-decoration:none;border-radius:50%;float:left;width:40px;height:40px;margin-right:10px;\\\">\\\n              <img src=\\\":/0c36e6dc30a0413ba24c5fd661bc67eb\\\" type=\\\"image/jpeg\\\" data-filename=\\\"100.jpg\\\" alt=\\\"100\\\" height=\\\"36\\\" style=\\\"max-width:100%;vertical-align:middle;height:100%;border:2px solid white;width:100%;border-radius:50%;box-sizing:border-box;\\\" width=\\\"36\\\"/>\\\n</a>            <span style=\\\"vertical-align:baseline;display:inline-block;border-radius:3px;white-space:nowrap;padding:2px 4px;color:rgb(231, 129, 112);line-height:1;font-weight:normal;text-shadow:none;font-size:11px;background:none;border:1px solid rgb(231, 129, 112);\\\">\\\n                作者\\\n            </span>\\\n            <a href=\\\"http://www.jianshu.com/users/137f3f825a45\\\" style=\\\"text-decoration:none;color:rgb(64, 148, 199);margin:0px 5px;\\\">\\\n              <span>hughlo</span>\\\n</a>              <span>2016.02.14 23:04</span>\\\n            <div style=\\\"margin-top:3px;\\\">\\\n              <span>写了5350字</span>，<span>被4人关注</span>，<span>获得了7个喜欢</span>\\\n            </div>\\\n          </div>\\\n          <h1 style=\\\"margin:10px 0px;font-family:inherit;color:inherit;text-rendering:optimizeLegibility;font-weight:bold;line-height:1.5;font-size:32px;word-break:break-all;\\\">AWS EC2打造自己的省钱VPN</h1>\\\n          <div style=\\\"font-family:&quot;lucida grande&quot;, &quot;lucida sans unicode&quot;, lucida, helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;margin:20px 0px;\\\">\\\n            <span style=\\\"position:relative;top:1px;margin-right:10px;font-size:12px;color:rgb(153, 153, 153);\\\">字数1108</span>\\\n            <span style=\\\"position:relative;top:1px;margin-right:10px;font-size:12px;color:rgb(153, 153, 153);\\\">阅读633</span>\\\n            <span style=\\\"position:relative;top:1px;margin-right:10px;font-size:12px;color:rgb(153, 153, 153);\\\">评论1</span>\\\n            <span style=\\\"position:relative;top:1px;margin-right:10px;font-size:12px;color:rgb(153, 153, 153);\\\">喜欢5</span>\\\n          </div>\\\n\\\n          \\\n          \\\n          \\\n\\\n          <div style=\\\"color:rgb(47, 47, 47);font-size:16px;font-weight:normal;line-height:1.7;\\\"><h3 style=\\\"font-family:inherit;font-weight:bold;margin:0px;line-height:1.8;color:inherit;text-rendering:optimizeLegibility;font-size:22px;\\\">前言</h3>\\\n<p style=\\\"margin:0px 0px 25px;text-align:justify;word-break:break-word;\\\">一直都是自己在AWS上架设shadowsocks服务器，速度有保障。EC2在第一年申请的时候基本是免费的，所有AWS上的EC2实例都是24小时开着的。到了第二年的EC2会按照0.025USD/小时收费（这是东京区的收费标准，其它区收费会有点不一样）。算下来如果不停机的话一个月要22USD左右，有点小贵。再者我这个VPN都是在家里自用的，也就是只有晚上才用，白天的时候基本就是空着的。理想的状态是，想用的时候打开EC2的实例，不用的时候关掉。但是每次开关EC2实例都需要登录到AWS控制台，很麻烦。再者，EC2实例每次启动IP地址都会变动，意味着shadowsocks客户端的设置也要每次跟着改，光是这个就够烦的了。为了省时省力，所以决心用AWS CLI结合GO语言，写一个简单的程序能够方便地启动和终止VPN和shadowsocks客户端，不用每次都手动改设置。<br/>基本功能列举如下：</p>\\\n<ul style=\\\"padding:0px;margin:0px 0px 10px 25px;text-align:justify;word-break:break-word;margin-bottom:20px;\\\">\\\n<li style=\\\"line-height:30px;\\\">可以在本机启动和停止EC2实例</li>\\\n<li style=\\\"line-height:30px;\\\">可以自动获取当前的EC2实例IP地址</li>\\\n<li style=\\\"line-height:30px;\\\">获取IP地址之后自动将shadowsocks客户端连接到服务端</li>\\\n</ul>\\\n<h3 style=\\\"font-family:inherit;font-weight:bold;margin:0px;line-height:1.8;color:inherit;text-rendering:optimizeLegibility;font-size:22px;\\\">设置AWS</h3>\\\n<h4 style=\\\"font-family:inherit;font-weight:bold;margin:0px;line-height:1.8;color:inherit;text-rendering:optimizeLegibility;font-size:20px;\\\">创建实例</h4>\\\n<p style=\\\"margin:0px 0px 25px;text-align:justify;word-break:break-word;\\\">AWS的设置很简单，首先创建一个AWS的帐号，然后创建一个EC2的t2.nano的实例。t2.micro首年是免费的，所以如果是新用户的话，可以直接使用t2.micro的实例。t2.nano和t2.micro的区别就是内存，micro是1GB而nano是500MB。对于我一个人使用而言，nano足以。<br/>AWS的实例有三种交费方式：按小时，按年以及竞标。具体的区别和收费方式可以查看官方的文档。本文的目的是针对按小时计费这种方式。按小时计费的计费区间是从实例开始运行一直到实例终结或者停止。本文的目的就是提供一种命令行工具可以简单地在本地终端控制AWS实例的开始和停止，以此达到省费用的目的。<br/>创建实例的时候会选择操作系统，这里选择AWS支持的ubuntu的最新版就可以了。</p>\\\n<h4 style=\\\"font-family:inherit;font-weight:bold;margin:0px;line-height:1.8;color:inherit;text-rendering:optimizeLegibility;font-size:20px;\\\">创建security group</h4>\\\n<p style=\\\"margin:0px 0px 25px;text-align:justify;word-break:break-word;\\\">另外还需要创建一个security group，在security group里面需要对inbound条件进行设置。默认的只开启了HTTP协议的80端口。为了能访问shadowsocks服务，需要把TCP的8388端口打开（8388是shadowsocks服务的默认端口，如果你用的不是默认端口，这里也要做相应的修改）。</p>\\\n<h3 style=\\\"font-family:inherit;font-weight:bold;margin:0px;line-height:1.8;color:inherit;text-rendering:optimizeLegibility;font-size:22px;\\\">安装shadowsocks服务端</h3>\\\n<p style=\\\"margin:0px 0px 25px;text-align:justify;word-break:break-word;\\\">大概来讲先安装pip，然后再安装shadowsocks。执行以下命令即可：</p>\\\n<pre style=\\\"word-break:break-all;padding:9.5px;font-size:13px;border:1px solid rgba(0, 0, 0, 0.14902);border-radius:4px;display:block;margin:0px 0px 10px;line-height:20px;font-family:Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace;color:rgb(101, 123, 131);background:rgb(253, 246, 227);text-size-adjust:none;word-wrap:normal;white-space:pre;overflow:auto;margin-bottom:20px;\\\"><code style=\\\"font-family:Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace;border-radius:3px;font-size:12px;color:rgb(101, 123, 131);border:none;padding:0px;background-color:transparent;white-space:pre;\\\">apt-get <span><span style=\\\"color:rgb(133, 153, 0);\\\">install</span> python-pip\\\npip <span style=\\\"color:rgb(133, 153, 0);\\\">install</span> shadowsocks</span></code></pre>\\\n<h4 style=\\\"font-family:inherit;font-weight:bold;margin:0px;line-height:1.8;color:inherit;text-rendering:optimizeLegibility;font-size:20px;\\\">设置开机启动</h4>\\\n<p style=\\\"margin:0px 0px 25px;text-align:justify;word-break:break-word;\\\">修改/etc/init.d/rc.local这个文件，在文件的最末加入下面代码：</p>\\\n<pre style=\\\"word-break:break-all;padding:9.5px;font-size:13px;border:1px solid rgba(0, 0, 0, 0.14902);border-radius:4px;display:block;margin:0px 0px 10px;line-height:20px;font-family:Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace;color:rgb(101, 123, 131);background:rgb(253, 246, 227);text-size-adjust:none;word-wrap:normal;white-space:pre;overflow:auto;margin-bottom:20px;\\\"><code style=\\\"font-family:Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace;border-radius:3px;font-size:12px;color:rgb(101, 123, 131);border:none;padding:0px;background-color:transparent;white-space:pre;\\\">sudo ssserver -k <span style=\\\"color:rgb(42, 161, 152);\\\">&quot;your-password&quot;</span> -d start <span style=\\\"color:rgb(147, 161, 161);\\\">//把your-password替换成你自己的密码</span></code></pre>\\\n<p style=\\\"margin:0px 0px 25px;text-align:justify;word-break:break-word;\\\">这样简单设置一下，在EC2实例启动的时候，就会自动启动shadowsocks服务端程序。</p>\\\n<h3 style=\\\"font-family:inherit;font-weight:bold;margin:0px;line-height:1.8;color:inherit;text-rendering:optimizeLegibility;font-size:22px;\\\">AWS CLI</h3>\\\n<h4 style=\\\"font-family:inherit;font-weight:bold;margin:0px;line-height:1.8;color:inherit;text-rendering:optimizeLegibility;font-size:20px;\\\">安装和配置AWS CLI</h4>\\\n<p style=\\\"margin:0px 0px 25px;text-align:justify;word-break:break-word;\\\">AWS CLI是一套用来在本地控制AWS实例的命令行工具。安装方法有很多种，这里不详说。可访问<a href=\\\"https://github.com/aws/aws-cli\\\" style=\\\"text-decoration:none;color:rgb(64, 148, 199);\\\" target=\\\"_blank\\\">github主面</a>获取更多的安装信息。<a href=\\\"http://docs.amazonaws.cn/cli/latest/userguide/cli-chap-getting-started.html\\\" style=\\\"text-decoration:none;color:rgb(64, 148, 199);\\\" target=\\\"_blank\\\">访问这里</a>获取更多的配置信息。</p>\\\n<h4 style=\\\"font-family:inherit;font-weight:bold;margin:0px;line-height:1.8;color:inherit;text-rendering:optimizeLegibility;font-size:20px;\\\">AWS CLI控制服务器</h4>\\\n<p style=\\\"margin:0px 0px 25px;text-align:justify;word-break:break-word;\\\">主要用到三个命令：</p>\\\n<pre style=\\\"word-break:break-all;padding:9.5px;font-size:13px;border:1px solid rgba(0, 0, 0, 0.14902);border-radius:4px;display:block;margin:0px 0px 10px;line-height:20px;font-family:Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace;color:rgb(101, 123, 131);background:rgb(253, 246, 227);text-size-adjust:none;word-wrap:normal;white-space:pre;overflow:auto;margin-bottom:20px;\\\"><code style=\\\"font-family:Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace;border-radius:3px;font-size:12px;color:rgb(101, 123, 131);border:none;padding:0px;background-color:transparent;white-space:pre;\\\">aws ec2 <span><span style=\\\"color:rgb(133, 153, 0);\\\">start</span>-instances <span style=\\\"color:rgb(147, 161, 161);\\\">--instance-id</span>\\\naws ec2 <span style=\\\"color:rgb(133, 153, 0);\\\">stop</span>-instances <span style=\\\"color:rgb(147, 161, 161);\\\">--instance-id</span>\\\naws ec2 <span style=\\\"color:rgb(133, 153, 0);\\\">describe</span>-instances <span style=\\\"color:rgb(147, 161, 161);\\\">--instance-id</span></span></code></pre>\\\n<h3 style=\\\"font-family:inherit;font-weight:bold;margin:0px;line-height:1.8;color:inherit;text-rendering:optimizeLegibility;font-size:22px;\\\">安装shadowsocks客户端</h3>\\\n<p style=\\\"margin:0px 0px 25px;text-align:justify;word-break:break-word;\\\">和服务端一样的安装方法，只是不需要设置开机启动。</p>\\\n<h3 style=\\\"font-family:inherit;font-weight:bold;margin:0px;line-height:1.8;color:inherit;text-rendering:optimizeLegibility;font-size:22px;\\\">使用auto-vpn工具</h3>\\\n<p style=\\\"margin:0px 0px 25px;text-align:justify;word-break:break-word;\\\">auto-vpn工具可以在<a href=\\\"https://github.com/HughLo/auto-vpn\\\" style=\\\"text-decoration:none;color:rgb(64, 148, 199);\\\" target=\\\"_blank\\\">github</a>拿到。需要根据README的指示自己编译一下。把编译出来的二进制文件放到<strong style=\\\"font-weight:bold;\\\">/usr/local/bin</strong>目录下，就可以直接在终端里面运行了。<br/>只需要在终端里面输入一行命令<code style=\\\"font-family:Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace;border-radius:3px;padding:2px 4px;font-size:12px;color:rgb(101, 123, 131);background-color:rgb(253, 246, 227);border:none;white-space:pre-wrap;\\\">auto-vpn start</code>，就可以将布置了shadowsocks服务端的EC2实例运行起来，并且在本地启动shadowsocks的服务端。在使用完毕之后输入<code style=\\\"font-family:Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace;border-radius:3px;padding:2px 4px;font-size:12px;color:rgb(101, 123, 131);background-color:rgb(253, 246, 227);border:none;white-space:pre-wrap;\\\">auto-vpn stop</code>就可以停止EC2实例并且关闭shadowsocks客户端。如果想要查看EC2实例的当前状态可以输入<code style=\\\"font-family:Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace;border-radius:3px;padding:2px 4px;font-size:12px;color:rgb(101, 123, 131);background-color:rgb(253, 246, 227);border:none;white-space:pre-wrap;\\\">auto-vpn status</code>命令。</p>\\\n</div>\\\n        </div></div></div></div></div></div></div></div><br/></div></span>\\\n</div></body></html>\\u0000\"]],\"start1\":0,\"start2\":0,\"length1\":0,\"length2\":12604}]"
metadata_diff: {"new":{"id":"c66e5c631aea4812a799327b313efa44","parent_id":"061de1401cfc4cfaadf6e74e015970e9","latitude":"0.00000000","longitude":"0.00000000","altitude":"0.0000","author":"","source_url":"","is_todo":0,"todo_due":0,"todo_completed":0,"source":"joplin-desktop","source_application":"net.cozic.joplin-desktop","application_data":"","order":1764345715962,"markup_language":2,"is_shared":0,"share_id":"","conflict_original_id":"","master_key_id":"","user_data":"","deleted_time":0},"deleted":[]}
encryption_cipher_text: 
encryption_applied: 0
updated_time: 2025-11-28T16:12:32.160Z
created_time: 2025-11-28T16:12:32.160Z
type_: 13