Skip to content
alirezaAsadi2018 edited this page Aug 29, 2019 · 3 revisions

Redis 5.0.5

Download

Download redis form redis.io and extract it using tar -xzf. Then move it to the directory you want to install it in.

Install

cd deps
make hiredis jemalloc linenoise lua geohash-int
cd ..
make

Run

Make a new directory and copy redis-server from src folder to it. Then make a new directory named 7000 (the port you want redis to listen on it). Create a file named redis.conf in this directory and write this settings into it:

port 7000
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
save 3600 10000
bind 0.0.0.0

Now you can start server with:

../redis-server ./redis.conf

Clustering

on one of the servers cd to src directory in redis installation path and run following command to make a redis cluster.

./redis-cli --cluster create node1-ip:node1-port node2-ip:node2-port node3-ip:node3-port --cluster-replicas 0\

note that redis doesn't accept host names for clustering so you need to enter the exact ip of the node.

CLI

You can connect and control your redis node by redis-cli. Cd to redis directory and open cli with the following command:

src/redis-cli -c -p PORT

Remove All Links

in redis-cli run FLUSHALL command.

redis-exporter:

wget https://github.com/oliver006/redis_exporter/releases/download/v1.0.4/redis_exporter-v1.0.4.linux-amd64.tar.gz
tar xzf redis_exporter-v1.0.4.linux-amd64.tar.gz
cd redis_exporter-v1.0.4.linux-amd64/
mv redis_exporter /usr/local/bin/
cd /etc/systemd/system
nano redis_exporter.service

after opening redis_exporter.service file with nano, write the following into it:

[Unit]
Description=Prometheus
Documentation=https://github.com/oliver006/redis_exporter
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=root
Group=root
ExecReload=/bin/kill -HUP $MAINPID
ExecStart=/usr/local/bin/redis_exporter \
  --log-format=txt \
  --namespace=redis \
  --web.listen-address=:9121 \
  --web.telemetry-path=/metrics \
  --redis.addr=redis://localhost:7000

SyslogIdentifier=redis_exporter
Restart=always

[Install]
WantedBy=multi-user.target

now you are ready to start the service:

systemctl start redis_exporter.service
#check if it is started with following command:
systemctl status redis_exporter.service

finally you should connect to master and change prometheus.yml file and add this exporter to it:

cd /usr/local/prometheus
nano prometheus.yml

copy this part to your yml file or if it already exists, just edit it:

#only add servers that export metrics
- job_name: 'redis_exporter'
    static_configs:
      - targets: ['slave1:9121']
      - targets: ['slave2:9121']
      - targets: ['master:9121']
      - targets: ['slave3:9121']

Links

Installation

Clustering

Clone this wiki locally