Docker series builds an open source bastion machine based on next-terminal
本文最后更新于 362 天前,其中的信息可能已经有所发展或是发生改变,如有失效可到评论区留言。

Preface

其实这篇文章我本来不想写的,对于网上一搜一大片的内容我从来都是懒得写的。。但是后来想想,以这个为契机,把我搭建一个应用的流程(主要包含了数据库的利旧)从头到尾记录一遍,在将来需要的时候直接一个:参看我的xx文章之类,反而可以偷更多的懒,所以才有了这篇文章。

next-terminal和其他一些应用(nextcloud,wordpress,chevereto,shlink,jumpserver等)一样,需要用到数据库,以下是官方对环境变量的说明:

image.png


说到这里,其实我还是建议大家,在部署一个应用的时候,尽量去看一看官方(如果没有官方网站,可以看看github或者docker hub上相关的网页)的文档说明,有时候网上的教程未必说得全面,也未必适合你的环境,所以尽量养成一个看官方文档的好习惯。


我一般都使用mariaDB,虽然这里写的mysql,但是大部分情况下,mariaDB可以认为和mysql是兼容的(我也遇到过不兼容的,不过目前只有一次),也有的应用会把mysql和maria区分开来作为不同的数据库类型(例如shlink)。本次部署我数据库依然采用mariaDB来代替mysql。

Initialize the database

以前的文章我提到过,我只会直接使用已有的数据库,不会动不动就用docker compose拉新的数据库起来,所以遇到这类需要依赖mariaDB数据库的应用,我都必须先手动初始化话数据库。具体步骤参考如下文章:Tips and tricks: Create a new empty database and grant permissions to corresponding users。根据文章中的步骤创建名为"next-terminal"的库,以及名为"next-terminal"的数据库用户(密码请自行定义)并对用户赋予访问该库的权限。

If there is no existing database, you need to create a new database container and then initialize the database. Refer to the following command:

docker run --name=mariadb01 -d --restart=always --network=public-net \
  -p 3306:3306 \
  -v /docker/mariadb/db:/var/lib/mysql \
  -e MARIADB_ROOT_PASSWORD=yourpassword \
  mariadb:10.11

Creating a bridge

Because a bridge named public-net is used below, it needs to be created in advance:

docker network create public-net

部署guacamole

guacamole是为了让我们能直接通过浏览器以web方式访问RDP、VNC、SSH的远程桌面网关(也可称之为跳板机,因为如果没有它,就真的需要单独的跳板机了)。

新建容器命令如下:

docker run --name=guacd -d --restart=always --network=public-net \
  -v /docker/next-terminal/data:/usr/local/next-terminal/data \
  dushixiang/guacd:latest

上述-v参数挂载的目录/docker/next-terminal/data就是下面要安装的next-terminal容器的挂载目录

–network=public-net 这个参数guacd的容器和next-terminal容器都要指定,否则next-terminal和guacd之间的关联就只能靠–link了


在同一个非默认的bridge内的容器都可以直接以容器名通信,–link并不是一个好的方式,后期这种关联多了以后可能会把自己搞晕。所以建议大家养成好的习惯,新建容器的时候用–network(或者–net)添加到同一个bridge网络,或者提前规划好,放在不同的bridge里,方便需要的时候用容器名直接通信。


部署next-terminal

docker run --name next-terminal -d --restart=always --network=public-net \ -p 8088:8088 \ -v /docker/next-terminal/data:/usr/local/next-terminal/data \ -v /etc/localtime:/etc/localtime \ -e DB=mysql \ -e MYSQL_HOSTNAME=mariadb01 \ -e MYSQL_PORT=3306 \ -e MYSQL_USERNAME=nextterminal \ -e MYSQL_PASSWORD=yourpassword \ -e MYSQL_DATABASE=nextterminal \ - e GUACD_HOSTNAME=guacd \ -e GUACD_PORT=4822 \ dushixiang/next-terminal:latest

