{"id":2881,"date":"2021-08-16T10:28:32","date_gmt":"2021-08-16T01:28:32","guid":{"rendered":"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=2881"},"modified":"2021-09-18T20:04:52","modified_gmt":"2021-09-18T11:04:52","slug":"nomad-autoscaler-%ea%b0%80%ec%a7%80%ea%b3%a0-%eb%86%80%ea%b8%b0","status":"publish","type":"post","link":"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=2881","title":{"rendered":"nomad autoscaler \uac00\uc9c0\uace0 \ub180\uae30"},"content":{"rendered":"<h1>nomad autoscaler \uac00\uc9c0\uace0 \ub180\uae30<\/h1>\n<p><a href=\"https:\/\/github.com\/hashicorp\/nomad-autoscaler-demos\/tree\/main\/vagrant\/horizontal-app-scaling\">\ucc38\uc870<\/a><\/p>\n<p><a href=\"https:\/\/learn.hashicorp.com\/tutorials\/nomad\/autoscaler-vagrant-demo\">\ucc38\uc870<\/a><\/p>\n<h2>\ubaa9\ud45c<\/h2>\n<p><code>nomad autoscaler<\/code> \ub97c \uc774\uc6a9\ud574 Auto Scaling \uc744 \uc791\ub3d9\uc2dc\ud0b5\ub2c8\ub2e4.<\/p>\n<h2>\uc900\ube44\ubb3c \uc124\uce58<\/h2>\n<p>AWS AMI \uc778\uc2a4\ud134\uc2a4\ub97c \uc0dd\uc131\ud569\ub2c8\ub2e4.<br \/>\n\uba54\ubaa8\ub9ac\ub294 2G \ub85c \ud569\ub2c8\ub2e4.<\/p>\n<p>JDK, Docker \ub97c \uc124\uce58\ud569\ub2c8\ub2e4.<\/p>\n<pre><code class=\"language-bash\">sudo yum install java-11-amazon-corretto-headless -y\njava -version<\/code><\/pre>\n<pre><code class=\"language-bash\">sudo yum install docker -y\ndocker -v\nsudo service docker start\nsudo systemctl enable docker.service<\/code><\/pre>\n<h2>Consul \uc124\uce58<\/h2>\n<pre><code class=\"language-bash\">sudo mkdir -p \/etc\/consul.d\nsudo mkdir -p \/opt\/consul\n\nsudo vi \/etc\/consul.d\/consul.hcl\n-----------------------------------------\ndatacenter       = &quot;dc1&quot;\nadvertise_addr   = &quot;127.0.0.1&quot;\nclient_addr      = &quot;0.0.0.0&quot;\ndata_dir         = &quot;\/opt\/consul&quot;\nserver           = true\nbootstrap_expect = 1\nui               = true\n\ntelemetry {\n  prometheus_retention_time = &quot;30s&quot;\n}\n-----------------------------------------<\/code><\/pre>\n<pre><code class=\"language-bash\">sudo docker run -d --name consul \\\n    -p 8500:8500 -p 8600:8600 -p 8600:8600\/udp \\\n    -v \/opt\/consul:\/opt\/consul \\\n    -v \/etc\/consul.d:\/etc\/consul.d \\\n    --net host \\\n    --restart=always \\\n    consul:1.4.2<\/code><\/pre>\n<h2>Nomad \uc124\uce58<\/h2>\n<p>\uc544\ub798 \uba85\ub839\uc73c\ub85c nomad \ub97c \uc124\uce58\ud574 \uc90d\ub2c8\ub2e4.<\/p>\n<pre><code class=\"language-bash\">wget https:\/\/releases.hashicorp.com\/nomad\/1.1.3\/nomad_1.1.3_linux_amd64.zip\nunzip nomad_1.1.3_linux_amd64.zip\nsudo mv nomad \/usr\/bin\/\n\nnomad version<\/code><\/pre>\n<p>\ud14c\uc2a4\ud2b8\uc6a9\uc774\ubbc0\ub85c, \ud55c \uc11c\ubc84\uc5d0 Server\/Client \ub97c \ud55c\ubc88\uc5d0 \ud65c\uc131\ud654 \ud569\ub2c8\ub2e4.<\/p>\n<pre><code class=\"language-bash\">sudo mkdir -p \/etc\/nomad.d\nsudo mkdir -p \/opt\/nomad\n\nsudo vi \/etc\/nomad.d\/nomad.hcl\n-----------------------------------------\ndatacenter = &quot;dc1&quot;\ndata_dir   = &quot;\/opt\/nomad\/data&quot;\nbind_addr  = &quot;0.0.0.0&quot;\n\nadvertise {\n  http = &quot;{{ GetPrivateIP }}&quot;\n  rpc  = &quot;{{ GetPrivateIP }}&quot;\n  serf = &quot;{{ GetPrivateIP }}&quot;\n}\n\nserver {\n  enabled          = true\n  bootstrap_expect = 1\n}\n\nclient {\n  enabled = true\n\n  host_volume &quot;grafana&quot; {\n    # add directory manually\n    # sudo mkdir -p \/opt\/nomad-volumes\/grafana\n    # sudo chown 472:472 \/opt\/nomad-volumes\/grafana\n    path = &quot;\/opt\/nomad-volumes\/grafana&quot;\n  }\n}\n\n# plugin &quot;nvidia-gpu&quot; {\n#   config {\n#     enabled            = true\n#     ignored_gpu_ids    = [&quot;GPU-fef8089b&quot;, &quot;GPU-ac81e44d&quot;]\n#     fingerprint_period = &quot;1m&quot;\n#   }\n# }\n\nplugin &quot;docker&quot; {\n  config {\n    volumes {\n      enabled = true\n    }\n  }\n}\n\ntelemetry {\n  publish_allocation_metrics = true\n  publish_node_metrics       = true\n  prometheus_metrics         = true\n}\n-----------------------------------------<\/code><\/pre>\n<p>grafana \uc6a9 \ubcfc\ub968 \uc0dd\uc131<\/p>\n<pre><code class=\"language-bash\">sudo mkdir -p \/opt\/nomad-volumes\/grafana\nsudo chown 472:472 \/opt\/nomad-volumes\/grafana<\/code><\/pre>\n<p>nomad client \ub294 root \uad8c\ud55c\uc774 \ud544\uc694\ud569\ub2c8\ub2e4.<\/p>\n<pre><code class=\"language-bash\">sudo nomad agent -config=\/etc\/nomad.d\/nomad.hcl<\/code><\/pre>\n<h2>nomad \uc11c\ube44\uc2a4\ub85c \uc2e4\ud589\ud558\uae30<\/h2>\n<pre><code class=\"language-bash\">sudo vi \/lib\/systemd\/system\/nomad.service\n---------------------------\n[Unit]\nDescription=Nomad\nDocumentation=https:\/\/nomadproject.io\/docs\/\nWants=network-online.target\nAfter=network-online.target\n\n# When using Nomad with Consul it is not necessary to start Consul first. These\n# lines start Consul before Nomad as an optimization to avoid Nomad logging\n# that Consul is unavailable at startup.\n#Wants=consul.service\n#After=consul.service\n\n[Service]\nExecReload=\/bin\/kill -HUP $MAINPID\nExecStart=\/usr\/bin\/nomad agent -config \/etc\/nomad.d\nKillMode=process\nKillSignal=SIGINT\nLimitNOFILE=65536\nLimitNPROC=infinity\nRestart=on-failure\nRestartSec=2\nStartLimitBurst=3\nStartLimitIntervalSec=10\nTasksMax=infinity\nOOMScoreAdjust=-1000\n\n[Install]\nWantedBy=multi-user.target\n---------------------------<\/code><\/pre>\n<pre><code class=\"language-bash\">sudo systemctl daemon-reload\nsudo systemctl enable nomad\nsudo systemctl start nomad\nsudo systemctl status nomad<\/code><\/pre>\n<h2><del>Traefik \uc124\uce58<\/del><\/h2>\n<p>Traefik \uc774 CPU \uacfc\ub2e4 \uc0ac\uc6a9 \uc774\uc288\uac00 \uc788\uc5b4 HAproxy \ub85c \ubcc0\uacbd\ud569\ub2c8\ub2e4.<\/p>\n<p>Reverse Proxy \ub97c \uc704\ud574 traefik \uc744 \uc124\uce58\ud569\ub2c8\ub2e4.<\/p>\n<pre><code class=\"language-bash\">vi traefik.nomad\n------------------------------\njob &quot;traefik&quot; {\n  region      = &quot;global&quot;\n  datacenters = [&quot;dc1&quot;]\n  type        = &quot;system&quot;\n\n  group &quot;traefik&quot; {\n    count = 1\n\n    network {\n      # traefik web ui\n      port &quot;api&quot; {\n        static = 8081\n      }\n\n      port &quot;grafana&quot; {\n        static = 3000\n      }\n\n      port &quot;prometheus&quot; {\n        static = 9090\n      }\n\n      port &quot;http&quot; {\n        static = 8080\n      }\n    }\n\n    task &quot;traefik&quot; {\n      driver = &quot;docker&quot;\n\n      config {\n        image = &quot;traefik:v2.4&quot;\n        ports = [&quot;api&quot;, &quot;grafana&quot;, &quot;prometheus&quot;, &quot;http&quot;]\n\n        # Use `host` network so we can communicate with the Consul agent\n        # running in the host to access the service catalog.\n        network_mode = &quot;host&quot;\n\n        volumes = [\n          &quot;local\/traefik.toml:\/etc\/traefik\/traefik.toml&quot;,\n        ]\n      }\n\n      template {\n        data = &lt;&lt;EOF\n[entryPoints]\n  [entryPoints.traefik]\n    address = &quot;:{{ env &quot;NOMAD_PORT_api&quot; }}&quot;\n  [entryPoints.grafana]\n    address = &quot;:{{ env &quot;NOMAD_PORT_grafana&quot; }}&quot;\n  [entryPoints.prometheus]\n    address = &quot;:{{ env &quot;NOMAD_PORT_prometheus&quot; }}&quot;\n  [entryPoints.http]\n    address = &quot;:{{ env &quot;NOMAD_PORT_http&quot; }}&quot;\n[api]\n  dashboard = true\n  insecure  = true\n[metrics]\n  [metrics.prometheus]\n    addServicesLabels = true\n# Enable Consul Catalog configuration backend.\n[providers.consulCatalog]\n  prefix           = &quot;traefik&quot;\n  exposedByDefault = false\n  [providers.consulCatalog.endpoint]\n    address = &quot;127.0.0.1:8500&quot;\n    scheme  = &quot;http&quot;\nEOF\n\n        destination = &quot;local\/traefik.toml&quot;\n      }\n\n      resources {\n        cpu    = 200\n        memory = 256\n      }\n\n      service {\n        name         = &quot;traefik-api&quot;\n        port         = &quot;api&quot;\n        address_mode = &quot;host&quot;\n\n        check {\n          name     = &quot;alive&quot;\n          type     = &quot;tcp&quot;\n          port     = &quot;api&quot;\n          interval = &quot;10s&quot;\n          timeout  = &quot;2s&quot;\n        }\n      }\n\n      service {\n        name         = &quot;traefik-http&quot;\n        port         = &quot;http&quot;\n        address_mode = &quot;host&quot;\n\n        check {\n          name     = &quot;alive&quot;\n          type     = &quot;tcp&quot;\n          port     = &quot;http&quot;\n          interval = &quot;10s&quot;\n          timeout  = &quot;2s&quot;\n        }\n      }\n\n      service {\n        name         = &quot;traefik-grafana&quot;\n        port         = &quot;grafana&quot;\n        address_mode = &quot;host&quot;\n\n        check {\n          name     = &quot;alive&quot;\n          type     = &quot;tcp&quot;\n          port     = &quot;grafana&quot;\n          interval = &quot;10s&quot;\n          timeout  = &quot;2s&quot;\n        }\n      }\n\n      service {\n        name         = &quot;traefik-prometheus&quot;\n        port         = &quot;prometheus&quot;\n        address_mode = &quot;host&quot;\n\n        check {\n          name     = &quot;alive&quot;\n          type     = &quot;tcp&quot;\n          port     = &quot;prometheus&quot;\n          interval = &quot;10s&quot;\n          timeout  = &quot;2s&quot;\n        }\n      }\n    }\n  }\n}\n------------------------------<\/code><\/pre>\n<pre><code class=\"language-bash\">nomad run traefik.nomad<\/code><\/pre>\n<h2>HAproxy \uc124\uc815<\/h2>\n<p>\uc571\uc758 DNS \ub9cc \ub9e4\uce6d\ud574 \uc8fc\uba74 \ub429\ub2c8\ub2e4.<br \/>\n\ub300\uc18c\ubb38\uc790\ub294 \uad6c\ubd84\ud558\uc9c0 \uc54a\uc2b5\ub2c8\ub2e4.<\/p>\n<p><code>_&lt;\uc571\uc758 \uc11c\ube44\uc2a4\uba85&gt;._tcp.service.consul<\/code><\/p>\n<pre><code class=\"language-bash\">vi haproxy.nomad\n------------------------------\njob &quot;haproxy&quot; {\n  datacenters = [&quot;dc1&quot;]\n\n  group &quot;haproxy&quot; {\n    count = 1\n\n    network {\n      port &quot;webapp&quot; {\n        static = 8080\n      }\n\n      port &quot;prometheus_ui&quot; {\n        static = 9090\n      }\n\n      port &quot;grafana_ui&quot; {\n        static = 3000\n      }\n\n      port &quot;haproxy_ui&quot; {\n        static = 4936\n      }\n\n      port &quot;haproxy_exporter&quot; {}\n    }\n\n    task &quot;haproxy&quot; {\n      driver = &quot;docker&quot;\n\n      config {\n        image = &quot;haproxy:2.3.5&quot;\n        ports = [&quot;webapp&quot;, &quot;haproxy_ui&quot;]\n\n        # Use `host` network so we can communicate with the Consul agent\n        # running in the host to access the service catalog.\n        network_mode = &quot;host&quot;\n\n        volumes = [\n          &quot;local\/haproxy.cfg:\/usr\/local\/etc\/haproxy\/haproxy.cfg&quot;,\n        ]\n      }\n\n      template {\n        data = &lt;&lt;EOF\nglobal\n   maxconn 8192\n\ndefaults\n   mode http\n   timeout client 10s\n   timeout connect 5s\n   timeout server 10s\n   timeout http-request 10s\n\nfrontend stats\n   bind *:{{ env &quot;NOMAD_PORT_haproxy_ui&quot; }}\n   stats uri \/\n   stats show-legends\n   no log\n\nfrontend http_front\n   bind *:{{ env &quot;NOMAD_PORT_webapp&quot; }}\n   default_backend http_back\n\nfrontend prometheus_ui_front\n   bind *:{{ env &quot;NOMAD_PORT_prometheus_ui&quot; }}\n   default_backend prometheus_ui_back\n\nfrontend grafana_ui_front\n   bind *:{{ env &quot;NOMAD_PORT_grafana_ui&quot; }}\n   default_backend grafana_ui_back\n\nbackend http_back\n   balance roundrobin\n   server-template webapp 20 _helloservice._tcp.service.consul resolvers consul resolve-opts allow-dup-ip resolve-prefer ipv4 check\n\nbackend prometheus_ui_back\n   balance roundrobin\n   server-template prometheus_ui 5 _prometheus._tcp.service.consul resolvers consul resolve-opts allow-dup-ip resolve-prefer ipv4 check\n\nbackend grafana_ui_back\n   balance roundrobin\n   server-template grafana 5 _grafana._tcp.service.consul resolvers consul resolve-opts allow-dup-ip resolve-prefer ipv4 check\n\nresolvers consul\n   nameserver consul {{ env &quot;attr.unique.network.ip-address&quot; }}:8600\n   accepted_payload_size 8192\n   hold valid 5s\nEOF\n\n        destination   = &quot;local\/haproxy.cfg&quot;\n        change_mode   = &quot;signal&quot;\n        change_signal = &quot;SIGUSR1&quot;\n      }\n\n      resources {\n        cpu    = 500\n        memory = 128\n      }\n\n      service {\n        name = &quot;haproxy-ui&quot;\n        port = &quot;haproxy_ui&quot;\n\n        check {\n          type     = &quot;http&quot;\n          path     = &quot;\/&quot;\n          interval = &quot;10s&quot;\n          timeout  = &quot;2s&quot;\n        }\n      }\n\n      service {\n        name = &quot;haproxy-webapp&quot;\n        port = &quot;webapp&quot;\n      }\n    }\n\n    task &quot;haproxy-exporter&quot; {\n      driver = &quot;docker&quot;\n\n      lifecycle {\n        hook    = &quot;prestart&quot;\n        sidecar = true\n      }\n\n      config {\n        image = &quot;prom\/haproxy-exporter:v0.10.0&quot;\n        ports = [&quot;haproxy_exporter&quot;]\n\n        network_mode = &quot;host&quot;\n\n        args = [\n          &quot;--web.listen-address&quot;,\n          &quot;:${NOMAD_PORT_haproxy_exporter}&quot;,\n          &quot;--haproxy.scrape-uri&quot;,\n          &quot;http:\/\/${NOMAD_ADDR_haproxy_ui}\/?stats;csv&quot;,\n        ]\n      }\n\n      resources {\n        cpu    = 100\n        memory = 32\n      }\n\n      service {\n        name = &quot;haproxy-exporter&quot;\n        port = &quot;haproxy_exporter&quot;\n\n        check {\n          type     = &quot;http&quot;\n          path     = &quot;\/metrics&quot;\n          interval = &quot;10s&quot;\n          timeout  = &quot;2s&quot;\n        }\n      }\n    }\n  }\n}\n------------------------------<\/code><\/pre>\n<pre><code class=\"language-bash\">nomad run haproxy.nomad<\/code><\/pre>\n<h2>Prometheus \uc124\uc815<\/h2>\n<p><a href=\"https:\/\/prometheus.io\/docs\/prometheus\/latest\/configuration\/configuration\/#consul_sd_config\">\ucc38\uc870<\/a><\/p>\n<pre><code class=\"language-bash\">vi prometheus.nomad\n------------------------------\njob &quot;prometheus&quot; {\n  datacenters = [&quot;dc1&quot;]\n\n  group &quot;prometheus&quot; {\n    count = 1\n\n    network {\n      port &quot;prometheus_ui&quot; {}\n    }\n\n    task &quot;prometheus&quot; {\n      driver = &quot;docker&quot;\n\n      config {\n        image = &quot;prom\/prometheus:v2.25.0&quot;\n        ports = [&quot;prometheus_ui&quot;]\n\n        network_mode = &quot;host&quot;\n\n        args = [\n          &quot;--config.file=\/etc\/prometheus\/config\/prometheus.yml&quot;,\n          &quot;--storage.tsdb.path=\/prometheus&quot;,\n          &quot;--web.listen-address=0.0.0.0:${NOMAD_PORT_prometheus_ui}&quot;,\n          &quot;--web.console.libraries=\/usr\/share\/prometheus\/console_libraries&quot;,\n          &quot;--web.console.templates=\/usr\/share\/prometheus\/consoles&quot;,\n        ]\n\n        volumes = [\n          &quot;local\/config:\/etc\/prometheus\/config&quot;,\n        ]\n      }\n\n      template {\n        data = &lt;&lt;EOH\n---\nglobal:\n  scrape_interval:     1s\n  evaluation_interval: 1s\n\nscrape_configs:\n\n  - job_name: haproxy_exporter\n    static_configs:\n      - targets: [{{ range service &quot;haproxy-exporter&quot; }}&#039;{{ .Address }}:{{ .Port }}&#039;,{{ end }}]\n\n  - job_name: nomad_autoscaler\n    metrics_path: \/v1\/metrics\n    params:\n      format: [&#039;prometheus&#039;]\n    static_configs:\n      - targets: [{{ range service &quot;autoscaler&quot; }}&#039;{{ .Address }}:{{ .Port }}&#039;,{{ end }}]\n\n  - job_name: nomad\n    metrics_path: \/v1\/metrics\n    params:\n      format: [&#039;prometheus&#039;]\n    static_configs:\n    - targets: [&#039;{{ env &quot;attr.unique.network.ip-address&quot; }}:4646&#039;]\nEOH\n\n        change_mode   = &quot;signal&quot;\n        change_signal = &quot;SIGHUP&quot;\n        destination   = &quot;local\/config\/prometheus.yml&quot;\n      }\n\n      resources {\n        cpu    = 100\n        memory = 256\n      }\n\n      service {\n        name = &quot;prometheus&quot;\n        port = &quot;prometheus_ui&quot;\n\n        check {\n          type     = &quot;http&quot;\n          path     = &quot;\/-\/healthy&quot;\n          interval = &quot;10s&quot;\n          timeout  = &quot;2s&quot;\n        }\n      }\n    }\n  }\n}\n------------------------------<\/code><\/pre>\n<pre><code class=\"language-bash\">nomad run prometheus.nomad<\/code><\/pre>\n<p>http:\/\/&lt;\uc778\uc2a4\ud134\uc2a4 \ud37c\ube14\ub9ad \uc544\uc774\ud53c&gt;:9090\/targets \ub97c \uc774\uc6a9\ud574 \uc811\uc18d \uc0c1\ud0dc\ub97c \ud655\uc778\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n<p><a href=\"https:\/\/www.skyer9.pe.kr\/wordpress\/wp-content\/uploads\/2021\/08\/2021-08-18-02.png\"><img decoding=\"async\" src=\"https:\/\/www.skyer9.pe.kr\/wordpress\/wp-content\/uploads\/2021\/08\/2021-08-18-02.png\" alt=\"\" \/><\/a><\/p>\n<h2>Grafana \uc124\uc815<\/h2>\n<pre><code class=\"language-bash\">vi grafana.nomad\n-----------------------------------------\njob &quot;grafana&quot; {\n  datacenters = [&quot;dc1&quot;]\n\n  group &quot;grafana&quot; {\n    count = 1\n\n    network {\n      port &quot;grafana_ui&quot; {}\n    }\n\n    volume &quot;grafana&quot; {\n      type   = &quot;host&quot;\n      source = &quot;grafana&quot;\n    }\n\n    task &quot;grafana&quot; {\n      driver = &quot;docker&quot;\n\n      config {\n        image = &quot;grafana\/grafana:7.4.2&quot;\n        ports = [&quot;grafana_ui&quot;]\n\n        network_mode = &quot;host&quot;\n\n        volumes = [\n          &quot;local\/datasources:\/etc\/grafana\/provisioning\/datasources&quot;,\n          &quot;local\/dashboards:\/etc\/grafana\/provisioning\/dashboards&quot;,\n          &quot;\/home\/vagrant\/nomad-autoscaler\/files:\/var\/lib\/grafana\/dashboards&quot;,\n        ]\n      }\n\n      env {\n        GF_INSTALL_PLUGINS         = &quot;grafana-clock-panel,grafana-piechart-panel,natel-discrete-panel&quot;\n        GF_AUTH_ANONYMOUS_ENABLED  = &quot;true&quot;\n        GF_AUTH_ANONYMOUS_ORG_ROLE = &quot;Editor&quot;\n        GF_SERVER_HTTP_PORT        = &quot;${NOMAD_PORT_grafana_ui}&quot;\n      }\n\n      template {\n        data = &lt;&lt;EOH\napiVersion: 1\ndatasources:\n- name: Prometheus\n  type: prometheus\n  access: proxy\n  url: http:\/\/{{ range $i, $s := service &quot;prometheus&quot; }}{{ if eq $i 0 }}{{.Address}}:{{.Port}}{{end}}{{end}}\n  isDefault: true\n  version: 1\n  editable: false\nEOH\n\n        destination = &quot;local\/datasources\/prometheus.yaml&quot;\n      }\n\n      template {\n        data = &lt;&lt;EOH\napiVersion: 1\nproviders:\n- name: Nomad Autoscaler\n  folder: Nomad\n  folderUid: nomad\n  type: file\n  disableDeletion: true\n  editable: false\n  allowUiUpdates: false\n  options:\n    path: \/var\/lib\/grafana\/dashboards\nEOH\n\n        destination = &quot;local\/dashboards\/nomad-autoscaler.yaml&quot;\n      }\n\n      volume_mount {\n        volume      = &quot;grafana&quot;\n        destination = &quot;\/var\/lib\/grafana&quot;\n      }\n\n      resources {\n        cpu    = 100\n        memory = 64\n      }\n\n      service {\n        name = &quot;grafana&quot;\n        port = &quot;grafana_ui&quot;\n\n        check {\n          type     = &quot;http&quot;\n          path     = &quot;\/api\/health&quot;\n          interval = &quot;10s&quot;\n          timeout  = &quot;2s&quot;\n        }\n      }\n    }\n  }\n}\n-----------------------------------------<\/code><\/pre>\n<pre><code class=\"language-bash\">nomad run grafana.nomad<\/code><\/pre>\n<p>\ud658\uacbd\ubcc0\uc218 <code>GF_INSTALL_PLUGINS<\/code> \uc744 \uc774\uc6a9\ud574 grafana \ud50c\ub7ec\uadf8\uc778\uc744 \uc124\uce58\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n<h2>Autoscaler \uc0dd\uc131<\/h2>\n<pre><code class=\"language-bash\">vi autoscaler.nomad\n-----------------------------------------\njob &quot;autoscaler&quot; {\n  datacenters = [&quot;dc1&quot;]\n\n  group &quot;autoscaler&quot; {\n    count = 1\n\n    task &quot;autoscaler&quot; {\n      driver = &quot;docker&quot;\n\n      config {\n        image   = &quot;hashicorp\/nomad-autoscaler:0.3.3&quot;\n        command = &quot;nomad-autoscaler&quot;\n        network_mode = &quot;host&quot;\n        args    = [&quot;agent&quot;, &quot;-http-bind-port=8090&quot;, &quot;-config&quot;, &quot;${NOMAD_TASK_DIR}\/config.hcl&quot;]\n      }\n\n      template {\n        data = &lt;&lt;EOF\nplugin_dir = &quot;\/plugins&quot;\n\nnomad {\n  address = &quot;http:\/\/{{env &quot;attr.unique.network.ip-address&quot; }}:4646&quot;\n}\napm &quot;nomad&quot; {\n  driver = &quot;nomad-apm&quot;\n  config  = {\n    address = &quot;http:\/\/{{env &quot;attr.unique.network.ip-address&quot; }}:4646&quot;\n  }\n}\napm &quot;prometheus&quot; {\n  driver = &quot;prometheus&quot;\n  config = {\n    address = &quot;http:\/\/{{ env &quot;attr.unique.network.ip-address&quot; }}:9090&quot;\n  }\n}\nstrategy &quot;target-value&quot; {\n  driver = &quot;target-value&quot;\n}\n          EOF\n\n        destination = &quot;${NOMAD_TASK_DIR}\/config.hcl&quot;\n      }\n    }\n  }\n}\n-----------------------------------------<\/code><\/pre>\n<pre><code class=\"language-bash\">nomad run autoscaler.nomad<\/code><\/pre>\n<h2>hello \uc124\uc815<\/h2>\n<pre><code class=\"language-bash\">vi hello.nomad\n------------------------------\njob &quot;hello&quot; {\n  datacenters = [&quot;dc1&quot;]\n  type = &quot;service&quot;\n\n  group &quot;helloGroup&quot; {\n    network {\n      port &quot;http&quot; {}\n      port &quot;https&quot; {}\n      # port &quot;lb&quot; { static = 8080 }\n    }\n\n    count = 1\n\n    scaling {\n      enabled = true\n      min     = 1\n      max     = 2\n\n      policy {\n        cooldown            = &quot;1m&quot;\n        evaluation_interval = &quot;30s&quot;\n\n        check &quot;avg_sessions&quot; {\n          source = &quot;prometheus&quot;\n          query  = &quot;avg((haproxy_server_current_sessions{backend=\\&quot;http_back\\&quot;}) and (haproxy_server_up{backend=\\&quot;http_back\\&quot;} == 1))&quot;\n\n          strategy &quot;target-value&quot; {\n            target = 5\n          }\n        }\n      }\n    }\n\n    # Define a task to run\n    task &quot;helloTask&quot; {\n      driver = &quot;java&quot;\n\n      config {\n        jar_path = &quot;local\/TestPublic-0.0.2-SNAPSHOT.jar&quot;\n        jvm_options = [&quot;-Xmx256m&quot;,&quot;-Xms256m&quot;]\n      }\n\n      env {\n        PORT    = &quot;${NOMAD_PORT_http}&quot;\n        NODE_IP = &quot;${NOMAD_IP_http}&quot;\n      }\n\n      service {\n        name = &quot;helloService&quot;\n        # port = &quot;lb&quot;\n        port = &quot;http&quot;\n\n        check {\n          type     = &quot;http&quot;\n          path     = &quot;\/hello&quot;     # health check \uc6a9 url\n          interval = &quot;2s&quot;\n          timeout  = &quot;2s&quot;\n        }\n      }\n\n      resources {\n        cpu = 500         # 500 Mhz\n        memory = 500      # 500 MB\n      }\n\n      # \uc6d0\uaca9\uc5d0\uc11c \ub2e4\uc6b4\ubc1b\uc544\uc57c \ud569\ub2c8\ub2e4.\n      artifact {\n        source = &quot;https:\/\/github.com\/skyer9\/TestPublic\/raw\/master\/TestPublic-0.0.2-SNAPSHOT.jar&quot;\n      }\n    }\n  }\n}\n------------------------------<\/code><\/pre>\n<pre><code class=\"language-bash\">nomad run hello.nomad<\/code><\/pre>\n<h2>Grafana \ub300\uc2dc\ubcf4\ub4dc \ucd94\uac00<\/h2>\n<p><code>Nomad Cluster<\/code> \ub300\uc2dc\ubcf4\ub4dc 6278 \uc744 \uc124\uce58\ud569\ub2c8\ub2e4.<\/p>\n<p><code>Nomad Jobs<\/code> \ub300\uc2dc\ubcf4\ub4dc 12787 \uc744 \ucd94\uac00\ud569\ub2c8\ub2e4.<\/p>\n<p><code>JVM (Micrometer)<\/code> \ub300\uc2dc\ubcf4\ub4dc 4701 \uc744 \ucd94\uac00\ud569\ub2c8\ub2e4.<\/p>\n<p><a href=\"https:\/\/www.skyer9.pe.kr\/wordpress\/wp-content\/uploads\/2021\/08\/2021-08-18-04.png\"><img decoding=\"async\" src=\"https:\/\/www.skyer9.pe.kr\/wordpress\/wp-content\/uploads\/2021\/08\/2021-08-18-04.png\" alt=\"\" \/><\/a><\/p>\n<p><a href=\"https:\/\/www.skyer9.pe.kr\/wordpress\/wp-content\/uploads\/2021\/08\/2021-08-18-05.png\"><img decoding=\"async\" src=\"https:\/\/www.skyer9.pe.kr\/wordpress\/wp-content\/uploads\/2021\/08\/2021-08-18-05.png\" alt=\"\" \/><\/a><\/p>\n<p>\uc2dc\uac04\uc744 5\ubd84\uc73c\ub85c \ubcc0\uacbd\ud574 \uc90d\ub2c8\ub2e4.<\/p>\n<p><a href=\"https:\/\/www.skyer9.pe.kr\/wordpress\/wp-content\/uploads\/2021\/08\/2021-08-18-03.png\"><img decoding=\"async\" src=\"https:\/\/www.skyer9.pe.kr\/wordpress\/wp-content\/uploads\/2021\/08\/2021-08-18-03.png\" alt=\"\" \/><\/a><\/p>\n<h2>\uc2a4\ud2b8\ub808\uc2a4 \ud14c\uc2a4\ud2b8 \ud558\uae30<\/h2>\n<pre><code class=\"language-bash\">wget https:\/\/hey-release.s3.us-east-2.amazonaws.com\/hey_linux_amd64\nchmod 777 hey_linux_amd64\nsudo mv hey_linux_amd64 \/usr\/bin\/hey\n\nhey -help<\/code><\/pre>\n<p>5\ubd84\uac04 200\uac1c\uc758 \ub3d9\uc2dc \ucee4\ub125\uc158\uc744 \ud558\ub3c4\ub85d \ud569\ub2c8\ub2e4.<\/p>\n<pre><code class=\"language-bash\">hey -z 5m -c 200 http:\/\/localhost:8080\/hello<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>nomad autoscaler \uac00\uc9c0\uace0 \ub180\uae30 \ucc38\uc870 \ucc38\uc870 \ubaa9\ud45c nomad autoscaler \ub97c \uc774\uc6a9\ud574 Auto Scaling \uc744 \uc791\ub3d9\uc2dc\ud0b5\ub2c8\ub2e4. \uc900\ube44\ubb3c \uc124\uce58 AWS AMI \uc778\uc2a4\ud134\uc2a4\ub97c \uc0dd\uc131\ud569\ub2c8\ub2e4. \uba54\ubaa8\ub9ac\ub294 2G \ub85c \ud569\ub2c8\ub2e4. JDK, Docker \ub97c \uc124\uce58\ud569\ub2c8\ub2e4. sudo yum install java-11-amazon-corretto-headless -y java -version sudo yum install docker -y docker -v sudo service docker start sudo systemctl enable docker.service Consul \uc124\uce58 sudo mkdir\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=2881\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31],"tags":[],"class_list":["post-2881","post","type-post","status-publish","format-standard","hentry","category-nomad"],"_links":{"self":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/2881","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2881"}],"version-history":[{"count":117,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/2881\/revisions"}],"predecessor-version":[{"id":3426,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/2881\/revisions\/3426"}],"wp:attachment":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2881"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2881"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2881"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}