Proxy Transport Layer (L4) Traffic
API7 Enterprise can handle transport layer (L4) TCP and UDP traffic dedicated or in addition to handling application layer (L7) traffic.
This tutorial walks through configuring a stream route to proxy L4 traffic between clients and a MySQL server.
Prerequisites
- Install API7 Enterprise.
- Obtain a user account with Super Admin or API Provider role.
- Rename the
default
gateway group toTest Group
and configure the network.Test Group
will be the API gateway for your test environment. - Have at least one gateway instance in the
Test Group
. - Install a MySQL client to validate the stream route.
Start a MySQL Server
Start a MySQL server inside Docker and use the default API7 Enterprise network as shown below:
docker run -d \
--name mysql \
--network=api7-ee_api7 \
-p 3306:3306 \
-e MYSQL_ROOT_PASSWORD=password \
mysql:8.4 \
mysqld --mysql-native-password=ON
Add a Service with Stream Routes
- Select Service Hub from the side navigation bar, then click Add Service.
- Select Add Manually.
- From the Add Service dialog box, do the following:
- In the Name field, enter
MySQL
. - In the Service Type field, choose
Stream(Layer 4 Proxy)
. - By default, the Upstream Scheme is
TCP
.
- In the Name field, enter
- Click Add.
- Inside the service, click Add Stream Route.
- From the Add Stream Route dialog box, do the following:
- In the Name field, enter
stream-route-mysql
. - In the Server Address field, enter
127.0.0.1
. - In the Server Port filed, enter
2000
.
- In the Name field, enter
- Click Add.
info
Make sure to expose the server port, 2000
, to the host machine.
Publish the Service Using Upstream Nodes
- Select Service Hub from the side navigation bar and then select
MySQL
service. - Click Publish Now.
- Select
Test Group
and then click Next. - From the dialog box, do the following:
- In the New Version field, enter
1.0.0
. - By default, the How to find the upstream field is
Use Nodes
. - Click Add Node. From the dialog box, do the following:
- In the Host and Port fields, enter your MySQL IP address and
3306
respectively. - In the Weight field, use the default value
100
.
- In the Host and Port fields, enter your MySQL IP address and
- Click Add.
- In the New Version field, enter
- Confirm the service information and then click Publish.
Validate the Stream Route
Establish a connection with the MySQL server through API7 Enterprise using the MySQL client. Connect as root using the password configured before:
mysql --host=127.0.0.1 --port=2000 -u root -p
You should see the MySQL prompt as shown below:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.4.0 MySQL Community Server - GPL
Copyright (c) 2000, 2024, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>