Selasa, 09 April 2019

Setting up NSQ as a Service on CentOS 7 (SystemD)


In this tutorial I will give an example of making nsqlookup, nsqd and nsqadmin run as service in centos 7 (systemD)

first create a configuration file for each of these services and all configurations are placed in the /etc/nsq directory


for the nsqlookupd configuration file it is nsqlookupd.conf and make it like the file below

# cd /etc/nsq
# vi nsqlookupd.conf

## log verbosity level: debug, info, warn, error, or fatal
log-level = "info"

## <addr>:<port> to listen on for TCP clients
tcp_address = "0.0.0.0:4160"

## <addr>:<port> to listen on for HTTP clients
http_address = "0.0.0.0:4161"

## address that will be registered with lookupd (defaults to the OS hostname)
broadcast_address = "main"


## duration of time a producer will remain in the active list since its last ping
inactive_producer_timeout = "300s"

## duration of time a producer will remain tombstoned if registration remains
tombstone_lifetime = "45s"


for the nsqd configuration file it is nsqd.conf and make it like the file below

# vi nsqd.conf

## log verbosity level: debug, info, warn, error, or fatal
#log-level = "info"

## unique identifier (int) for this worker (will default to a hash of hostname)
# id = 5150

## <addr>:<port> to listen on for TCP clients
tcp_address = "0.0.0.0:4150"

## <addr>:<port> to listen on for HTTP clients
http_address = "0.0.0.0:4151"

## <addr>:<port> to listen on for HTTPS clients
# https_address = "0.0.0.0:4152"

## address that will be registered with lookupd (defaults to the OS hostname)
broadcast_address = "127.0.0.1"

## cluster of nsqlookupd TCP addresses
nsqlookupd_tcp_addresses = [
    "127.0.0.1:4160"
]

## duration to wait before HTTP client connection timeout
http_client_connect_timeout = "2s"

## duration to wait before HTTP client request timeout
http_client_request_timeout = "5s"

## path to store disk-backed messages
data_path = "/var/lib/nsq"

## number of messages to keep in memory (per topic/channel)
mem_queue_size = 10000

## number of bytes per diskqueue file before rolling
max_bytes_per_file = 104857600

## number of messages per diskqueue fsync
sync_every = 2500

## duration of time per diskqueue fsync (time.Duration)
sync_timeout = "2s"

## duration to wait before auto-requeing a message
msg_timeout = "60s"

## maximum duration before a message will timeout
max_msg_timeout = "15m"

## maximum size of a single message in bytes
max_msg_size = 1024768

## maximum requeuing timeout for a message
max_req_timeout = "1h"

## maximum size of a single command body
max_body_size = 5123840

## maximum client configurable duration of time between client heartbeats
max_heartbeat_interval = "60s"

## maximum RDY count for a client
max_rdy_count = 2500

## maximum client configurable size (in bytes) for a client output buffer
max_output_buffer_size = 65536

## maximum client configurable duration of time between flushing to a client (time.Duration)
max_output_buffer_timeout = "1s"

## UDP <addr>:<port> of a statsd daemon for pushing stats
# statsd_address = "127.0.0.1:8125"

## prefix used for keys sent to statsd (%s for host replacement)
statsd_prefix = "nsq.%s"

## duration between pushing to statsd (time.Duration)
statsd_interval = "60s"

## toggle sending memory and GC stats to statsd
statsd_mem_stats = true

## the size in bytes of statsd UDP packets
# statsd_udp_packet_size = 508

## message processing time percentiles to keep track of (float)
e2e_processing_latency_percentiles = [
    1.0,
    0.99,
    0.95
]

## calculate end to end latency quantiles for this duration of time (time.Duration)
e2e_processing_latency_window_time = "10m"

## path to certificate file
tls_cert = ""

## path to private key file
tls_key = ""

## set policy on client certificate (require - client must provide certificate,
##  require-verify - client must provide verifiable signed certificate)
# tls_client_auth_policy = "require-verify"

## set custom root Certificate Authority
# tls_root_ca_file = ""

## require client TLS upgrades
tls_required = false

## minimum TLS version ("ssl3.0", "tls1.0," "tls1.1", "tls1.2")
tls_min_version = ""

## enable deflate feature negotiation (client compression)
deflate = true

## max deflate compression level a client can negotiate (> values == > nsqd CPU usage)
max_deflate_level = 6

## enable snappy feature negotiation (client compression)
snappy = true


for the nsqadmin configuration file it is nsqadmin.conf and make it like the file below

# vi  nsqadmin.conf

## log verbosity level: debug, info, warn, error, or fatal
log-level = "info"

