Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Redis single instance, multi-instance, master-slave synchronous actual combat

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

[installation of redis single instance]

Yum-y install gcc gcc-c++ # install compilation tool cd / optwget-c http://download.redis.io/releases/redis-3.0.5.tar.gz # download package tar xf redis-3.0.5.tar.gz # extract cd redis-3.0.5make MALLOC=libc # compile make PREFIX=/usr/local/redis install # install echo 'PATH=/usr/local/redis/bin:$PATH' > > / etc/profile # configure environment variable source / etc/profile # or. / etc/profilemkdir / usr/local/redis/conf # create directory cp / opt/redis-3.0.5/redis.conf / usr/local/redis/conf/# copy configuration file sed-I "46s#/var/run/redis.pid#/usr/local/redis/conf/redis.pid#" / usr/local/redis/conf/redis.confsed-I "192s#./#/usr/local/redis/conf/#" / usr/local/redis/ Conf/redis.confsed-I 509s/no/yes/ / usr/local/redis/conf/redis.confnohup redis-server / usr/local/redis/conf/redis.conf & > / dev/null & echo vm.overcommit_memory = 1 > > / etc/sysctl.confsysctl-plsof-iusr/local/redis/conf/redis.confnohup redis-server 6379 # check whether the port is up # redis-cli shutdown

[redis multi-instance actual combat]

Mkdir-p / usr/local/redis/6380/confcp / usr/local/redis/conf/redis.conf / usr/local/redis/6380/conf/sed-I 50s/6379/6380/ / usr/local/redis/6380/conf/redis.confsed-I "46s#/var/run/redis.pid#/usr/local/redis/6380/conf/redis.pid#" / usr/local/redis/6380/conf/redis.confsed-I "192s#./#/usr/local/redis/ 6380/conf/# "/ usr/local/redis/6380/conf/redis.confsed-I 509s/no/yes/ / usr/local/redis/6380/conf/redis.confredis-server / usr/local/redis/6380/conf/redis.conf & mkdir-p / usr/local/redis/6381/confcp / usr/local/redis/conf/redis.conf / usr/local/redis/6381/conf/sed-I 50s/6379/6381/ / usr/local/redis/6381/conf/redis. Confsed-I "46s#/var/run/redis.pid#/usr/local/redis/6381/conf/redis.pid#" / usr/local/redis/6381/conf/redis.confsed-I "192s#./#/usr/local/redis/6381/conf/#" / usr/local/redis/6381/conf/redis.conf # change the rdb file storage directory sed-I 509s/no/yes/ / usr/local/redis/6381/conf/redis.conf # Open the aof log file redis-server / usr/local/redis/6380/conf/redis.conf & # redis-cli-p 6381 > set a b > save > quit# ls / usr/local/redis/6381/conf # View the generated dump.rdb file # redis-cli-p 6381 shutdown # disable the service

[master-slave synchronization] (master and followers can be on the same server, and there must be at least two instances when they are on the same server)

Master: 6379 slave: 6380-"same server, different instance

1) from modifying the configuration file

Sed-I "210a slaveof 192.168.1.103 6379" / usr/local/redis/6380/conf/redis.conf # if you don't write the main IP here, you can also write the main domain name or sed-I "217a masterauth wsyht" / usr/local/redis/6380/conf/redis.conf # master without a password to do this step redis-cli-p 6380 shutdownredis-server / usr/local/redis/6380/conf/redis.conf &

2) build a database to verify and view, and the main operation

[root@localhost conf] # redis-cli-p 6379-a wsyht127.0.0.1:6379 > set name wsyhtOK127.0.0.1:6379 > get name "wsyht" 127.0.0.1wsyht127.0.0.1:6379 6379 > select 1OK127.0.0.1:6379 [1] > set name peterOK127.0.0.1:6379 [1] > info # check all information including synchronization 127.0.0.1 wsyht127.0.0.1:6379 6380 > info replication # View only his synchronization information

3) from viewing the library and status information, monitor monitoring is spelled every 10 seconds.

[root@localhost] # redis-cli-p 6380 127.0.0.1 PING 6380 > monitorOK1446980247.929617 [0 192.168.1.103 monitorOK1446980247.929617 6379] "PING" 1446980257.981266 [0 192.168.1.103 monitorOK1446980247.929617 6379] "PING" 1446980268.034426 [0 192.168.1.103 monitorOK1446980247.929617 6379] "PING" 1446980273.602672 [0192.168.1.103monitorOK1446980247.929617 6379] "SELECT" 0 "1446980273.602687 [0 192.168.1.103lane 6379]" set "name"wsyht" 1446980278.089068 [0 192.168.1.103 PING] "PING" 1446980288.140236 [0 192.168.1.103 SELECT] "SELECT"1" 1446980294.722721 [1 192.168.1.1036379] "set"name"peter" 1446980298.190898 [1 192.168.1.103] 6379] "PING" ^ C Localhost ~] # redis-cli-p 6380 127.0.0.1 localhost 6380 > get name # View the synchronized library "wsyht" 127.0.0.1 get name 6380 > info # View all information including synchronization 127.0.0.1 get name # View only his synchronization information

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report