安装网关

安装网关 #

极限网关支持主流的操作系统和平台,程序包很小,没有任何额外的外部依赖,安装起来应该是很快的 :)

安装演示 #

下载安装 #

根据您所在的操作系统和平台选择下面相应的下载地址:

https://github.com/medcl/infini-gateway/releases

最新快照的下载地址访问:这里

容器部署 #

极限网关也支持 Docker 容器方式部署。

了解更多

验证安装 #

极限网关下载解压之后,我们可以执行这个命令来验证安装包是否有效,如下:

✗ ./bin/gateway -v
gateway 1.0.0_SNAPSHOT 2021-01-03 22:45:28 6a54bb2

如果能够正常看到上面的版本信息,说明网关程序本身一切正常。

启动网关 #

以管理员身份直接运行网关程序即可启动极限网关了,如下:

➜ sudo ./bin/gateway
   ___   _   _____  __  __    __  _       
  / _ \ /_\ /__   \/__\/ / /\ \ \/_\ /\_/\
 / /_\///_\\  / /\/_\  \ \/  \/ //_\\\_ _/
/ /_\\/  _  \/ / //__   \  /\  /  _  \/ \ 
\____/\_/ \_/\/  \__/    \/  \/\_/ \_/\_/ 

[GATEWAY] A light-weight, powerful and high-performance elasticsearch gateway.
[GATEWAY] 1.0.0_SNAPSHOT, 4daf6e9, Mon Jan 11 11:40:44 2021 +0800, medcl, add response_header_filter
[01-11 16:43:31] [INF] [instance.go:24] workspace: data/gateway/nodes/0
[01-11 16:43:31] [INF] [api.go:255] api server listen at: http://0.0.0.0:2900
[01-11 16:43:31] [INF] [runner.go:59] pipeline: primary started with 1 instances
[01-11 16:43:31] [INF] [runner.go:59] pipeline: nodes_index started with 1 instances
[01-11 16:43:31] [INF] [entry.go:262] entry [es_gateway] listen at: https://0.0.0.0:8000
[01-11 16:43:32] [INF] [floating_ip.go:170] floating_ip listen at: 192.168.3.234, echo port: 61111
[01-11 16:43:32] [INF] [app.go:254] gateway now started.

看到上面的启动信息,说明网关已经成功运行了,并且监听了响应的端口。

访问网关 #

使用浏览器或者其它客户端即可正常访问由网关代理的后端 Elasticsearch 服务了,如下:

停止网关 #

如果需要停止网关,按 Ctrl+C 即可停止极限网关,如下:

^C
[GATEWAY] got signal: interrupt, start shutting down
[01-11 16:44:41] [INF] [app.go:303] gateway now terminated.
[GATEWAY] 1.0.0_SNAPSHOT, uptime: 1m10.550336s

Thanks for using GATEWAY, have a good day!

后台运行 #

如果希望将极限网关以后台任务的方式运行,如下:

➜ sudo ./bin/gateway -daemon -pidfile=/tmp/gateway.pid
   ___   _   _____  __  __    __  _       
  / _ \ /_\ /__   \/__\/ / /\ \ \/_\ /\_/\
 / /_\///_\\  / /\/_\  \ \/  \/ //_\\\_ _/
/ /_\\/  _  \/ / //__   \  /\  /  _  \/ \ 
\____/\_/ \_/\/  \__/    \/  \/\_/ \_/\_/ 

[GATEWAY] A light-weight, powerful and high-performance elasticsearch gateway.
[GATEWAY] 1.0.0_SNAPSHOT, aa6f614, Mon Jan 11 14:48:17 2021 +0800, medcl, add request_client_ip_filter
[GATEWAY] started in background, pid: 16474

通过 PID 可以方便的停止极限网关,如下:

sudo  kill -9 `cat /tmp/gateway.pid`

系统服务 #

如果希望将极限网关当做一个系统服务来管理,可以将网关程序拷贝到 /opt/gateway/bin/gateway 位置,将配置文件拷贝到 /etc/gateway/gateway.yml 位置, 然后新增一个系统服务,编辑 /usr/lib/systemd/system/gateway.service 内容如下:

[Unit]
Description=infini-gateway
After=network.target

[Service]
Type=forking
WorkingDirectory=/opt/gateway
ExecStart=/opt/gateway/bin/gateway -daemon -pidfile /var/run/gateway.pid  -config /etc/gateway/gateway.yml
ExecStop=/bin/kill `cat /var/run/gateway.pid`
PrivateTmp=true
User=root
Group=root
LimitNOFILE=16384:163840

[Install]
WantedBy=multi-user.target

重新加载服务

systemctl daemon-reload

启动网关服务

systemctl start gateway

查看网关服务

systemctl status gateway

停止网关服务

systemctl stop gateway

查看服务日志

journalctl -fu gateway

设置开机自启

systemctl enable gateway

取消开机自启

systemctl disable gateway

到这里极限网关就已经安装好了,下一步我们来看如何配置极限网关。

下一步