0%

从零开始配置VPS

环境

  • Ubuntu 16.04 x64

ssh无密登录

创建 ssh 公私钥

1
2
3
ssh-keygen -t rsa
cd ~/.ssh/
cat id_rsa.pub

将公钥 id_rsa.pub 的内容 copy,链接上服务器

1
ssh root@[domain] -p [port]

默认会在 root 用户目录下,这个时候我们需要再次生成一对公私钥

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
root@hot-cluster:~# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:JO3v66ip8fefzexPuZR2/7uoDXtfqy1DIzNMrRleJYc root@hot-cluster-1.localdomain
The key's randomart image is:
+---[RSA 2048]----+
| . |
| . E o |
| . o . + |
| + o o |
| S + = |
| . O o o|
| . ..= .=+|
| o ..o +O=.*|
| ..+o.o====XOB|
+----[SHA256]-----+
root@hot-cluster:~# ls -la
total 32
drwx------ 5 root root 4096 Aug 20 06:17 .
drwxr-xr-x 23 root root 4096 Aug 20 05:26 ..
-rw-r--r-- 1 root root 3106 Oct 22 2015 .bashrc
drwx------ 2 root root 4096 Mar 14 2017 .cache
drwxr-xr-x 2 root root 4096 Mar 14 2017 .nano
-rw-r--r-- 1 root root 148 Aug 17 2015 .profile
drwx------ 2 root root 4096 Aug 20 06:17 .ssh
-rw-r--r-- 1 root root 197 Aug 20 05:27 virt-sysprep-firstboot.log
root@hot-cluster:~#

进入到 .ssh 目录,创建一个 authorized_keys 文件,并给一个 644 的权限,将我们本机的公钥,也就是 id_rsa.pub 的内容粘贴进去。退出,重新连接该服务器,你会发现已经不需要你再输入密码了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
root@hot-cluster:~# cd .ssh/
root@hot-cluster:~/.ssh# ls
id_rsa id_rsa.pub
root@hot-cluster:~/.ssh# touch authorized_keys
root@hot-cluster:~/.ssh# ls
authorized_keys id_rsa id_rsa.pub
root@hot-cluster:~/.ssh# chmod 644 authorized_keys
root@hot-cluster:~/.ssh# ll
total 16
drwx------ 2 root root 4096 Aug 20 06:22 ./
drwx------ 5 root root 4096 Aug 20 06:17 ../
-rw-r--r-- 1 root root 0 Aug 20 06:22 authorized_keys
-rw------- 1 root root 1675 Aug 20 06:17 id_rsa
-rw-r--r-- 1 root root 412 Aug 20 06:17 id_rsa.pub
root@hot-cluster-1:~/.ssh# vim authorized_keys
root@hot-cluster-1:~/.ssh# cat authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQAxBAAABsdAQDA4JC3Ag2DZsH77YP6bIX0bC5BT+JADyVry7ktGYso2hbPyvgAZo2pnA+Q1WO2Tz3JxnJolDXhJIOm+mRrra1pufJX181LzEI4kBWxZmGHDsj6SoiHOwNgyXcTsS0ixctnL+DDLS8ncD5q40/iKgo7N9p9fE8aBLsd56WgfxU26WNDn3WzM3YNaTEmPnZ6+p6bwe5xnTR0S9sXyWIBfibAXnKzrccYQ9/CLAkL/hHVQzlUnii76gy0E/7Zg9FIta4X2a2tazBbB+ZchuJUEl/j6AfBKwetAIEPq5PEzWEj5oNZJXGFVOAw9TXqDXAbqqmSq/lqOrBD6lbNVXxs5REFPn3 xxx@xxxx-xxx.local
root@hot-cluster-1:~/.ssh# exit

配置nginx二级域名分发

安装nginx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
sudo apt update
sudo apt install nginx
sudo ufw allow 'Nginx HTTP'
# 检查下 nginx 的状态
sudo systemctl status nginx
# output
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2019-08-20 06:35:40 EDT; 15h ago
Process: 1983 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=1/FAILURE)
Process: 1900 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 1996 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 1902 (nginx)
Tasks: 3
Memory: 2.2M
CPU: 4.669s
CGroup: /system.slice/nginx.service
├─19902 nginx: master process /usr/sbin/nginx -g daemon on; master_process on
├─19903 nginx: worker process
└─19904 nginx: worker process

Aug 20 06:35:40 hot-cluster.localdomain systemd[1]: Starting A high performance web server and a reverse proxy server...
Aug 20 06:35:40 hot-cluster.localdomain systemd[1]: Started A high performance web server and a reverse proxy server.

nginx 状态变更

  • 停止 nginx

    1
    sudo systemctl stop nginx
  • 重启 nginx

    1
    sudo systemctl restart nginx
  • 启动 nginx

    1
    sudo systemctl start nginx
  • 重新加载

    1
    sudo systemctl reload nginx

nginx 配置

接下来,需要配置nginx,使我们域名能够分发到二级域名去,通过如下命令找到nginx的配置文件地址

1
2
3
root@hot-cluster:/etc/nginx/conf.d# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

从上面返回的结果可以看到配置文件在 /etc/nginx 目录下,进入这个目录,使用 cat 命令查看一下 nginx.conf 文件,通常我们不会直接在 nginx.conf 文件中修改,而是在 nginx.conf 中引入文件的目录下去增加修改配置文件

1
2
3
4
5
6
7
8
9
10
11
http {

......

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}

http 模块中有个 Virtual Host Configs 可以看到配置文件包含了 /etc/nginx/conf.d/ 下所有的 .conf 文件。我们要给二级目录增加一个server,用来解析二级域名,在 /etc/nginx/conf.d/ 目录下创建一个 conf 文件

创建完毕后,我们需要将服务配置进去,所以这里我们需要先启动我们的服务,这里启动一个ssmgr的服务,要先处理后面的内容。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
server {
listen 80;
server_name x.xxxxxx.com;
rewrite ^(.*)$ https://$host$1 permanent;
}
server {
listen 443;
server_name x.flyriven.com;
ssl on;
ssl_certificate /root/Dropbox/x.xxxxxx.com/Nginx/1_x.xxxxxx.com_bundle.crt;
ssl_certificate_key /root/Dropbox/x.xxxxx.com/Nginx/2_x.xxxxxx.com.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;

location / {
proxy_set_header Host $host:$server_port;
proxy_pass http://127.0.0.1:9999;
}
}

这里用了腾讯云申请的证书,一定要去搞个证书,不然的话,订阅功能不能正常使用。

安装Dropbox

为什么我们需要Dropbox呢,有了Dropbox,我们可以在自己的电脑上编辑一些内容,同步到服务器上,避免了你手动登录服务器,去创建文件,设置权限等等一系列复杂的操作。比如efb的配置文件内容。

Dropbox 的安装特别简单。

  • 下载 Dropbox
  • 运行 Dropbox 守护程序
  • 通过 python 脚本启动 Dropbox

下载 Dropbox

我的VPS系统是 Ubuntu 16.04 x86_64 的,一条命令搞定:

1
cd ~ && wget -O - "https://www.dropbox.com/download?plat=lnx.x86_64" | tar xzf -

如果是其他 32 位的 Linux 发行版本 使用下面这条, 64 位的使用上面这条:

1
cd ~ && wget -O - "https://www.dropbox.com/download?plat=lnx.x86" | tar xzf -

运行 Dropbox 守护程序

下载速度非常快,看到如下界面即是下载完成:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
root@hot-cluster:~# wget -O - "https://www.dropbox.com/download?plat=lnx.x86_64" | tar xzf -
--2019-08-20 22:19:35-- https://www.dropbox.com/download?plat=lnx.x86_64
Resolving www.dropbox.com (www.dropbox.com)... 162.125.2.1, 2620:100:6017:1::a27d:201
Connecting to www.dropbox.com (www.dropbox.com)|162.125.2.1|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://clientupdates.dropboxstatic.com/dbx-releng/client/dropbox-lnx.x86_64-79.4.143.tar.gz [following]
--2019-08-20 22:19:36-- https://clientupdates.dropboxstatic.com/dbx-releng/client/dropbox-lnx.x86_64-79.4.143.tar.gz
Resolving clientupdates.dropboxstatic.com (clientupdates.dropboxstatic.com)... 13.225.144.57
Connecting to clientupdates.dropboxstatic.com (clientupdates.dropboxstatic.com)|13.225.144.57|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 95990187 (92M) [binary/octet-stream]
Saving to: 'STDOUT'

