Sunday, October 13, 2019

[Consul] - consul docker installation

[Consul] - consul docker installation

http://coding4ever.net/blog/2019/08/02/menyimpan-konfigurasi-terpusat-menggunakan-consul-key-value-store-bagian-number-1/

https://doc.networknt.com/tutorial/common/discovery/token/


sudo docker run  -p 8500:8500 -p 8600:8600/udp --name=consul consul:latest agent -server -bootstrap -ui -client=0.0.0.0

agent join:
-----------
sudo docker run -d consul agent
sudo docker run -d consul agent --retry-join=172.17.0.2


change mode host
----------------



sudo docker run --net=host -e CONSUL_BIND_INTERFACE=wlp2s0 --name=consul consul:latest agent -server -bootstrap -ui -client=0.0.0.0

sudo docker run --net=host -e CONSUL_BIND_INTERFACE=wlp2s0 -e CONSUL_CLIENT_INTERFACE=wlp2s0 -d consul agent -ui -server -bootstrap-expect=1

ip: 192.168.43.154

docker run -d --name=consulagent1 --net=host consul agent --retry-join=192.168.43.154 -bind=192.168.43.154


//sudah jalan menggunakan network interface
-------------------------------------------
sudo docker run --net=host -e CONSUL_BIND_INTERFACE=wlp2s0 --name=consul consul:latest agent -server -bootstrap -ui -client=0.0.0.0




docker with token - sudah jalan denga acl token
--------------------------------
docker run -d -p 8400:8400 -p 8500:8500/tcp -p 8600:53/udp -e 'CONSUL_LOCAL_CONFIG={"acl_datacenter":"dc1","acl_default_policy":"deny","acl_down_policy":"extend-cache","acl_master_token":"the_one_ring","bootstrap_expect":1,"datacenter":"dc1","data_dir":"/usr/local/bin/consul.d/data","server":true}' consul agent -server -ui -bind=127.0.0.1 -client=0.0.0.0


with volumes:
-------------
docker run -d -p 8400:8400 -p 8500:8500/tcp -p 8600:53/udp -v consul_config:/consul/config -v consul_data:/consul/data -e 'CONSUL_LOCAL_CONFIG={"acl_datacenter":"dc1","acl_default_policy":"deny","acl_down_policy":"extend-cache","acl_master_token":"the_one_ring","bootstrap_expect":1,"datacenter":"dc1","data_dir":"/usr/local/bin/consul.d/data","server":true}' consul agent -server -ui -bind=127.0.0.1 -client=0.0.0.0

with volumes, name
-----------------
docker run -d -p 8400:8400 -p 8500:8500/tcp -p 8600:53/udp --name consul -v consul_config:/consul/config -v consul_data:/consul/data -e 'CONSUL_LOCAL_CONFIG={"acl_datacenter":"dc1","acl_default_policy":"deny","acl_down_policy":"extend-cache","acl_master_token":"the_one_ring","bootstrap_expect":1,"datacenter":"dc1","data_dir":"/usr/local/bin/consul.d/data","server":true}' consul:latest agent -server -ui -bind=127.0.0.1 -client=0.0.0.0


docker run -d \
-p 8400:8400 \
-p 8500:8500/tcp \
-p 8600:53/udp \
--name consul \
--restart always \
-v consul_config:/consul/config \
-v consul_data:/consul/data \
-e 'CONSUL_LOCAL_CONFIG={"acl_datacenter":"dc1","acl_default_policy":"deny","acl_down_policy":"extend-cache","acl_master_token":"the_one_ring","bootstrap_expect":1,"datacenter":"dc1","data_dir":"/usr/local/bin/consul.d/data","server":true}' \
consul:latest agent -server -ui \
-bind=127.0.0.1 \
-client=0.0.0.0



Create agent token
------------------

//read only key/value
---------------------

curl \
    --request PUT \
    --header "X-Consul-Token: the_one_ring" \
    --data \
'{
  "Name": "Agent Token",
  "Type": "client",
  "Rules": "node \"\" { policy = \"write\" } service \"\" { policy = \"write\"}"
}' http://127.0.0.1:8500/v1/acl/create

{"ID":"a4daa51f-9f76-60f5-b7cd-e715a03007f7"}

a9eccfd9-1cd7-25bf-7f93-a649f1feb5ee

//with write key/value
----------------------
curl \
    --request PUT \
    --header "X-Consul-Token: the_one_ring" \
    --data \
'{
  "Name": "Agent Token",
  "Type": "client",
  "Rules": "node \"\" { policy = \"write\" } service \"\" { policy = \"write\" }  key \"\" { policy = \"read\" }"
}' http://127.0.0.1:8500/v1/acl/create

{"ID":"e675ef87-6ab7-9681-941e-9885acbc6361"}


key with filter value:
----------------------
curl \
    --request PUT \
    --header "X-Consul-Token: the_one_ring" \
    --data \
'{
  "Name": "Agent Token",
  "Type": "client",
  "Rules": "node \"\" { policy = \"write\" } service \"\" { policy = \"write\" }  key \"config1\" { policy = \"read\" }"
}' http://127.0.0.1:8500/v1/acl/create
ID":"3d514fa4-ff0b-91a6-e544-d784758b7907


key with filter value database:
----------------------
curl \
    --request PUT \
    --header "X-Consul-Token: the_one_ring" \
    --data \
'{
  "Name": "Agent Token",
  "Type": "client",
  "Rules": "node \"\" { policy = \"write\" } service \"\" { policy = \"write\" }  key \"database\" { policy = \"read\" }"
}' http://127.0.0.1:8500/v1/acl/create

{"ID":"75bde197-45eb-c9d2-d309-11e23bd282b7"}

key with filter value database:
----------------------
curl \
    --request PUT \
    --header "X-Consul-Token: the_one_ring" \
    --data \
'{
  "Name": "Agent Token",
  "Type": "client",
  "Rules": "node \"\" { policy = \"write\" } service \"\" { policy = \"write\" }  key \"database/spdb\" { policy = \"read\" }"
}' http://127.0.0.1:8500/v1/acl/create

{"ID":"1d1cc16a-71ad-4f26-e89c-24f345580c36"}

tes postman:
------------
http://127.0.0.1:8500/v1/kv/config1?raw=true&token=e675ef87-6ab7-9681-941e-9885acbc6361  --> ok



[Apache Pulsar] Docker Installation

Apache Pulsar Docker - ubuntu


Run docker :

docker run -it \
  -p 6650:6650 \
  -p 8080:8080 \
  -v $PWD/data:/pulsar/data \
  apachepulsar/pulsar:2.4.1 \
  bin/pulsar standalone

Download install pulsar-client

$ pip install pulsar-client


producer.py
------------
import pulsar

client = pulsar.Client('pulsar://localhost:6650')
producer = client.create_producer('my-topic')

for i in range(10):
    producer.send(('hello-pulsar-%d' % i).encode('utf-8'))

client.close()


=> menjalankan : python producer.py

consumer.py
-----------
import pulsar

client = pulsar.Client('pulsar://localhost:6650')
consumer = client.subscribe('my-topic',
                            subscription_name='my-sub')

while True:
    msg = consumer.receive()
    print("Received message: '%s'" % msg.data())
    consumer.acknowledge(msg)

client.close()

=> menjalankan : python consumer.py

Pemrograman Running text P10 RGB dengan Arduino Nano

Pemrograman Running text P10 RGB dengan Arduino Nano PIN CONNECTION P10 RGB DENGAN ARDUINO NANO/UNO Source code arduino p10 RGB  #include &q...