redis-trib.rb is no longer available but redis-cli --cluster create throws unrecognized option error - redis

I am attempting to create a new redis cluster on the docker swarm using redis 4.0.11. The closest tutorial I have found was this one: https://get-reddie.com/blog/redis4-cluster-docker-compose/
The problem I am having is this like all other tutorials use the ruby redis-trib.rb script to create the cluster after discovering all of the nodes and this guy seems to be no longer supported:
| WARNING: redis-trib.rb is not longer available!
| You should use redis-cli instead.
|
| All commands and features belonging to redis-trib.rb have been moved
| to redis-cli.
| In order to use them you should call redis-cli with the --cluster
| option followed by the subcommand name, arguments and options.
|
| Use the following syntax:
| redis-cli --cluster SUBCOMMAND [ARGUMENTS] [OPTIONS]
|
| Example:
| redis-cli --cluster create 172.22.0.3:6379 172.22.0.5:6379 172.22.0.7:6379 172.22.0.2:6379 172.22.0.6:6379 172.22.0.4:6379 --cluster-replicas 1
|
| To get help about all subcommands, type:
| redis-cli --cluster help
But yet when I attempt to use the recommended command I get an error:
# redis-cli --cluster create 172.22.0.3:6379 172.22.0.5:6379 172.22.0.7:6379 172.22.0.2:6379 172.22.0.6:6379 172.22.0.4:6379 --cluster-replicas 1
Unrecognized option or bad number of args for: '--cluster'
# redis-cli --cluster help
Unrecognized option or bad number of args for: '--cluster'
Ideas?

redis-cli 4.0.11 hasn't --cluster option.
use following ways:
download https://github.com/antirez/redis/archive/unstable.zip
make
use redis-cli in src/redis

They have changed the docs, with the previous version you had to do it with the redis-trib.rb file as you said.
The easiest way to do it, is to download to your server the previous redis-trib.rb (link) and run this command:
./redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 \
127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005
before you do it make sure you have installed ruby.
If you have any questions let me know :)
Good luck!

Related

Ignite cluster size using control script

I need to get ignite cluster size(no of server nodes running) preferably using control script or ignite rest api. I am able to get baseline nodes using command below but I don't see any command or rest api to return topology snapshot. Is there a way we could get this information to ignite client rather than looking into logs.
Workaround to get baseline nodes:
baselineNodes=$(kubectl --kubeconfig config.conf exec <ignite-node> -n {client_name} -- /opt/ignite/apache-ignite/bin/./control.sh --baseline | grep "Number of baseline nodes" | cut -d ':' -f2 | sed 's/^ *//g')
It seems that topology REST command could do the trick. Here's the documentation link.
http://host:port/ignite?cmd=top&attr=true&mtr=true&id=c981d2a1-878b-4c67-96f6-70f93a4cd241
Got help from ignite community and below command worked for me. Basically idea is to use metric to extract server nodes.
kubectl --kubeconfig config.conf exec <ignite-node> -n {client_name} -- /opt/ignite/apache-ignite/bin/./control.sh --metric cluster.TotalServerNodes | grep -v "metric" | grep cluster.TotalServerNodes | cut -d " " -f5 | sed 's/^ *//g'
Quoting the reply received:
"You can query any metric value or system view content via control script [1], [2]
control.sh --system-view nodes
or [3]
control.sh —metric cluster.TotalBaselineNodes
control.sh —metric cluster.TotalServerNodes
control.sh —metric cluster.TotalClientNodes
[1] https://ignite.apache.org/docs/latest/tools/control-script#metric-command
[2] https://ignite.apache.org/docs/latest/tools/control-script#system-view-command
[3] https://ignite.apache.org/docs/2.11.1/monitoring-metrics/new-metrics#cluster"

How to get rabbitmq cluster status in json format