- 100%[========================================================================>] 91.54M 30.1MB/s in 3.0s

2019-08-20 22:19:39 (30.1 MB/s) - written to stdout [95990187/95990187]

root@hot-cluster-1:~# ll
total 56
drwx------ 8 root root 4096 Aug 20 22:20 ./
drwxr-xr-x 23 root root 4096 Aug 20 06:29 ../
-rw------- 1 root root 506 Aug 20 06:36 .bash_history
-rw-r--r-- 1 root root 3106 Oct 22 2015 .bashrc
drwx------ 2 root root 4096 Mar 14 2017 .cache/
drwxr-xr-x 7 root root 4096 Aug 20 22:20 .dropbox/
drwxrwxr-x 3 1000 1000 4096 Aug 13 07:34 .dropbox-dist/
drwxr-xr-x 2 root root 4096 Mar 14 2017 .nano/
-rw-r--r-- 1 root root 148 Aug 17 2015 .profile
drwx------ 2 root root 4096 Aug 20 06:22 .ssh/
-rw------- 1 root root 1100 Aug 20 22:15 .viminfo
-rw-r--r-- 1 root root 172 Aug 20 22:19 .wget-hsts
-rw-r--r-- 1 root root 197 Aug 20 05:27 virt-sysprep-firstboot.log

可以看到我们用户目录下已经有一个隐藏的目录 .dropbox/ 接下来我们需要执行 Dropbox 的守护程序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
root@hot-cluster:~# ~/.dropbox-dist/dropboxd
dropbox: locating interpreter
dropbox: logging to /tmp/dropbox-antifreeze-lRsecj
dropbox: initializing
dropbox: initializing python 3.7.2
dropbox: setting program path '/root/.dropbox-dist/dropbox-lnx.x86_64-79.4.143/dropbox'
dropbox: setting home path '/root/.dropbox-dist/dropbox-lnx.x86_64-79.4.143'
dropbox: setting python path '/root/.dropbox-dist/dropbox-lnx.x86_64-79.4.143:/root/.dropbox-dist/dropbox-lnx.x86_64-79.4.143/python-packages-37.zip'
dropbox: python initialized
dropbox: running dropbox
dropbox: setting args
dropbox: applying overrides
dropbox: running main script
dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-79.4.143/cryptography.hazmat.bindings._constant_time.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-79.4.143/cryptography.hazmat.bindings._openssl.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-79.4.143/cryptography.hazmat.bindings._padding.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-79.4.143/psutil._psutil_linux.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-79.4.143/psutil._psutil_posix.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-79.4.143/linuxffi.pthread._linuxffi_pthread.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-79.4.143/cpuid.compiled._cpuid.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-79.4.143/tornado.speedups.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-79.4.143/apex._apex.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-79.4.143/linuxffi.resolv.compiled._linuxffi_resolv.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-79.4.143/librsyncffi.compiled._librsyncffi.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-79.4.143/linuxffi.sys.compiled._linuxffi_sys.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-79.4.143/posixffi.libc._posixffi_libc.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-79.4.143/linuxffi.gnu.compiled._linuxffi_gnu.cpython-37m-x86_64-linux-gnu.so'
Dropbox ...
https://www.dropbox.com/cli_link_nonce?nonce=5f30616049d385497f188f52421b38a6
Dropbox ...
https://www.dropbox.com/cli_link_nonce?nonce=5f30616049d385497f188f52421b38a6
Dropbox ...
https://www.dropbox.com/cli_link_nonce?nonce=5f30616049d385497f188f52421b38a6
Dropbox ...
https://www.dropbox.com/cli_link_nonce?nonce=5f30616049d385497f188f52421b38a6
Dropbox ...
https://www.dropbox.com/cli_link_nonce?nonce=5f30616049d385497f188f52421b38a6
Dropbox ...
https://www.dropbox.com/cli_link_nonce?nonce=5f30616049d385497f188f52421b38a6
Dropbox ...
https://www.dropbox.com/cli_link_nonce?nonce=5f30616049d385497f188f52421b38a6
Dropbox ...
https://www.dropbox.com/cli_link_nonce?nonce=5f30616049d385497f188f52421b38a6
Dropbox ...
https://www.dropbox.com/cli_link_nonce?nonce=5f30616049d385497f188f52421b38a6
Dropbox ...
https://www.dropbox.com/cli_link_nonce?nonce=5f30616049d385497f188f52421b38a6
Dropbox xxxx xxxx