Parameter explanation:
-p 8088:8088 将容器的8088端口映射到宿主机的8088端口,前面的8088端口为宿主机端口,大家可以根据自己的实际情况进行修改
-v /docker/next-terminal/data:/usr/local/next-terminal/data The host machine/docker/next-terminal/data挂载到容器里的/usr/local/next-terminal/data目录
-v /etc/localtime:/etc/localtime 将宿主机的本地时间同步到docker
-e DB=mysql \ 指定数据库类型为mysql
-e MYSQL_HOSTNAME=mariadb01 你的数据库容器名称或者对外的IP地址。如果部署的mariadb数据库也在这台宿主机上,且也用了--network=public-net参数,则这里就可以直接用数据库对应的容器名进行直接调用,否则就只能用–link命令硬关联数据库的容器名;如果不在同一台宿主机,这里就需要用部署数据库的宿主机的IP通过网络访问数据库
-e MYSQL_PORT=3306 指定mariadb的端口。如果是同一台宿主机且网络是同一个bridge,则直接使用3306端口;如果不是同一台宿主机,则使用数据库对外映射的端口
-e MYSQL_USERNAME=nextterminal 初始化数据库时候新建的数据库用户名称
-e MYSQL_PASSWORD=yourpassword 初始化数据库时候设置的数据库用户密码
-e MYSQL_DATABASE=nextterminal 初始化数据库时候新建的库名称
-e GUACD_HOSTNAME=guacd 前面新建的guacamole容器的名称
-e GUACD_PORT=4822 guacd代理的监听端口,默认就是4822,因为是容器内网络访问,所以前提是和next-terminal位于同一个非默认bridge

如果前面的准备工作都做好的话,现在next-terminal已经可以直接通过http://宿主机ip:8088进行登录了:

image.png

默认用户名和密码均为admin
image.png

Mission accomplished.

后续的步骤我就不详细说了,网上教程很多,一句话归纳就是:添加资产,然后点击"接入"进行连接:

image.png

image.png

image.png

讲道理,这个比jumpserver简单多了,jumpserver我现在都还是处于懵逼的状态:(,主要是以前没玩过专业的堡垒机,对一些概念比较陌生,而且对家庭数据中心而言,那些高档功能的确是用不上,所以没有啥研究的动力。本来我是准备写jumpserver,但是搭建完以后被里面的一些概念搞晕了,最终就妥协下改用next-terminal了。

关于jumpserver,有兴趣大家也可以自行尝试下,除了一样要初始化数据库之外,还需要提前部署redis,如果没有部署,参考如下命令:

docker run --name redis -d --restart=always --network=public-net -p 6379:6379 redis

我安装的是all in one版本,命令如下:

docker run --name jumpserver -d --restart=always --network=public-net \
  -v /docker/jumpserver/core/data:/opt/jumpserver/data \
  -v /docker/jumpserver/koko/data:/opt/koko/data \
  -v /docker/jumpserver/lion/data:/opt/lion/data \
  -p 9040:80 \
  -p 2222:2222 \
  -p 30000-30100:30000-30100 \
  -e SECRET_KEY=xxxxxxxx \
  -e BOOTSTRAP_TOKEN=xxxxxxxx \
  -e LOG_LEVEL=ERROR \
  -e DB_HOST=mariaDB01 \
  -e DB_PORT=3306 \
  -e DB_USER=jumpserver \
  -e DB_PASSWORD=yourpassowrd \
  -e DB_NAME=jumpserver \
  -e REDIS_HOST=redis \
  -e REDIS_PORT=6379 \
  --privileged=true \
  jumpserver/jms_all:v3.4.3

具体网上教程很多,大家搜一下即可,我就不折腾了。

Configuring public network access

If you want to publish to the public Internet, you need to choose the most suitable publishing method according to the actual environment and the reverse proxy you use. You can refer to my previous articles:
1,Docker series uses Docker to build its own reverse proxy based on NPM
2,Linux panel series configure reverse proxy and use non-443 port for publishing
3.Home data center series uses domestic cloud hosting to get free cloudflare to achieve fast access to domestic sites from abroad
4.Home Data Center Series: Use cloudflare to build a website quickly with no public IP in your home broadband (general purpose)

The first and second methods are suitable for environments with public IP but no legal 443 port (home broadband, unregistered cloud host). You need to add a non-standard port after the URL (if you use cloudflare to build a website, you don't need to add a port, but you need to customize the source station port. You can refer to:Home data center series uses cloudflare's Origin Rules to solve the problem of having a public IP but no legal ports 80 and 443 when building a websiteThe third method is suitable for cloud hosts with a record, and the fourth method is suitable for all environments (including environments without public IP), which is also the method I recommend (regardless of whether your environment has a public IP or not, because this method does not require running https traffic directly on the public network).

The content of the blog is original. Please indicate the source when reprinting! For more blog articles, you can go toSitemapUnderstand. The RSS address of the blog is:https://blog.tangwudi.com/feed, welcome to subscribe; if necessary, you can joinTelegram GroupDiscuss the problem together.
No Comments

Send Comment Edit Comment


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠(ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ°Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
Emoticons
Emoji
Little Dinosaur
flower!
Previous
Next
       
error:
en_US
Spring Festival
hapiness