- Developed the concept of Service Directory Cache which Caches all services' information locally on the service consumer machine
- No need for dig and curl commands to discover service information Language optimized cache configs.
-
Download consul binary from https://consul.io/downloads.html
-
Download Consul-template binary from https://github.com/hashicorp/consul-template/releases
-
Copy those binaries in /usr/local/bin with executable permission.
-
Check Consul and Consul Template is installed correctly by typing following in the terminal.
consul --version
consul-template --version- Enter the following commands in terminal.
sudo git clone http://gitlab.infoedge.com/s.kushwaha/SDCache.git /apps
cd /apps/SDCachelibrary
./reset.shChange the node name of consul client in client configuration, according to host machine.
vi /apps/SDCachelibrary/consulClientMode/config.jsonType the following in terminal to start consul client agent :
cd /apps/SDCachelibrary/
./reset.sh
consul agent -config-dir /apps/SDCachelibrary/consulClientModeTo change consul client configuration , simply edit /apps/SDCachelibrary/consulClientMode/config.json
Change the node name of consul server in server configuration, according to host machine.
vi /apps/SDCachelibrary/consulServerMode/config.jsonType the following in terminal to start consul server agent :
cd /apps/SDCachelibrary/
./reset.sh
consul agent -config-dir /apps/SDCachelibrary/consulServerModeTo change consul server configuration , simply edit /apps/SDCachelibrary/consulServerMode/config.json
- Start consul agent { refer (3) point }
- Then enter following commands in terminal :
cd /apps/SDCachelibrary/Either enter the consul watch configuration in consul agent's configuration or type the following in terminal to start consul watch:
consul watch -type=event -name=service ./eventHandling/handler.shconsul-template -config consul-template/config/consul-template.cfg cd /apps/SDCachelibrary/registerLibraryEdit the serviceConfig.json and enter the configuration of service correctly in the specified manner and run
php register.phpService registeration shoud be done from that consul agent where service is running.
cd /apps/SDCachelibrary/registerLibraryOpen deregister.php . Change the object creation line in end of deregister.php like as follows
$obj = new deregisterService($id , $name ,$tag , $node) ;id = unique id of service given at the time of registeration of service.
name = Name of service.
tag = Tag of service which can be version number.
node = Host machine name or name of consul agent from which service was registered.
like as follows :
$obj = new deregisterService("1","Filestorageservice","2.3","Rishu") ;
Start consul agent.
Setup SDCache.
Join the existing cluster by following command .
- ip = IP of any cluster member .
- port = PORT for serf-lan for an agent
consul join ip:portlike
consul join 192.168.2.116:8301Run following commands in terminal to setup sync with SDCache of others.
cd /apps/SDCachelibrary/InitializeCache
php InitializeCache.php
Remember to deregister all services running on that node so that services entries is removed properly from consul. Then in terminal type
consul leave
cd /apps/SDCachelibrary/
./reset.sh