Skip to content

Instantly share code, notes, and snippets.

@anishcorratech
Last active August 1, 2017 13:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anishcorratech/106fddd8ab6435a6abc84d19c4ee16c9 to your computer and use it in GitHub Desktop.
Save anishcorratech/106fddd8ab6435a6abc84d19c4ee16c9 to your computer and use it in GitHub Desktop.
Multiple REDIS instance on a CENTOS Linux

Multiple REDIS instance on a CENTOS Linux

  • create a new redis .conf file
$ cp /etc/redis.conf /etc/redis-xxx.conf
  • edit /etc/redis-xxx.conf, illustrated as below
...
#modify pidfile
#pidfile /var/run/redis/redis.pid
pidfile /var/run/redis/redis-xxx.pid

...
#dir /var/lib/redis/
dir /var/lib/redis-xxx/

...
#modify port
#port 6379
port 6380

...
#modify logfile
#logfile /var/log/redis/redis.log
logfile /var/log/redis/redis-xxx.log

...
#modify vm-swap-file
#vm-swap-file /tmp/redis.swap
vm-swap-file /tmp/redis-xxx.swap
...
  • make dir /var/lib/redis-xxx
$ mkdir -p /var/lib/redis-xxx
  • copy init script
$ cp /etc/init.d/redis /etc/init.d/redis-xxx
  • edit the new init script
...

#pidfile="/var/run/redis/redis.pid"
pidfile="/var/run/redis/redis-xxx.pid"

...

#REDIS_CONFIG="/etc/redis.conf"
REDIS_CONFIG="/etc/redis-xxx.conf"

...
  • copy the shutdown script
cp -ar /usr/bin/redis-shutdown /usr/bin/redis-xxx-shutdown
  • edit the new shutdown script
...
#SERVICE_NAME=redis
SERVICE_NAME=redis-session
...

...
# if [ "$SERVICE_NAME" = redis ]; then
if [ "$SERVICE_NAME" = redis-session ]; then
...

...
#PORT=${PORT:-6379}
PORT=${PORT:-6380}
...

  • query the status of this redis in
$ sudo service redis-xxx status
# server is stopped

# start service
$ sudo service redis-xxx start
  • make redis-xxx service auto start
$ sudo chkconfig --level 3 redis-xxx on
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment