HashiCorp's consul is the good pick for service mesh and service discovery. While developing microservices, we need some service discoveries mechanism so that our services/Web-APIs get registered themselves with a centralized service-repository. A Web API gateway (like ocelot etc.) then can use the consul to serve the request.
Using Consul in Production Deployment
In a production deployment, we need to install consul on each node(host/machine/container) where our services are and we want them to register with consul. The Consul can run in two modes i.e.
- server-agent (maintains the state) and
- client-agent (light-weight process, must be installed on each & every node where our microservices are running).
The Consul, needs to be running up constantly for the Production servers and for that have two ways-
- let the consul up and running from a command prompt window
- install consul as a windows service
The first solution looks very awkward. If by accidently someone closes that command prompt window, consul will stop working. So, we can think for the second approach that is installing consul as a windows service.
How to install consul as a Windows Service?
- Download the consul from here- https://www.consul.io/downloads
- Unzip the consul in a folder where you want to keep the consul and its config
- Go to that folder and create a folder lets name it "config"
- Inside the "config" folder, create a "config.json" file and put below content-
{
"datacenter": "east-aws",
"data_dir": "c:\\consul\\config",
"log_level": "INFO",
"node_name": "WebServer",
"server": true,
"bind_addr": "10.0.0.217",
"bootstrap": true,
"ui_config": {"enabled": true},
"log_file": "c:\\consul\\log\\consul.log"
}
- Run the below command from the command prompt to install the consul as a windows service-
sc.exe create "Consul" binPath= "c:\\consul\\Consul.exe agent -config-dir=c:\\consul\\config" start= auto
- Then to start consul service, type below command-
sc.exe start Consul
- Go the services and check if your consul is up and running
That's it!
@AnilAwadh