How to get status and cluster_status from rabbitmq in JSON format
sudo rabbitmqctl status
sudo rabbitmqctl cluster_status
help is your friend:
# rabbitmqctl help cluster_status
Error:
Usage
rabbitmqctl [--node <node>] [--longnames] [--quiet] cluster_status
Displays all the nodes in the cluster grouped by node type, together with the currently running nodes.
Relevant Doc Guides
* https://rabbitmq.com/clustering.html
* https://rabbitmq.com/cluster-formation.html
* https://rabbitmq.com/monitoring.html
General Options
The following options are accepted by most or all commands.
short | long | description
-----------------|---------------|--------------------------------
-? | --help | displays command help
-n <node> | --node <node> | connect to node <node>
-l | --longnames | use long host names
-t | --timeout <n> | for commands that support it, operation timeout in seconds
-q | --quiet | suppress informational messages
-s | --silent | suppress informational messages
| and table header row
-p | --vhost | for commands that are scoped to a virtual host,
| | virtual host to use
| --formatter | alternative result formatter to use
| if supported: json, pretty_table, table, csv.
not all commands support all (or any) alternative formatters.
Figured out by myself. You can use the option --formatter json
Could not find it in the rabbitmq documentation!
sudo rabbitmqctl cluster_status --formatter json
sudo rabbitmqctl cluster_status --formatter json | jq .running_nodes
To parse this and use it in bash script:
running_nodes=($(egrep -o '[a-z0-9#-]+' <<< $(sudo rabbitmqctl cluster_status --formatter json | jq .running_nodes)))

redis: Create cluster with redis-cli non interactively

When trying to create a cluster with redis-cli as follows
redis-cli --cluster create
a prompt comes up asking for configuration confirmation?
Is there a way to script this (preferably in ansible) and run it non-interactively?
I am aware of this topic however it addresses data manipulation which is not the scope of this question.
--cluster-yes is the correct option!
EDIT:
The answer of Leonardo Oliveira rightfully points out that the option --cluster-yes will avoid the prompt. For example:
redis-cli --cluster create host1:6379 host2:6379 host3:6379 --cluster-yes
As of the current Redis version (5.0.5) there doesn't seem to be a flag under --cluster that can silence or auto-answer the interactive question:
$ redis-cli --cluster help
Cluster Manager Commands:
create host1:port1 ... hostN:portN
--cluster-replicas <arg>
check host:port
--cluster-search-multiple-owners
info host:port
fix host:port
--cluster-search-multiple-owners
reshard host:port
--cluster-from <arg>
--cluster-to <arg>
--cluster-slots <arg>
--cluster-yes
--cluster-timeout <arg>
--cluster-pipeline <arg>
--cluster-replace
rebalance host:port
--cluster-weight <node1=w1...nodeN=wN>
--cluster-use-empty-masters
--cluster-timeout <arg>
--cluster-simulate
--cluster-pipeline <arg>
--cluster-threshold <arg>
--cluster-replace
add-node new_host:new_port existing_host:existing_port
--cluster-slave
--cluster-master-id <arg>
del-node host:port node_id
call host:port command arg arg .. arg
set-timeout host:port milliseconds
import host:port
--cluster-from <arg>
--cluster-copy
--cluster-replace
help
By using echo you can execute the command and auto-answer the prompt:
echo "yes" | redis-cli --cluster create host1:6379 host2:6379 host3:6379
The default Ansible Redis module only supports a few commands and not --cluster so you would have to create your own logic with command/shell tasks:
- name: Create cluster
shell: echo "yes" | redis-cli --cluster create host1:6379 host2:6379 host3:6379
run_once: true
when: not cluster_setup_done
Well, I don't know about the ansible part. But Redis official site does provide a way to create cluster with script in a little interactive-mode.
Creating a Redis Cluster using the create-cluster script (Please refer docs for more details)
If you don't want to create a Redis Cluster by configuring and executing individual instances manually as explained above, there is a much simpler system (but you'll not learn the same amount of operational details).
Just check utils/create-cluster directory in the Redis distribution. There is a script called create-cluster inside (same name as the directory it is contained into), it's a simple bash script. In order to start a 6 nodes cluster with 3 masters and 3 slaves just type the following commands:
create-cluster start
create-cluster create
Reply to yes in step 2 when the redis-cli utility wants you to accept the cluster layout.
You can now interact with the cluster, the first node will start at port 30001 by default. When you are done, stop the cluster with:
create-cluster stop
Please read the README inside this directory for more information on how to run the script.
You can try implementing this if it helps you in any way!
Cheers :)

how to delete nodes from redis cluster?

