3. Adding a new deployment for an existing domain¶
Suppose that you have deployed the domain example-accelerator.shimmercat.com
on an edge server in Stockholm, and that you noticed that the site started to get a lot of traffic from US. You would probably like to deploy a new edge server, let’s say in New York, and load-balance the traffic to the site so that users from US get faster response times. To do so, you will need to create a new deployment site in ShimmerCat Accelerator, and link it to your domain example-accelerator.shimmercat.com
. Below we explain how you can do that.
3.1. Prerequisites¶
We will assume that you have:
followed our Getting Started tutorial.
In any of those cases you should already have created:
an authentication token to use our API,
a Python3 virtual environment and installed the sc_pack
3.2. 1. Create a new deployment site, and assign it to the existing domain¶
Suppose that we already have deployed the domain example-accelerator.shimmercat.com
on an edge server in Stockholm. Let’s now create the deployment site that will represent the deployment in New York. We do this with the command:
$ curl -X POST https://accelerator.shimmercat.com/presentation-api/v1/deployment-site/ -H 'Authorization: Token <your_authentication_token>' -H 'Content-type: application/json' -d '{"description": "New York edge server deployment."}'
You will get a response like this:
{
"id":<deployment_id_new_york>,
"customer": {
"id": <your_customer_id>,
"name":"ShimmerCat Accelerator Test"
},
"description":"New York edge server deployment.",
"name16":"<your_deployment_site_long_name>",
"secret16":"<your_deployment_site_long_secret>"
}
To list the domains you already have created (just in case you need that list):
curl -X GET https://accelerator.shimmercat.com/presentation-api/v1/domain/ -H 'Authorization: Token <your_authentication_token>' -H 'Content-type: application/json'
You will get a response like this:
[
{
"id":<domain_id>,
"name":"example-accelerator.shimmercat.com",
"sub_domains":[],
"deployment_sites": [
{
"id":<deployment_id_stockholm>,
"customer": {
"id": <your_customer_id>,
"name":"ShimmerCat Accelerator Test"
},
"description":"Stockholm edge server deployment.",
"name16":"<your_deployment_site_long_name>",
"secret16":"<your_deployment_site_long_secret>"
}
]
}
]
Let’s assign the created deployment site to the domain:
curl -X PUT https://accelerator.shimmercat.com/presentation-api/v1/domain/example-accelerator.shimmercat.com/ -H 'Authorization: Token <your_authentication_token>' -H 'Content-type: application/json' -d '{"deployment_site_id": <deployment_id_new_york>}'
Notice that you need to use the domain name on the URL above to link the deployment site to that domain.
You will get a response like this:
{
"id":<domain_id>,
"name":"example-accelerator.shimmercat.com",
"sub_domains":[],
"deployment_sites": [
{
"id":<deployment_id_stockholm>,
"customer": {
"id": <your_customer_id>,
"name":"ShimmerCat Accelerator Test"
},
"description":"Stockholm edge server deployment.",
"name16":"<your_deployment_site_long_name>",
"secret16":"<your_deployment_site_long_secret>"
},
{
"id":<deployment_id_new_york>,
"customer": {
"id": <your_customer_id>,
"name":"ShimmerCat Accelerator Test"
},
"description":"New York edge server deployment.",
"name16":"<your_deployment_site_long_name>",
"secret16":"<your_deployment_site_long_secret>"
}
]
}
With the deployment site linked to the domain, you can now configure sc_pack
to use it. See more details in the next section.
3.3. 2. Create/edit sc_pack.conf.yaml
file¶
You could just copy the sc_pack_conf.yaml
from your edge server in Stockholm, paste it on your edge in New York, and update the deployment_site_long_name
and deployment_site_long_secret
according with the deployment site created above. Below is an example of how your sc_pack_conf.yaml
could look like on the New York server:
---
# This is a YAML document with the configuration items
# we need to set up the server with sc_pack.
# For the format, see example below.
#
# All the directories defined are relative to install_dir
shimmercat:
root_dir: www
devlove_file_path: devlove.yaml
scratch_dir_name: shimmercat-scratch-folder
listen_port: "4043"
http2https_port: "8084"
bots_views_dir: views-dir
api_access_token: <your_authentication_token> # Update this value with the value of your authentication token
user: shimmercat
user_group: shimmercat
install_dir: /home/shimmercat/test/shimmercat-accelerator
logs_host_name: localhost
deployment_site_long_name: <your_name16_new_york> # Update this value with the value of your deployment site's `name16` you will create on the next step
deployment_site_long_secret: <your_secret16_new_york> # Update this value with the value of your deployment site's `secret16` you will create on the next step
amqp_server_url: amqp.staging.c.shimmercat.com
amqp_vhost: skyloft
enable_bots_blocking: True
humanity_validator_host: localhost
humanity_validator_port: 8080
google_recaptcha_site_key: 6LfimFIUAAAAAACMycLvA3wetRR9v6ejSbf7uu2v
google_recaptcha_site_secret: 6LfimFIUAAAAAEpCe1QNHwr2p46AMKbUoOBdLWbE
transit_encryption_key: test-accelerator.shimmercat.com.no_enc
deployment_group: test
Note that you should be careful with the ports that you use on the deployments, since you could have some conflicts with services that use the same ports on the same server.
If you don’t want to copy the sc_pack_conf.yaml
from Stockholm, remember that you can use the sc_pack extract
command to get a copy of it:
$ sc_pack extract example.sc_pack.conf.yaml
Once the configuration file is ready, it’s time to setup the directory hierarchy. One way of doing this is:
$ sc_pack create -f /srv/example-accelerator.shimmercat.com/sc_pack.conf.yaml
or, if you are on /srv/example-accelerator.shimmercat.com, you can simply do:
$ sc_pack create
If you would like to serve the same content as on our getting started tutorial, you can download our static website example. You basically need to update your devlove.yaml
if you didn’t copy and paste it from the Stockholm server before executing the sc_pack create
command. Otherwise you will have a copy of the one that the sc_pack
provides by default.
Remember that you need to use the New York edge IP address on your /etc/hosts
:
<new_york_server_ip_address> example-accelerator.shimmercat.com
.
3.4. Cloning the views, and certificates (optional)¶
All the work you already did for the edge in Stockholm, like creating views-dir
, certificates
, and devlove.yaml
, can be cloned to the New York server.
Having the:
devlove.yaml
using the domainexample-accelerator.shimmercat.com
(the devlove file does not have to be the same as the Stockholm server, you just need to be sure this domain is on the domains field of the devlove.yaml),sc_pack.conf.yaml
ready on the New York edge and,services running:
$ sc_pack supervisord
or if you already demonized it.
You can clone the deployment you have in Stockholm to the one in New York with just one command:
$ sc_pack clone example-accelerator.shimmercat.com
With the above command, all the configurations you already did for the Stockholm server will be cloned to the New York server.
When you have more than one deployment, it is ideal to use a Load Balancer. We have used, and helped our customers to use, HAProxy for that. So don’t hesitate to contact us at ops@shimmercat.com or through our ticket system if you need our help with that.
Thanks a lot for your time, and keep reading!