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

Ubuntu Server 18.04 configure Redis stand-alone master-slave

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

[target]

Configure redis stand-alone master and slave, port 6378 connect master,6379 port connect slave,master read-write, slave read-only.

[installation and testing]

Installation

Sudo apt updatesudo apt install redis

Test (the following is normal)

Walker@Ubuntu:~$ redis-cli127.0.0.1:6379 > pingPONG

Use systemctl to manage redis

# View status $systemctl status redis# start redis$ systemctl start redis# restart redis$ systemctl restart redis# stop redis$ systemctl stop redis# add redis service to boot start $systemctl enable redis# disable boot start $systemctl disable redis

[configure stand-alone master-slave]

Create a directory and copy the configuration file

Mkdir-p / data/redis/ {6378 copyright Mastermind 6379 hands} / {conf,db,log} cp / etc/redis/redis.conf / data/redis/6378-master/conf/cp / etc/redis/redis.conf / data/redis/6379-slave/conf/

Edit the / data/redis/6378-master/conf/redis.conf file and modify or add the following

Daemonize yes pidfile / data/redis/6378-master/redis.pid bind 0.0.0.0port 6378 logfile / data/redis/6378-master/log/redis.logdir / data/redis/6378-master/db/

Edit the / data/redis/6379-slave/conf/redis.conf file and modify or add the following

Daemonize yes pidfile / data/redis/6379-slave/redis.pid bind 0.0.0.0port 6379 logfile / data/redis/6379-slave/log/redis.logdir / data/redis/6379-slave/db/ slaveof 127.0.0.1 6378

Turn off and disable the system redis

Sudo systemctl stop redissudo systemctl disable redis

Start the redis instance

Sudo redis-server / data/redis/6378-master/conf/redis.conf # launch mastersudo redis-server / data/redis/6379-slave/conf/redis.conf # launch slave

View the startup of the instance

# ps aux | grep redisroot 6069 0.0 0.1 50148 3952? Ssl 03:15 0:00 redis-server 0.0.0.0:6378root 6451 0.0 0.0 50148 3852? Ssl 03:27 0:00 redis-server 0.0.0.0:6379root 6457 0.0 13136 1084 pts/0 S + 03:28 0:00 grep-- color=auto redis

Close the instance

Redis-cli-h 127.0.0.1-p 6378 shutdown # turn off masterredis-cli-h 127.0.0.1-p 6379 shutdown # close slave

[persistence]

Persistence in rdb mode is enabled by default. (/ data/redis/6378-master/conf/redis.conf)

# save # save "" save 9001 # if there is one change in 900s, write the data snapshot in memory to disk save 30010 # if there are 10 changes in 300s, write the data snapshot in memory to disk save 60 10000 # if there are 10000 changes in 60 seconds, write the snapshot of data in memory to disk

Walker guessed that the implementation should be from small to large: set a timer to monitor, save 10000 changes in 60 seconds, 10 changes in 300 seconds, and 1 change in 900 seconds.

[maximum memory]

# maxmemory # 1Gmaxmemory 1073741824

[view version]

# redis-server-v Redis server vault 4.0.9 sha=00000000:0 malloc=jemalloc-3.6.0 bits=64 build=1bc80a08306a3efd

[view configuration]

$redis-cli-h 127.0.0.1-p 6378-a "mypass" 127.0.0.1 info

[configure Boot Boot]

Reference: ubuntu-18.04 settings boot startup script

Create a file: / etc/systemd/system/rc-local.service

Add the following to the rc-local.service

[Unit] Description=/etc/rc.local CompatibilityConditionPathExists=/etc/rc.localAfter= network.target[Service] Type=forkingExecStart=/etc/rc.local startTimeoutSec=0StandardOutput=ttyRemainAfterExit=yesSysVStartPriority= 99[Install] WantedBy=multi-user.target

Create a file: / etc/rc.local

Add the following to the rc.local

#! / bin/bashredis-server / data/redis/6378-master/conf/redis.confredis-server / data/redis/6379-slave/conf/redis.conf/home/walker/Python3Project/proxy_gather/start.shexit 0

Add executable permissions to rc.local

Sudo chmod 754 / etc/rc.local

Enable services (boot self-boot)

Sudo systemctl enable rc-local# is equivalent to ln-s / etc/systemd/system/rc-local.service / etc/systemd/system/multi-user.target.wants/

Start the service and check the status

Sudo systemctl start rc-local.servicesudo systemctl status rc-local.service

Restart the server to see if it can be booted.

* walker * *

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