这里当我们看到:

1
2
Dropbox ...
https://www.dropbox.com/cli_link_nonce?nonce=5f30616049d385497f188f52421b38a6

出现时,需要将这个网址复制出来,粘贴到浏览器中访问,绑定设备到Dropbox

然后就会看到最后一条 Dropbox xxxx xxxx ,这里的 xxxx xxxx 是你的账号信息。

最后一步我们需要使用官方提供的python脚本来启动Dropbox

启动Dropbox

打开网址: https://www.dropbox.com/install-linux

在最下面找到 Python 脚本 的超链接,点击下载,或者直接访问这个网址:

https://www.dropbox.com/download?dl=packages/dropbox.py

或许你还可以使用 wget 之类的命令行工具下载这个脚本

下一步我们使用 python3 来执行这个脚本,注意,我们系统是Ubuntu 16.04,幸运的是系统自带 python3 直接使用就行,如果你的系统不是自带 python3 的,那么将你的系统改为 Ubuntu 16.04,因为其他版本的Ubuntu安装不上Dropbox。这个比较遗憾。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
root@hot-cluster:~# python3 dropbox.py help
Dropbox command-line interface

commands:

Note: use dropbox help <command> to view usage for a specific command.

autostart automatically start Dropbox at login
exclude ignores/excludes a directory from syncing
filestatus get current sync status of one or more files
help provide help
lansync enables or disables LAN sync
ls list directory contents with current sync status
proxy set proxy settings for Dropbox
puburl get public url of a file in your Dropbox's public folder
running return whether Dropbox is running
sharelink get a shared link for a file in your Dropbox
start start dropboxd
status get current status of the dropboxd
stop stop dropboxd
throttle set bandwidth limits for Dropbox
update download latest version of Dropbox
version print version information for Dropbox

执行:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
root@hot-cluster-1:~# python3 dropbox.py start
Starting Dropbox...dropbox: locating interpreter
dropbox: logging to /tmp/dropbox-antifreeze-107MZM
dropbox: initializing
dropbox: initializing python 3.7.2
dropbox: setting program path '/root/.dropbox-dist/dropbox-lnx.x86_64-79.4.143/dropbox'
dropbox: setting home path '/root/.dropbox-dist/dropbox-lnx.x86_64-79.4.143'
dropbox: setting python path '/root/.dropbox-dist/dropbox-lnx.x86_64-79.4.143:/root/.dropbox-dist/dropbox-lnx.x86_64-79.4.143/python-packages-37.zip'
dropbox: python initialized
dropbox: running dropbox
dropbox: setting args
dropbox: applying overrides
dropbox: running main script
dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-79.4.143/cryptography.hazmat.bindings._constant_time.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-79.4.143/cryptography.hazmat.bindings._openssl.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-79.4.143/cryptography.hazmat.bindings._padding.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-79.4.143/psutil._psutil_linux.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-79.4.143/psutil._psutil_posix.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-79.4.143/linuxffi.pthread._linuxffi_pthread.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-79.4.143/cpuid.compiled._cpuid.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-79.4.143/tornado.speedups.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-79.4.143/apex._apex.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-79.4.143/linuxffi.resolv.compiled._linuxffi_resolv.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-79.4.143/librsyncffi.compiled._librsyncffi.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-79.4.143/linuxffi.sys.compiled._linuxffi_sys.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-79.4.143/posixffi.libc._posixffi_libc.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-79.4.143/linuxffi.gnu.compiled._linuxffi_gnu.cpython-37m-x86_64-linux-gnu.so'
Done!
root@hot-cluster-1:~#

看到 Done!就说明运行成功了,可以用 python3 dropbox.py status 来查看状态。

安装docker

dropbox 安装完了,不用等,接下来我们安装docker,这个可爱的小鲸鱼🐳,是我们接下来跑efb的重要工具。因为efbdocker版的。

  • 设置源
  • 安装docker
  • test docker