## <addr>:<port> to listen on for HTTP clients
http_address = "0.0.0.0:4171"

## graphite HTTP address
graphite_url = ""

## proxy HTTP requests to graphite
proxy_graphite = false

## prefix used for keys sent to statsd (%s for host replacement, must match nsqd)
statsd_prefix = "nsq.%s"

## format of statsd counter stats
statsd_counter_format = "stats.counters.%s.count"

## format of statsd gauge stats
statsd_gauge_format = "stats.gauges.%s"

## time interval nsqd is configured to push to statsd (must match nsqd)
statsd_interval = "60s"

## HTTP endpoint (fully qualified) to which POST notifications of admin actions will be sent
notification_http_endpoint = ""

## nsqlookupd HTTP addresses
nsqlookupd_http_addresses = [
    "127.0.0.1:4161"
]

## nsqd HTTP addresses (optional)
#nsqd_http_addresses = [
#    "127.0.0.1:4151"
#]


let's make a service for all nsq service
  • nsqlookupd

  • # cd /etc/systemd/system
    # vim nsqlookupd.service

    [Unit]
    Description=nsqlookup daemon Service
    After=network.target

    [Service]
    PrivateTmp=yes
    ExecStart=/usr/local/nsq/bin/nsqlookupd -config /etc/nsq/nsqlookupd.conf
    Restart=always

    [Install]
    WantedBy=multi-user.target

  • nsqd

  • # vim nsqd.service

    [Unit]
    Description=Realtime distributed messaging (nsqd)
    After=network.target

    [Service]
    PrivateTmp=yes
    ExecStart=/usr/local/nsq/bin/nsqd -config /etc/nsq/nsqd.conf
    Restart=always

    [Install]
    WantedBy=multi-user.target

  • nsqadmin

  • v# vim nsqadmin.service

    [Unit]
    Description=nsqadmin daemon Service (nsqadmin)
    After=network.target

    [Service]
    PrivateTmp=yes
    ExecStart=/usr/local/nsq/bin/nsqadmin -config /etc/nsq/nsqadmin.conf
    Restart=always

    [Install]
    WantedBy=multi-user.target

enable all nsq service

# systemctl enable nsqlookupd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/nsqlookupd.service to /etc/systemd/system/nsqlookupd.service.

# systemctl enable nsqd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/nsqd.service to /etc/systemd/system/nsqd.service.

# systemctl enable nsqadmin.service
Created symlink from /etc/systemd/system/multi-user.target.wants/nsqadmin.service to /etc/systemd/system/nsqadmin.service.

here we go start the service

# systemctl start nsqlookupd
# systemctl start nsqd
# systemctl start nsqadmin

to check service run or not

# systemctl status nsqlookupd
● nsqlookupd.service - nsqlookup daemon Service
   Loaded: loaded (/etc/systemd/system/nsqlookupd.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2019-04-09 03:38:40 EDT; 1h 41min ago
 Main PID: 5193 (nsqlookupd)
   CGroup: /system.slice/nsqlookupd.service
           └─5193 /usr/local/nsq/bin/nsqlookupd -config /etc/nsq/nsqlookupd.c...

Apr 09 05:18:06 main.coba.net nsqlookupd[5193]: [nsqlookupd] 2019/04/09 05:1...)
Hint: Some lines were ellipsized, use -l to show in full.

# systemctl status nsqd
● nsqd.service - Realtime distributed messaging (nsqd)
   Loaded: loaded (/etc/systemd/system/nsqd.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2019-04-09 04:58:21 EDT; 22min ago
 Main PID: 5234 (nsqd)
   CGroup: /system.slice/nsqd.service
           └─5234 /usr/local/nsq/bin/nsqd -config /etc/nsq/nsqd.conf

Apr 09 04:58:21 main.coba.net nsqd[5234]: [nsqd] 2019/04/09 04:58:21.319327 ...0
Hint: Some lines were ellipsized, use -l to show in full.

# systemctl status nsqadmin
● nsqadmin.service - nsqadmin daemon Service (nsqadmin)
   Loaded: loaded (/etc/systemd/system/nsqadmin.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2019-04-09 04:59:13 EDT; 21h ago
 Main PID: 5249 (nsqadmin)
   CGroup: /system.slice/nsqadmin.service
           └─5249 /usr/local/nsq/bin/nsqadmin -config /etc/nsq/nsqadmin.conf

Apr 09 04:59:13 main.coba.net systemd[1]: Started nsqadmin daemon Service (n....
Apr 09 04:59:13 main.coba.net nsqadmin[5249]: [nsqadmin] 2019/04/09 04:59:13...)
Hint: Some lines were ellipsized, use -l to show in full


That all's

Tidak ada komentar: