Using FRP for Windows Remote Desktop

最近实验室出于“敏感原因”,禁掉了包括Teamviewer以及花生壳在内的大部分远程软件,直接导致无法在实验室外连接实验室内的电脑,大大缩短了科研人员的科研时间,基于以上原因,撰写本教程,帮助大家配置内网穿透以及远程桌面。

目录:

  1. 服务器、客户端准备
  2. 服务器及客户端FRP配置
  3. 如何进行远程桌面

 服务器、客户端准备

首先,需要准备一台服务器,这里推荐阿里云轻量应用服务器的学生优惠机,9.5元/月, 十分划算。预装环境选择系统镜像-CentOS 7.3/Ubuntu 16.04,购买成功后,进入服务 器控制台,机器分配好后,会提供一个固定IP,如下图所示:

之后,准备客户端,也就是你需要被远程的电脑,这里以Windows 10电脑为例,需要完成以下事情:

1. 打开本机远程控制

控制面板-系统-远程设置-勾选允许连接到此计算机,如下图所示:

  1. 添加端口3389到出站规则

控制面板-Windows Defender 防火墙-高级设置-新建规则-端口-TCP-特定远程端口。具 体过程如下图所示:

3. 关闭Windows Defender 防火墙

控制面板-Windows Defender 防火墙

服务器及客户端FRP配置

什么是FRP

frp 是一个高性能的反向代理应用,可以帮助您轻松地进行内网穿透,对外网提供服务,支持 tcp, http, https 等协议类型,并且 web 服务支持根据域名进行路由转发。

服务器FRP配置

首先,在服务器端依次执行以下指令下载并解压FRP安装包:

# 下载安装包
wget https://github.com/fatedier/frp/releases/download/v0.34.1/frp_0.34.1_linux_amd64.tar.gz

# 解压安装包文件
tar -zxvf frp_0.34.1_linux_amd64.tar.gz

完成解压后,通过cd命令进入指定文件夹,并删除客户端相关的文件

# 进入文件夹
cd frp_0.34.1_linux_amd64.tar.gz
# 删除文件
rm -f frpc
rm -f frpc.ini

之后,使用vim编辑服务器配置文件frps.ini。这里直接贴出我的配置文件,其中bind_port为服务器入站端口,dashboard系列为配置服 务端面板登录,可以通过访问your_server_ip:7500 来检查各端口使用情况。token相当于 客户端连接服务端的通关密码,http_proxy那一段代码则为设置通过代理连接frps。

[common]
bind_port = 7000
dashboard_user = admin
dashboard_password = admin
dashboard_port = 7500 

token = hunt1ey2 

[http_proxy]

type = tcp remote_port = 8010 plugin = http_proxy

配置好后,可以通过./frps -c frps.ini 启动FRP服务,可配合nohup达到服务器后台静默运行的需求。需注意,如使用阿里云服务器,需要在服务器安全设置中,添加所有使用的端口,如下所示:

客户端FRP配置

类似的方法下载FRP并解压,修改客户端配置文件frpc.ini,这里依然贴出我的配置文件供 大家参考。

[common] 
server_addr = 39.96.XX.XX 
server_port = 7000 
token = hunt1ey2 

[hunt1ey2]

type = tcp local_ip = 127.0.0.1 # 必须使用3389端口,这是远程桌面使用的端口 local_port = 3389 # 这是外网访问的端口 remote_port = 6000 # 使用加密,避免被发现 use_encryption = true # 设置socks5链接

[socks5]

type = tcp remote_port = 8010 plugin = socks5

由于frpc.exe需要有命令行启动,使用命令行cd到当前文件夹,使用命令frpc.exe -c frpc.ini 启动客户端服务。至此,所有配置工作已经完成,可以开始使用外网电脑远程控制内网电脑了。

如何进行远程桌面

以Windows为例,选择远程桌面连接,计算机选择your_server_ip:6000 就可以连接了。

Zotero: Manage Your Papers in an Easier Way

最近得闲,写一下如何使用Zotero进行论文管理,以方便实验室各位同学之后的文献查阅和整理。本文大致分为以下章节:
目录:

  1. 如何使用Zotero + Chrome满足日常科研需求
  2. 进阶:Zotero + 坚果云
  3. 进阶:Zotero + 阿里云

如何使用Zotero + Chrome满足日常科研需求

首先,我们来简要了解一下Zotero到底是什么。简单地讲,Zotero是一款集文献收集、整理、引用以及分享为一体的跨平台软件,支持Mac, Windows以及Linux,可以说是非常友好的跨平台论文管理工具了。

收集

下载Zotero,同时安装Zotero Connector(Chrome插件需要科学上网)



在Chrome插件安装好后,打开Zotero,就可以在Chrome右上角插件栏里将需要保存的pdf网页存到Zotero文库中了

整理

在Zotero中,我们可以在我的文库中,依据论文的topic等建立不同的分类,方便分门别类地管理不同的论文,如下图


在Chrome保存过程中,我们也可以直接选择对应的类别进行保存。对于已经保存的文献,我们可以进一步地添加文献的评论(用于记录对于文献的理解),标签(方便文献的检索)以及关联文献等

Zotero + 坚果云

如果有多设备同步的需求,可以注册Zotero账号,方便同步论文信息


但是Zotero自带免费同步空间300MB,其实根本不够用,因此,我们需要第三方的云服务,将论文存储到第三方云空间中(有钱的也可以直接充Zotero的会员),网上常用的方法是同步到坚果云(因为它支持WebDAV),这方面网上的教程很多了,直接贴个教程链接

Zotero + 阿里云