设置源

  1. 更新apt包索引

    1
    sudo apt update
  1. 安装包允许apt通过https来使用存储库

    1
    2
    3
    4
    5
    6
    sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common

    直接copy执行就行

  2. 添加docker官方的GPG密钥

    添加密钥:

    1
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

    然后在执行:

    1
    sudo apt-key fingerprint 0EBFCD88

    看到如下结果就是成功的:

    1
    2
    3
    4
    pub   rsa4096 2017-02-22 [SCEA]
    9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
    uid [ unknown] Docker Release (CE deb) <docker@docker.com>
    sub rsa4096 2017-02-22 [S]
  1. 添加源

    1
    2
    3
    4
    sudo add-apt-repository \
    "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
    $(lsb_release -cs) \
    stable"

    直接复制到终端执行就行。

  2. 更新包索引

    1
    sudo apt update
  1. 安装docker

    1
    sudo apt install docker-ce docker-ce-cli containerd.io

    安装完成之后在安装 docker-compose

    1
    sudo apt install docker-compose

    这样docker就安装完成了。

配置 EH Forwarder Bot

接下来配置 EFB,我们使用的版本是2.0的版本,docker镜像选择的是 akayakya 的。

  • 创建配置文件目录结构和文件
  • 创建telegram bot
  • yaml 配置
  • 启动EFB服务
  • 连接微信

创建配置文件目录结构和文件

先来看下结构树🌲长啥样:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
root@hot-cluster-1:~/Dropbox/docker_application# tree
.
`-- efb_v2
|-- blueset.telegram
| |-- config.yaml
| `-- tgdata.db
|-- blueset.wechat
| |-- config.yaml
| |-- wxpy.pkl
| `-- wxpy_puid.pkl
|-- config.yaml
`-- docker-compose.yml

3 directories, 7 files

这里说明一下,.pkl 结尾的文件是自动生成的。我们仅仅需要创建 .yaml | .yml 三种文件格式的文件。

上面我们安装了Dropbox,为了方便操作,将目录创建在Dropbox 的目录下,

1
2
3
4
5
6
root@hot-cluster-1:~# cd Dropbox/
root@hot-cluster-1:~/Dropbox# mkdir -p docker_application^C
root@hot-cluster-1:~/Dropbox# ls
20181110-????????????????????? 20190225-???????????? docker_application dropbox.py workspace
root@hot-cluster-1:~/Dropbox# cd docker_application/
root@hot-cluster-1:~/Dropbox/docker_application#

Docker_application 目录就专门用来存放一些docker镜像的yml文件吧。

接着,再创建efb_v2目录

1
2
3
4
5
root@hot-cluster-1:~/Dropbox/docker_application# mkdir -p efb_2v
root@hot-cluster-1:~/Dropbox/docker_application# ls
efb_v2
root@hot-cluster-1:~/Dropbox/docker_application# cd efb_v2/
root@hot-cluster-1:~/Dropbox/docker_application/efb_v2#

创建blueset.telegram 目录和blueset.wechat 目录,docker-compose.ymlconfig.yaml

1
2
3
4
5
6
root@hot-cluster-1:~/Dropbox/docker_application/efb_v2# mkdir -p blueset.telegram
root@hot-cluster-1:~/Dropbox/docker_application/efb_v2# mkdir -p blueset.wechat
root@hot-cluster-1:~/Dropbox/docker_application/efb_v2# touch config.yaml docker-compose.yml blueset.telegram/config.yaml blueset.wechat/config.yaml
root@hot-cluster-1:~/Dropbox/docker_application/efb_v2# ls
blueset.telegram blueset.wechat config.yaml docker-compose.yml
root@hot-cluster-1:~/Dropbox/docker_application/efb_v2#

这里注意docker-compose字母不要拼写错误。分别为blueset.telegramblueset.wechat目录下创建对应的配置文件。

创建Telegram bot

打开Telegram, @BotFather,输入 /newbot 创建一个bot,bot的名称需要以 _bot 作为结尾,这里做个小小的演示。

image-20190821141127861

到这步,我们就可以得到一个token了957778340:AAHXUvCWeqG-b6DXdkYOnukHWTvqhjYi9LE

接下来设置bot的命令:输入 /setcommands ,然后选择你刚创建的bot

image-20190821141326574

输入:

1
2
3
4
link - 将会话绑定到 Telegram 群组
chat - 生成会话头
recog - 回复语音消息以进行识别
extra - 获取更多功能

