Install two servers with an internal network via RESTful API

Im Durchschnitt wird dieses Tutorial Install two servers with an internal network via RESTful API mit 5 bewertet, wobei 1.0 die schlechteste und 5.0 die beste Bewertung ist. Es haben insgesamt 570 Besucher eine Bewertung abgegeben.
570 0

Install two servers with an internal network via RESTful API

API gridscale
Install two servers with an internal network via RESTful API

Simple setup of two servers via RESTful API

In this guide we will show you how to setup two servers with a shared private network with Debian 8 via the gridscale RESTful API.
This simple example can be easily extended to 4 servers, which can reach each other with a shared private network (for example for a cluster of two web servers and two database servers).

If you don’t want your database servers to be reachable directly over the internet, this guide will help you out: Set up your Debian router/gateway in 10 minutes


Hint: You can log in to your gridscale panel while you enter the API commands to see how your objects appear and get configured!

For this guide the only prerequisite is that an API token has already been generated (https://my.gridscale.io/APIs/Create) and your User-UUID is known (you can find it here: https://my.gridscale.io/APIs)

We will install two servers with Debian 8 with the following adoptions:

  1. Setup of a private network which is connected to both of our servers
  2. “Server 1” with 2 network-interfaces
    • Public-Network(eth0)
    • Private-Network(eth1)
  3. “Server 2” with 2 Network interfaces
    • Public-Netzwerk (eth0)
    • Private-Netzwerk (eth1)

On both servers I will configure one public IPv4 and one public IPv6 Address each.

Ok, let’s get started. 🙂

To make it easier to copy & paste the following examples, we will set some environment variables in our console for the token and for the UUID (Linux-Terminal or Putty):

export X_USERID=your_user_uuid
export X_TOKEN=your_token

At first we search for a location where our servers shall be set up:

# Request
curl -H "Content-Type: application/json" \
     -H "X-Auth-UserId:$X_USERID" \
     -H "X-Auth-Token:$X_TOKEN" \
     -X GET \
     https://api.gridscale.io/objects/locations
# Response
{"locations": {"45ed677b-3702-4b36-be2a-a2eab9827950": {"iata": "fra", "object_uuid": "45ed677b-3702-4b36-be2a-a2eab9827950", "country": "de", "name": "de/fra"}}}

# or a little more beautifully formatted:
{
    "locations": {
        "45ed677b-3702-4b36-be2a-a2eab9827950": {
            "country": "de",
            "iata": "fra",
            "name": "de/fra",
            "object_uuid": "45ed677b-3702-4b36-be2a-a2eab9827950"
        }
    }
}

OK, so let’s take “de/fra” as location parameter:

export X_LOCATION="45ed677b-3702-4b36-be2a-a2eab9827950"

Now the private network:

curl -H "Content-Type: application/json" \
     -H "X-Auth-UserId: $X_USERID" \
     -H "X-Auth-Token: $X_TOKEN" \
     -X POST \
     -d '{"name": "geschütztes Netzwerk", "location_uuid":"'$X_LOCATION'"}' \
     https://api.gridscale.io/objects/networks

# response
{"object_uuid": "6dd023d1-9d71-448a-ac80-d3e2c2aaf954"}

The object_uuid for the private network we received will also get an environment variable:

export X_PRIVATE_NET="6dd023d1-9d71-448a-ac80-d3e2c2aaf954"

The Public Network will not be created, it already exists – but we will need its object_uuid later, so ask for all available networks to get the id:

curl -H "Content-Type: application/json" \
     -H "X-Auth-UserId:$X_USERID" \
     -H "X-Auth-Token:$X_TOKEN" \
     -X GET \
     https://api.gridscale.io/objects/networks

Ok, there is already a huge response – you can “pretty up” the whole thing is somewhat by sending it through a json parser:

curl -H "Content-Type: application/json" \
     -H "X-Auth-UserId:$X_USERID" \
     -H "X-Auth-Token:$X_TOKEN" \
     -X GET \
     https://api.gridscale.io/objects/networks | python -m json.tool

# response
{
    "networks": {
        "6dd023d1-9d71-448a-ac80-d3e2c2aaf954": {
            "change_time": "2016-01-28T15:51:03Z",
            "create_time": "2016-01-28T15:51:03Z",
            "labels": [],
            "location_country": "de",
            "location_iata": "fra",
            "location_name": "de/fra",
            "location_uuid": "45ed677b-3702-4b36-be2a-a2eab9827950",
            "name": "gesch\u00fctztes Netzwerk",
            "object_uuid": "6dd023d1-9d71-448a-ac80-d3e2c2aaf954",
            "public_net": false,
            "relations": {
                "servers": []
            },
            "status": "active"
        },
        "d20386b7-5892-447b-9e40-917d9b7a4c44": {
            "change_time": "2015-10-02T23:29:56Z",
            "create_time": "2015-10-02T23:29:56Z",
            "labels": [],
            "location_country": null,
            "location_iata": null,
            "location_name": null,
            "location_uuid": null,
            "name": "Public Network",
            "object_uuid": "d20386b7-5892-447b-9e40-917d9b7a4c44",
            "public_net": true,
            "relations": {
                "servers": []
            },
            "status": "active"
        }
    }
}

For the public network, we are only interested in the object_uuid which we will again store in an environment variable:

export X_PUBLIC_NET="d20386b7-5892-447b-9e40-917d9b7a4c44"

Now create the two servers:

# Server 1
curl -H "Content-Type: application/json" \
     -H "X-Auth-UserId: $X_USERID" \
     -H "X-Auth-Token: $X_TOKEN" \
     -X POST \
     -d '{"name": "Server 1", "cores":1, "memory":1, "location_uuid":"'$X_LOCATION'"}' \
     https://api.gridscale.io/objects/servers

# response
{"object_uuid": "e25b9248-4efd-4654-97ca-526ebb0626a4"}

The object_uuid we got for the “Server 1” returned to an environment variable:

export X_SERVER1="e25b9248-4efd-4654-97ca-526ebb0626a4"
# Server 2
curl -H "Content-Type: application/json" \
     -H "X-Auth-UserId: $X_USERID" \
     -H "X-Auth-Token: $X_TOKEN" \
     -X POST \
     -d '{"name": "Server 2", "cores":1, "memory":1, "location_uuid":"'$X_LOCATION'"}' \
     https://api.gridscale.io/objects/servers

# response
{"object_uuid": "f11aac20-0a96-4434-b637-204da08fc4ea"}

The server object_uuid which we have received back into an environment variable:

export X_SERVER2="f11aac20-0a96-4434-b637-204da08fc4ea"

And now connect the two servers to the networks – both respond with status code 204 (No Content):

# Server 1 -> Public-Netzwerk
curl -H "Content-Type: application/json" \
     -H "X-Auth-UserId: $X_USERID" \
     -H "X-Auth-Token: $X_TOKEN" \
     -X POST \
     -d '{"object_uuid":"'$X_PUBLIC_NET'"}' \
     https://api.gridscale.io/objects/servers/$X_SERVER1/networks

# Server 1 -> Private-Netzwerk
curl -H "Content-Type: application/json" \
     -H "X-Auth-UserId: $X_USERID" \
     -H "X-Auth-Token: $X_TOKEN" \
     -X POST \
     -d '{"object_uuid":"'$X_PRIVATE_NET'"}' \
     https://api.gridscale.io/objects/servers/$X_SERVER1/networks

# Server 2 -> Public-Netzwerk
curl -H "Content-Type: application/json" \
     -H "X-Auth-UserId: $X_USERID" \
     -H "X-Auth-Token: $X_TOKEN" \
     -X POST \
     -d '{"object_uuid":"'$X_PUBLIC_NET'"}' \
     https://api.gridscale.io/objects/servers/$X_SERVER2/networks

# Server 2 -> Private-Netzwerk
curl -H "Content-Type: application/json" \
     -H "X-Auth-UserId: $X_USERID" \
     -H "X-Auth-Token: $X_TOKEN" \
     -X POST \
     -d '{"object_uuid":"'$X_PRIVATE_NET'"}' \
     https://api.gridscale.io/objects/servers/$X_SERVER2/networks

The servers are now configured and connected to the appropriate networks. Now we install a storage with a Debian 8 template for each of the servers.

First, however, we need the object_uuid of the matching template and to call up a list of all available templates:

curl -H "Content-Type: application/json" \
     -H "X-Auth-UserId:$X_USERID" \
     -H "X-Auth-Token:$X_TOKEN" \
     -X GET \
     https://api.gridscale.io/objects/templates | python -m json.tool

# response (shortended)
[...]
        "a5112c72-c9fa-4a23-8115-5f6303eb047b": {
            "capacity": 1,
            "change_time": "2015-10-03T12:57:21Z",
            "create_time": "2015-10-03T12:57:21Z",
            "current_price": 0.0,
            "description": "no swap",
            "location_country": "de",
            "location_iata": "fra",
            "location_name": "de/fra",
            "location_uuid": "45ed677b-3702-4b36-be2a-a2eab9827950",
            "name": "Debian 8 (64bit)",
            "object_uuid": "a5112c72-c9fa-4a23-8115-5f6303eb047b",
            "ostype": "linux",
            "private": false,
            "status": "active",
            "version": "8.1"
        },
[...]

And again, an environment variable for the template:

export X_TEMPLATE="a5112c72-c9fa-4a23-8115-5f6303eb047b"

You can install templates with either SSH keys or passwords – to keep the example simple, we use a randomly generated password (again set as an environment variable):

export X_ROOTPW="$(pwgen 8 1)"
echo "Root-Passwort: $X_ROOTPW"

Now install the two Storages – each with 10GB capacity – enough for our example:

# Server 1
curl -H "Content-Type: application/json" \
     -H "X-Auth-UserId: $X_USERID" \
     -H "X-Auth-Token: $X_TOKEN" \
     -X POST \
     -d '{"name": "Server 1 Storage", "location_uuid":"'$X_LOCATION'", "capacity": 10, "template": {"hostname": "server1", "template_uuid": "'$X_TEMPLATE'", "password": "'$X_ROOTPW'", "password_type": "plain"}}' \
     https://api.gridscale.io/objects/storages

# response:
{"object_uuid": "3ee3be75-a7c0-4d07-9815-b2345c9f6290"}

# Protected server
curl -H "Content-Type: application/json" \
     -H "X-Auth-UserId: $X_USERID" \
     -H "X-Auth-Token: $X_TOKEN" \
     -X POST \
     -d '{"name": "Server 2 Storage", "location_uuid":"'$X_LOCATION'", "capacity": 10, "template": {"hostname": "server2", "template_uuid": "'$X_TEMPLATE'", "password": "'$X_ROOTPW'", "password_type": "plain"}}' \
     https://api.gridscale.io/objects/storages

# response:
{"object_uuid": "3d152618-7547-4f34-b957-1afac9d29ede"}

And the environment variables for the storage/s:

export X_STORAGE_SERVER1="3ee3be75-a7c0-4d07-9815-b2345c9f6290"
export X_STORAGE_SERVER2="3d152618-7547-4f34-b957-1afac9d29ede"

Almost done – now connect the finished storage/s to the servers:

curl -H "Content-Type: application/json" \
     -H "X-Auth-UserId: $X_USERID" \
     -H "X-Auth-Token: $X_TOKEN" \
     -X POST \
     -d '{"object_uuid":"'$X_STORAGE_SERVER1'"}' \
     https://api.gridscale.io/objects/servers/$X_SERVER1/storages

curl -H "Content-Type: application/json" \
     -H "X-Auth-UserId: $X_USERID" \
     -H "X-Auth-Token: $X_TOKEN" \
     -X POST \
     -d '{"object_uuid":"'$X_STORAGE_SERVER2'"}' \
     https://api.gridscale.io/objects/servers/$X_SERVER2/storages

And so that we can also reach the servers over the Internet still an IPv4 and an IPv6 address request and assign.

# Server 1

curl -H "Content-Type: application/json" \
     -H "X-Auth-UserId: $X_USERID" \
     -H "X-Auth-Token: $X_TOKEN" \
     -X POST \
     -d '{"family": 4, "location_uuid":"'$X_LOCATION'"}' \
     https://api.gridscale.io/objects/ips

# response:
{"object_uuid": "2f811423-371b-4694-aed4-ec57003b9600", "ip": "185.102.95.70"}

curl -H "Content-Type: application/json" \
     -H "X-Auth-UserId: $X_USERID" \
     -H "X-Auth-Token: $X_TOKEN" \
     -X POST \
     -d '{"family": 6, "location_uuid":"'$X_LOCATION'"}' \
     https://api.gridscale.io/objects/ips

# response:
{"object_uuid": "a08bb5a1-3ae4-408a-abe8-f6e241829c68", "ip": "2a06:2380:0:1::26"}

curl -H "Content-Type: application/json" \
     -H "X-Auth-UserId: $X_USERID" \
     -H "X-Auth-Token: $X_TOKEN" \
     -X POST \
     -d '{"object_uuid":"2f811423-371b-4694-aed4-ec57003b9600"}' \
     https://api.gridscale.io/objects/servers/$X_SERVER1/ips

curl -H "Content-Type: application/json" \
     -H "X-Auth-UserId: $X_USERID" \
     -H "X-Auth-Token: $X_TOKEN" \
     -X POST \
     -d '{"object_uuid":"a08bb5a1-3ae4-408a-abe8-f6e241829c68"}' \
     https://api.gridscale.io/objects/servers/$X_SERVER1/ips
# Server 2

curl -H "Content-Type: application/json" \
     -H "X-Auth-UserId: $X_USERID" \
     -H "X-Auth-Token: $X_TOKEN" \
     -X POST \
     -d '{"family": 4, "location_uuid":"'$X_LOCATION'"}' \
     https://api.gridscale.io/objects/ips

# response:
{"object_uuid": "364b4769-28e7-4e15-9d17-62d2f131b776", "ip": "185.102.95.71"}

curl -H "Content-Type: application/json" \
     -H "X-Auth-UserId: $X_USERID" \
     -H "X-Auth-Token: $X_TOKEN" \
     -X POST \
     -d '{"family": 6, "location_uuid":"'$X_LOCATION'"}' \
     https://api.gridscale.io/objects/ips

# response:
{"object_uuid": "ced650c5-2007-48a1-839b-5f7a383bb66a", "ip": "2a06:2380:0:1::27"}

curl -H "Content-Type: application/json" \
     -H "X-Auth-UserId: $X_USERID" \
     -H "X-Auth-Token: $X_TOKEN" \
     -X POST \
     -d '{"object_uuid":"364b4769-28e7-4e15-9d17-62d2f131b776"}' \
     https://api.gridscale.io/objects/servers/$X_SERVER2/ips

curl -H "Content-Type: application/json" \
     -H "X-Auth-UserId: $X_USERID" \
     -H "X-Auth-Token: $X_TOKEN" \
     -X POST \
     -d '{"object_uuid":"ced650c5-2007-48a1-839b-5f7a383bb66a"}' \
     https://api.gridscale.io/objects/servers/$X_SERVER2/ips

For the final step; start both servers. You can see the servers on the system console in the panel at boot time:

curl -H "Content-Type: application/json" \
     -H "X-Auth-UserId: $X_USERID" \
     -H "X-Auth-Token: $X_TOKEN" \
     -X PATCH \
     -d '{"power":true}' \
     https://api.gridscale.io/objects/servers/$X_SERVER1/power

curl -H "Content-Type: application/json" \
     -H "X-Auth-UserId: $X_USERID" \
     -H "X-Auth-Token: $X_TOKEN" \
     -X PATCH \
     -d '{"power":true}' \
     https://api.gridscale.io/objects/servers/$X_SERVER2/power

Wait a few seconds and you can connect to both servers with the established IPs via SSH.
Both servers are now ready and we can set up the internal network.

Change the values for “address”, “netmask” and “broadcast” for your internal network. In the internal network, it makes sense to have an MTU of 9000 to achieve a higher data throughput between your servers.

Server 1

# nano -w /etc/network/interfaces

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
allow-hotplug eth0
iface eth0 inet dhcp
iface eth0 inet6 dhcp

# The internal LAN interface (eth1)
allow-hotplug eth1
iface eth1 inet static
   address 10.0.0.1
   netmask 255.255.255.0
   network 10.0.0.0
   broadcast 10.0.0.255
   mtu 9000

Server 2

# nano -w /etc/network/interfaces

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
allow-hotplug eth0
iface eth0 inet dhcp
iface eth0 inet6 dhcp

# The internal LAN interface (eth1)
allow-hotplug eth1
iface eth1 inet static
   address 10.0.0.2
   netmask 255.255.255.0
   network 10.0.0.0
   broadcast 10.0.0.255
   mtu 9000

Simple setup of two servers via RESTful API In this guide we will show you how to setup two servers with a shared private network with Debian 8 via the gridscale RESTful API. This simple example can be easily extended to 4 servers, which can reach each other with a shared private network (for example […]

Schade, dass dir der Artikel nicht gefallen hat.
Was sollten wir deiner Meinung nach besser machen?

Thank you for your feedback!
We will get back to you as soon as the article is finished.

Übrigens: kennst du schon unser Tutorial zum Thema Resize Storage on the fly – without rebooting your server?

×

Developer?

Get the latest gridscale developer tutorials here.
And don’t worry - we won’t spam you