坚果云已经够好了,为什么还要用阿里云呢,主要原因是,坚果云每个月有流量上线,有上限的事情,就会让人觉得束手束脚,总归觉得不爽。于是我和磊磊琢磨出了用阿里云来进行同步的方法。阿里云真是个好东西啊,学生服务器一个月10块钱,frp也是它,云同步也是它,我的网站也是它,阿里云,yyds!

如果你的阿里云安装的Apache服务:

懒得写了,上链接吧:Apache+WebDAV

如果你的阿里云安装的Nginx服务:

但是如果你同时用阿里云搭了个人网站,那你有可能是安装的Nginx服务,这需要你进宝塔管理页面,选择编译安装Nginx,然后下载Nginx-WebDAV插件
git clone https://github.com/arut/nginx-dav-ext-module.git /root/nginx-dav-ext-module
编辑Nginx安装脚本
vi /www/server/panel/install/nginx.sh
找到./configure那一行,在后面添加
--with-http_dav_module --add-module=/root/nginx-dav-ext-module
选择安装Nginx,安装好之后nginx -V 查看安装参数
在宝塔面板新建一个网站

但是如果你同时用阿里云搭了个人网站,那你有可能是安装的Nginx服务,这需要你进宝塔管理页面,选择编译安装Nginx,然后下载Nginx-WebDAV插件
git clone https://github.com/arut/nginx-dav-ext-module.git /root/nginx-dav-ext-module
编辑Nginx安装脚本
vi /www/server/panel/install/nginx.sh
找到./configure那一行,在后面添加
--with-http_dav_module --add-module=/root/nginx-dav-ext-module
选择安装Nginx,安装好之后nginx -V 查看安装参数
在宝塔面板新建一个网站

修改域名等信息

修改网站配置文件,在末尾添加如下代码:

修改网站配置文件,在末尾添加如下代码:

[common]
location / {
root /www/wwwroot/webdav.zihaozhang.tech; #注意修改成自己的目录
#client_max_body_size 102400M; #大文件支持
autoindex on;
dav_methods PUT DELETE MKCOL COPY MOVE;
# 需要 nginx-dav-ext-module 才有下面的选项
dav_ext_methods PROPFIND OPTIONS LOCK UNLOCK;
create_full_put_path  on;
}

添加密码访问


在对应目录下新建zotero文件夹,配置zotero:

On how to use the server in our laboratory

Preface

Recently, I reinstalled the server OS in our laboratory, and decided to manage the server usage methods so that my colleagues can get better user experience on it. The article will be divided into the following three parts.

Virtual Environment

I strongly advise using Anaconda to manage the virtual environment, so that your environment won’t be influenced by the others who share the same server with you. The steps are as follows.

  1. See the existing conda virtual environment and see whether there are similar virtual environment for your need
conda -env list
  1. Use the following code to create your own virtual environment. Use “-p” to specify the path, or it will be installed in the “$HOME/.conda/envs/env_name”; use “-n” to name your environment; use “–clone” to decide the virtual environment you want to clone from; use “–python” to specify the python version you want to use; you can also specify the package you need, such as pip and matplotlib
conda create -p /home/zhangzihao/env-name/
  1. Activate your environment. What should be noted is that if you specify the installation path, you should use the full path instead of your environment name.
conda activate env_name
  1. Install the package you need using the following command. If you installed pip during creation, you may also use pip to install the package
  2. Make sure to deactivate your environment if you don’t need to use it anymore.
conda deactivate
# to delete an environment, use:
conda env remove -n env_name

Remote Debugging

As for how to run your project on the server, I sincerly recommend using PyCharm “SSH Interpreter”. The configuration process are as follows.

1. Deployment Configuration

Tools->Deployment->Configuration, this step mainly setup the SFTP server for your Pycharm.

Add an new SFTP server, fill in the user name and password as well as the path where you want to save your project on the server. Here is an example. After this, you will be able to see the remote file catalog via Tools->Deployment->Browse Remote Host

Then, set the mappings. This step helps you to map your local project to the server. The deployment path is the root path + current path, for example, in my configuration, it’s “/home/zhangzihao/test” + “/”

After that, the remote file catalog should turn green, then you can upload your project to the server via: Tools->Deployment->Upload to…

2. Remote Interpreter Configuration

First, choose to add a new project interpreter via: File->Settings->Project: your_project_name->Add

Choos “SSH Interpreter” and then select “Existing server configuration”, chose the deployment configuration you set in the previous step. Then, chose “Move this server to IDE settings”.

Set the interpreter path and sync folders, then press next. What should be noted is that if you use a virtual environment, the interpreter path is under the path you set when you configure your virtual environment.

  • Thanks to Lei Hu, we can also use frp to map the port 22 on the server to your frp server port, and add the remote interpreter from outer net.

Graphical interfaces

Here, I mainly refer to how to get the graphical interface remotely. All of our servers has installed XRDP and can be directly connected using Windows Remote Desktop. However, what if you just want to get a graphical result, such as cv2.imshow() if you are using PyCharm remote debugging? Xserver should be the answer.

Using Xserver can make you get a graphical result in the command line. The easiest way is to use MobaXterm. You can also use Xming + Xshell to get it.

1. Xming Configuration

  • Open XLaunch, set the display number and remember it.
  • Next–> Start no client –>Clipbard–>Complete
  • Modify the X0.hosts under the Xming installation path, add the IP address under the localhost line.

2. XShell Configuration

Follow the image below, in localhost:0.0, the first zero is your display number

3. PyCharm Configuration

  • run the command “echo $DISPLAY”, you will get a returned value: localhost XX.0
  • add DISPLAY=XX.0 to the PyCharm Run/Debug Configurations Environment variable