I google it and found two solution:
CLUSTER FORGET (http://redis.io/commands/cluster-forget)
redis-trib.rb del-node
I think CLUSTER FORGET" is the right way to do.
But I really want to know the details about redis-trib.rb del-node.
Can someone explain the difference between them?
redis-trib.rb is a ruby utility script that antirez (lead redis developer) built as a reference implementation of building administrative tools on top of the basic redis cluster commands.
Under the hood redis-trib uses CLUSTER FORGET to implement it's own administrative del-node command. https://github.com/antirez/redis/blob/unstable/src/redis-trib.rb#L1374
Redis-trib is a lot friendlier to work with. If you're doing CLUSTER FORGET you'd need to loop over and send that command to every other node in the system, while del-node will automate that process for you.
As of Redis 6.2.3
WARNING: redis-trib.rb is not longer available!
You should use redis-cli instead.
All commands and features belonging to redis-trib.rb have been moved
to redis-cli.
In order to use them you should call redis-cli with the --cluster
option followed by the subcommand name, arguments and options.
Use the following syntax:
redis-cli --cluster SUBCOMMAND [ARGUMENTS] [OPTIONS]
Example:
redis-cli --cluster info 127.0.0.1:6382
~$ redis-cli
127.0.0.1:6379> CLUSTER HELP
127.0.0.1:6379> CLUSTER NODES
127.0.0.1:6379> CLUSTER FORGET <node-id>
src/redis-trib.rb del-node 192.168.0.211:6379 650e3746968e6b7c7e357f06adbde5b3b92fcceb
Note:
192.168.0.211:6379 This is any node in the cluster
650e3746968e6b7c7e357f06adbde5b3b92fcceb this is the cluster ID of the node you want to remove. You can get the value of this ID from “cluster nodes” command.
Per redis article you should use:
redis-cli --cluster del-node 127.0.0.1:7000
where the the first argument is one of your cluster nodes.
Check 'removing a node' in he following article:
https://redis.io/docs/manual/scaling/

Loading initial data into a Redis Docker container

I'm trying to create a Redis Docker image, based on the redis:3. However, I need to load a small amount of test data into the image (it is used for testing, both on developer machines and on the CI server).
My initial attempt looks like:
FROM redis:3.0.3
MAINTAINER Howard M. Lewis Ship
RUN redis-cli sadd production-stores 5555
But this fails with the error:
Step 2 : RUN redis-cli sadd production-stores 5555
---> Running in 60fb98c133c0
Could not connect to Redis at 127.0.0.1:6379: Connection refused
The command '/bin/sh -c redis-cli sadd production-stores 5555' returned a non-zero code: 1
I'm wondering if there's a trick that allows me, in a Docker file, to connect to the server started via the CMD/ENTRYPOINT of the Dockerfile. As I'm guessing right now, the RUN occurs before the command is started.
Alternately, is there a Redis command or trick that would allow me to load some data into its database.
I suspect one approach would be to mount the Redis' data directory in a volume exposed to the Docker host; this is not ideal as
I would need an extra non-Dockerfile command to load the data
The loaded data would not be shared in the image, which is to be used by others on my team
I'm on OS X and am using docker-machine, so the volumes get trickier
The error tells Redis service is not started before you run redis-cli.
Add a new line to start it first. Let me know if this can fix your issue or not.
FROM redis:3.0.3
MAINTAINER Howard M. Lewis Ship
RUN /usr/sbin/redis-server /etc/redis.conf
RUN redis-cli sadd production-stores 5555
Updates:
Review the official redis image, it has given the way to use redis-cli
# via redis-cli
$ docker run -it --link some-redis:redis --rm redis sh -c 'exec redis-cli -h "$REDIS_PORT_6379_TCP_ADDR" -p "$REDIS_PORT_6379_TCP_PORT"'
So I test the image and make it run as below:
# start redis container
$ docker run --name some-redis -d redis
# link redis container and run redis-cli command
$ docker run -it --link some-redis:redis --rm redis redis-cli -h redis
redis:6379> PING
PONG
redis:6379> exit
# Add the specified members to the set stored at key
$ docker run -it --link some-redis:redis --rm redis redis-cli -h redis sadd production-stores 5555
(integer) 1
$