看到 Success! Command list updated. /help,说明设置成功。

然后配置privacy, 输入命令 /setprivacy, 选择刚创建的bot,然后选择disable

yaml 配置

1
2
3
4
5
6
# config.yaml
master_channel: blueset.telegram
slave_channels:
- blueset.wechat
middlewares:
# - catbaron.sticker2img
1
2
3
4
5
6
7
8
9
# docker-compose.yml
efb_v2:
image: akyakya/efb-v2:latest
container_name: efb_v2
restart: always
volumes:
- .:/root/.ehforwarderbot/profiles/default/
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
1
2
3
4
5
6
7
8
9
10
11
12
13
# blueset.telegram/config.yaml
token: "xxxxxxxxx:xxxxxxxxxxxx" #换成自己的bot token
admins:
- xxxxxxxx #换成自己的telegram 数字id
flags:
chats_per_page: 20 #选择/ chat和/ link命令时显示的聊天次数。过大的值可能导致这些命令的故障
network_error_prompt_interval: 100 #每收到n个错误后再通知用户有关网络错误的信息。 设置为0可禁用它
multiple_slave_chats: true #默认true #将多个远程聊天链接到一个Telegram组。使用未关联的聊天功能发送和回复。禁用以远程聊天和电报组一对一链接。
prevent_message_removal: true #当从通道需要删除消息时,如果此值为true,EFB将忽略该请求。
auto_locale: true #自动从管理员的消息中检测区域设置。否则将使用在环境变量中定义的区域设置。
retry_on_error: false #在向Telegram Bot API发送请求时发生错误时无限重试。请注意,这可能会导致重复的消息传递,因为Telegram Bot API的响应不可靠,并且可能无法反映实际结果
message_muted_on_slave: normal #normal:作为普通信息发送给Telegram silent:发送给Telegram作为正常消息,但没有通知声音 mute:不要发送给Telegram
your_message_on_slave: silent #在从属通道平台上收到消息时的行为。这将覆盖message_muted_on_slave中的设置。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# blueset.wechat/config.yaml
# 实验功能
# # 使用本段来调整实验功能的设置。请注意实验功能随时可能变更或失效。
# # 详细说明见下文。
flags:
refresh_friends: false #每当请求会话列表时,强制刷新会话列表。[默认值: false]
first_link_only: false #在收到多链接消息时,仅发送第一条链接。默认多链接会发送多条消息。 [默认值: false]
max_quote_length: -1 #引用消息中引文的长度限制。设置为 0 关闭引文功能。设置为 -1 则对引文长度不做限制。max_quote_length (int) [默认值: -1]
qr_reload: "master_qr_code" # "console_qr_code": 将二维码和提示输出到系统标准输出(stdout)。"master_qr_code": 将二维码和提示发送到主端。[默认值: "master_qr_code"]
on_log_out: "command" #微信服务器将用户登出时的操作。 选项:"idle": 仅通知用户。"reauth": 通知用户,并立即开始重新登录。"command": 通知用户,并等待用户启动重新登录过程。[默认值: "command"]
imgcat_qr: false #使用 iTerm2 图像协议 显示二维码。本功能只适用于 iTerm2 用户。[默认值: false]
delete_on_edit: true #以撤回并重新发送的方式代替编辑消息。默认禁止编辑消息。 [默认值: false]
app_shared_link_mode: "ignore" #在收到第三方合作应用分享给微信的链接时,其附带的预览图以何种形式发送。"ignore":忽略附带的缩略图"upload":将缩略图上传到公开图床(https://sm.ms),并在日志中输出图片的删除链接。"image":将消息以图片形式发送(不推荐)[默认值:"ignore"]
puid_logs: null #输出 PUID 相关日志到指定日志路径。请使用绝对路径。PUID 日志可能会根据会话数量和消息吞吐量 而占用大量存储空间。
send_stickers_and_gif_as_jpeg: false #以 JPEG 图片方式发送自定义表情和 GIF,用于临时绕过微信网页版的自定义表情限制。[默认值: true]

启动EFB服务

配置文件写完之后,我们需要启动这个服务。移动到 docker-compose.yml 的目录下,使用如下命令下载运行该镜像:

1
root@hot-cluster-1:~/Dropbox/docker_application/efb_v2# docker-compose up -d

这样就可以了,如果你对docker感兴趣,可以去官网看看其他的操作。然后我们下一步,接入我们的微信。

连接微信

接入这个微信的原理,其实是使用efb去登录了我们的网页版微信,然后所有的信息都会发到efb中,由efb处理之后才会让你在Telegram客户端看到内容,你可以使用Telegram去回复微信,创建分组各种。

我们需要查看docker镜像的日志,获取到登录网页微信的二维码或者网址。

1
root@hot-cluster-1:~/Dropbox/docker_application/efb_v2# docker-compose logs

手机打开微信,等日志加载完后,扫描最后一个二维码,点击登录即可。这样你就可以在 @testefb111_bot 这个 chat 中收到微信的聊天消息,reply 即可回复消息。

安装配置ssmgr

有了vps 没有ss就太可怜了,经过卢大佬的安利,我选择 ssmgr 来作为ss管理后台,这里选择普通安装方式。

  • 安装 shadowsocks
  • 安装 node.js 10.x
  • 安装 Redis 并设置密码
  • 安装 ssmgr

安装 shadowsocks

可以采用libevpython版本

这里我们选择python版本吧,毕竟系统默认就带了个python3。

  • 安装 pip
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
root@hot-cluster-1:~# apt install python3-pip
Reading package lists... Done
Building dependency tree
Reading state information... Done
# ......
After this operation, 201 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y # 输入 Y
# ......
Setting up python3-pip (8.1.1-2ubuntu0.4) ...
Setting up python3-setuptools (20.7.0-1) ...
Setting up python3-wheel (0.29.0-1) ...
Processing triggers for libc-bin (2.23-0ubuntu11) ...
root@hot-cluster-1:~# pip3 -V
pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5)
root@hot-cluster-1:~#

这样就安装好了!下面安装 shadowsocks

  • 安装 shadowsocks

因Shadowsocks作者不再维护pip中的Shadowsocks(定格在了2.8.2), 我们使用下面的命令来安装最新版的Shadowsocks

1
2
3
4
5
6
7
8
9
root@hot-cluster-1:~# pip3 install https://github.com/shadowsocks/shadowsocks/archive/master.zip
Traceback (most recent call last):
File "/usr/bin/pip3", line 11, in <module>
sys.exit(main())
File "/usr/lib/python3/dist-packages/pip/__init__.py", line 215, in main
locale.setlocale(locale.LC_ALL, '')
File "/usr/lib/python3.5/locale.py", line 594, in setlocale
return _setlocale(category, locale)
locale.Error: unsupported locale setting

来了个小惊喜,解决方法:

1
root@hot-cluster-1:~# export LC_ALL=C

再次安装:

1
2
3
4
5
6
7
8
9
10
root@hot-cluster-1:~# pip3 install https://github.com/shadowsocks/shadowsocks/archive/master.zip
Collecting https://github.com/shadowsocks/shadowsocks/archive/master.zip
Downloading https://github.com/shadowsocks/shadowsocks/archive/master.zip (115kB)
100% |################################| 122kB 342kB/s
Installing collected packages: shadowsocks
Running setup.py install for shadowsocks ... done
Successfully installed shadowsocks-3.0.0
You are using pip version 8.1.1, however version 19.2.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
root@hot-cluster-1:~#

看到 Successfully installed shadowsocks-XXX 就是安装成功了。

  • 创建配置文件

在 /etc 目录下创建 shadowsocks 配置文件所在目录

1
2
3
root@hot-cluster-1:~# mkdir /etc/shadowsocks
root@hot-cluster-1:~# cd /etc/shadowsocks
root@hot-cluster-1:~# touch config.json

使用 vim 编辑 config.json 粘贴一下内容,注意修改 password

1
2
3
4
5
6
7
8
9
10
{
"server":"::",
"server_port":8388,
"local_address": "127.0.0.1",
"local_port":1080,
"password":"mypassword",
"timeout":300,
"method":"aes-256-cfb",
"fast_open": false
}

完成之后测试一下看看能不能用。

  • 测试 shadowsocks 配置
1
2
3
4
root@hot-cluster-1:~# ssserver -c /etc/shadowsocks/config.json
INFO: loading config from /etc/shadowsocks/config.json
2019-08-21 03:15:24 INFO loading libcrypto from libcrypto.so.1.0.0
2019-08-21 03:15:24 INFO starting server at :::8388
  • 配置 Systemd 来管理 shadowsocks

