Redis implement multi-ports and multiple instances for single operation

Source: Internet
Author: User
Tags redis install redis redis server

First, the installation of Redis-server

Since I am using the Ubuntu system for my current web machine, here is an example of Ubuntu, which can be installed directly using apt source redis-server

$ sudo apt-get install Redis-server
After the installation is complete, you can use the dpkg command to view the path where the files are located:

  code is as follows copy code
$ sudo dpkg-l redis-server
/.
/etc
/etc/default
/etc/default/ Redis-server
/etc/redis
/etc/redis/redis.conf
/etc/redis/sentinel.conf
/ETC/INIT.D
/etc/init.d/ Redis-server
/ETC/LOGROTATE.D
/etc/logrotate.d/redis-server
/var
/var/log
/var/log/redis
/ Var/lib
/var/lib/redis
/usr
/usr/bin
/usr/bin/redis-server
/usr/share
/usr/share/man
/usr /share/man/man1
/usr/share/man/man1/redis-server.1.gz
/usr/share/doc
/usr/share/doc/redis-server
/ Usr/share/doc/redis-server/copyright
/usr/bin/redis-sentinel
/usr/share/doc/redis-server/changelog. debian.gz

Where/usr/bin/redis-server is the program execution file,/etc/redis/redis.conf is the configuration file,/etc/init.d/redis-server is the self startup file. Single instance, you can start by Sudo/etc/init.d/redis-server start.

Second, run multiple instance Redis

The default configuration file contents are:

The code is as follows Copy Code
$ Egrep-v ' ^#|^$ ' redis.conf
Daemonize Yes
Pidfile/var/run/redis/redis-server.pid
Port 6379
Bind 127.0.0.1
Timeout 0
Tcp-keepalive 0
LogLevel Notice
Logfile/var/log/redis/redis-server.log
Databases 16
Save 900 1
Save 300 10
Save 60 10000
Stop-writes-on-bgsave-error Yes
Rdbcompression Yes
Rdbchecksum Yes
Dbfilename Dump.rdb
Dir/var/lib/redis
Slave-serve-stale-data Yes
Slave-read-only Yes
Repl-disable-tcp-nodelay No
Slave-priority 100
AppendOnly No
Appendfilename "Appendonly.aof"
Appendfsync everysec
No-appendfsync-on-rewrite No
Auto-aof-rewrite-percentage 100
Auto-aof-rewrite-min-size 64MB
Lua-time-limit 5000
Slowlog-log-slower-than 10000
Slowlog-max-len 128
Notify-keyspace-events ""
Hash-max-ziplist-entries 512
Hash-max-ziplist-value 64
List-max-ziplist-entries 512
List-max-ziplist-value 64
Set-max-intset-entries 512
Zset-max-ziplist-entries 128
Zset-max-ziplist-value 64
activerehashing Yes
Client-output-buffer-limit Normal 0 0 0
Client-output-buffer-limit slave 256MB 64MB 60
Client-output-buffer-limit pubsub 32MB 8MB 60
Hz 10
Aof-rewrite-incremental-fsync Yes

The meaning of the parameters in the specific configuration file, you can refer to the Redis configuration file detailed. Suppose we now have to start two more Redis instances, listening on the port is 6378, 6376, only need to duplicate a copy of the redis.conf configuration file and make a modification and then through the Redis-server boot.

Take the Redis 6378 port as an example, only need to modify the following parts, other configuration department he still use the default can:

The code is as follows Copy Code
Pidfile/var/run/redis/redis-server6378.pid
Port 6378
Logfile/var/log/redis/redis-server6378.log
dir/opt/redis6378
Vm-swap-file/opt/redis6378/redis.swap

The Dir store path can also be/var/lib/redis with the default location, but Dbfilename can no longer use the defaults Dump.rdb, you may use Dump6378.rdb. However, it is recommended that different Redis instances be stored in different paths.

After modifying the configuration file, you can start a new Redis instance by using the following command:

The code is as follows Copy Code
# sudo/usr/bin/redis-server/etc/redis/redis6378.conf

However, after the boot, through the PS command view will find a problem, the original default Redis instance is started with the Redis user, and the new Redis instance will start with root.

The code is as follows Copy Code
yang@crunchbang:/var/lib/redis$ PS Auxf|grep Redis
Yang 4296 0.0 0.0 8060 864 pts/0 s+ 05:41 0:00 | _ grep Redis
Redis 3837 0.0 0.0 35912 1492? SSL 05:22 0:00/usr/bin/redis-server/etc/redis/redis.conf
Root 4275 0.0 0.0 35912 1480? SSL 05:37 0:00/usr/bin/redis-server/etc/redis/redis6378.conf

By looking at/etc/init.d/redis-server from the startup file, you will find that the statement that you use when starting at Start is:

The code is as follows Copy Code
Start-stop-daemon--start--quiet--umask 007--pidfile $PIDFILE--chuid Redis:redis--exec $DAEMON--$DAEMON _args

Here again, you can draw a gourd. Copy sudo cp/etc/init.d/redis-server/etc/init.d/redis6378, and after the replication is complete, modify the following:

The code is as follows Copy Code
Daemon_args=/etc/redis/redis6378.conf
Name=redis-server
Desc=redis6378-server
Rundir=/var/run/redis
pidfile= $RUNDIR/redis-server6378.pid

When you have finished modifying it, you can also start with the redis6378 configuration file. Then through the PS view, the discovery also will be a Redis user run the process. Want to add 6376, 6375 and so on more than one instance, also press the above method to operate on OK.

Here are the results of the test after you refer to this article yourself:

The default Redis program is installed in the/usr/local/redis directory;

Configuration file:/usr/local/redis/redis.conf, the port configured in this profile is the default port: 6379;

The code is as follows Copy Code

Redis boot command path:/usr/local/bin/redis-server.

You can specify a port to start multiple Redis processes.

The code is as follows Copy Code

#/usr/local/bin/redis-server
--port 6380 & #启动6380端口的redis实例.

Multiple Redis instances need to be started:

A Redis server, divided into multiple nodes, each node assigned a port (6380,6381 ...) ), the default port is 6379.
Each node corresponds to a redis configuration file, such as: redis6380.conf, redis6381.conf

The code is as follows Copy Code

#cp redis.confredis6380.conf

#vi redis6380.conf

Pidfile:pidfile/var/run/redis/redis_6380.pid

Port 6380

Logfile:logfile/var/log/redis/redis_6380.log

Rdbfile:dbfilenamedump_6380.rdb

(Other configuration files are similar to modifications)

To start multiple Redis instances:

  code is as follows copy code

#redis-server /usr/local/redis/redis6380.conf

#redis-server/usr/local/redis/redis6381.conf

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.