测试通过后,我们将shadowsocks 做为一个服务来启动,这样的话比较方便。

  1. 创建 service 文件
1
root@hot-cluster-1:~# vim /etc/systemd/system/shadowsocks-server.service
  1. 编写服务内容: shadowsocks-server.service
1
2
3
4
5
6
7
8
9
10
[Unit]
Description=Shadowsocks Server
After=network.target

[Service]
ExecStart=/usr/local/bin/ssserver -c /etc/shadowsocks/config.json
Restart=on-abort

[Install]
WantedBy=multi-user.target
  1. 启动服务

启动Shadowsocks:

1
root@hot-cluster-1:~# systemctl start shadowsocks-server.service

设置开机启动:

1
2
3
root@hot-cluster-1:~# systemctl enable shadowsocks-server.service
Created symlink from /etc/systemd/system/multi-user.target.wants/shadowsocks-server.service to /etc/systemd/system/shadowsocks-server.service.
root@hot-cluster-1:~#

到此 shadowsocks 安装配置完毕,如果有进阶优化的需求的话,可以看下面的这个文章:

https://www.polarxiong.com/archives/Ubuntu-16-04%E4%B8%8BShadowsocks%E6%9C%8D%E5%8A%A1%E5%99%A8%E7%AB%AF%E5%AE%89%E8%A3%85%E5%8F%8A%E4%BC%98%E5%8C%96.html

安装 node.js 10.x

建议使用nodesource里边的方式安装

Ssmgr 官方推荐我们用 nodesource 方式来安装,点开看下。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
root@hot-cluster-1:~# curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -

## Installing the NodeSource Node.js 10.x repo...


## Populating apt-get cache...

+ apt-get update
Hit:1 http://us.archive.ubuntu.com/ubuntu xenial InRelease
Get:2 http://us.archive.ubuntu.com/ubuntu xenial-updates InRelease [109 kB]

# ......

## Run `sudo apt-get install -y nodejs` to install Node.js 10.x and npm
## You may also need development tools to build native addons:
sudo apt-get install gcc g++ make
## To install the Yarn package manager, run:
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install yarn


root@hot-cluster-1:~#

我们直接找到readme 中关于 Node.js v10.x 安装的部分,选择Using Ubuntu的内容

安装:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
root@hot-cluster-1:~# apt install nodejs -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
nodejs
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 15.8 MB of archives.
After this operation, 76.5 MB of additional disk space will be used.
Get:1 https://deb.nodesource.com/node_10.x xenial/main amd64 nodejs amd64 10.16.3-1nodesource1 [15.8 MB]
Fetched 15.8 MB in 3s (4951 kB/s)
Selecting previously unselected package nodejs.
(Reading database ... 99725 files and directories currently installed.)
Preparing to unpack .../nodejs_10.16.3-1nodesource1_amd64.deb ...
Unpacking nodejs (10.16.3-1nodesource1) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up nodejs (10.16.3-1nodesource1) ...

验证一下是否安装成功:

1
2
3
4
5
root@hot-cluster-1:~# node -v
v10.16.3
root@hot-cluster-1:~# npm -v
6.9.0
root@hot-cluster-1:~#

下一步走着。

安装 Redis 并设置密码

安装Redis,ssmgr 的文档同样没有给详细的文档。我们可以点击这里查看, 或者我们直接 apt 安装

1
2
3
root@hot-cluster-1:~# apt update
root@hot-cluster-1:~# apt install redis-server
root@hot-cluster-1:~# systemctl enable redis-server.service

上面,我们安装了redis-server 并且,将他设置为开机启动的服务了,下面我们来配置redis

1
root@hot-cluster-1:~# vim /etc/redis/redis.conf

安装 ssmgr

上面的准备工作都做完了,我们仅仅需要安装 ssmgr 就行了。

1
root@hot-cluster-1:~# npm i -g shadowsocks-manager --unsafe-perm

配置方面,官方写的比较完整:

https://shadowsocks.github.io/shadowsocks-manager/#/config?id=%E9%85%8D%E7%BD%AE%E9%A6%96%E4%B8%AA%E8%8A%82%E7%82%B9

over