CentOS 6.7 builds Redis master-slave Service

Source: Internet
Author: User

Environment deployment:

Redis Master (ZKDB1): 192.168.16.210

Redis slave:192.168.16.211

Installation deployment:

#创建一个软件安装目录

[Email protected] ~]# Mkdir/home/softwares
[Email protected] ~]# cd/home/softwares/

#下载软件包, simultaneous decompression and installation
[Email protected] softwares]# wget http://download.redis.io/releases/redis-3.0.7.tar.gz
[Email protected] softwares]# TAR-XVF redis-3.0.7.tar.gz-c/usr/local/
[Email protected] redis7]# cd/usr/local/redis-3.0.7/
[[email protected] redis7]# make PREFIX=/USR/LOCAL/REDIS7 Install

[[email protected] REDIS7] #mkdir configuration file directory for the/opt/redis307 #创建一个redis

[Email protected] redis7]# cd/opt/redis307
[Email protected] redis7]# cp/usr/local/redis-3.0.7/redis.conf/opt/redis307/
[[email protected] redis7]#./bin/redis-server/opt/redis307/redis.conf # #启动redis Services
2. Kernel and other adjustments
Add the following two lines

#/etc/sysctl.conf

Net.core.somaxconn =8192
Vm.overcommit_memory=1

#将下面三行写入到redis配置文件中
[[email protected] redis7] #echo ' rename-command flushall ' "' >> redis.conf
[[email protected] redis7] #echo ' rename-command flushdb ' "' >> redis.conf
[[email protected] redis7] #echo ' rename-command KEYS ' "' >> redis.conf

Configuration file
Vim/opt/redis307/redis.conf
Port 6000 # #更改端口
Save 900 1
Save 300 10000 # # Change Configuration
Save 60 200000
Dbfilename Dump.rdb
Slave-read-only Yes # #更改为yes
Dir/opt/redis307/dbdata # # Redis data store directory, but the directory needs to be created manually
AppendOnly Yes
MaxClients 30000
Appendfsync everysec
Appendfilename "Appendonly.aof"
LogFile "/tmp/redis307.log"
Timeout 0

# #启动redis Service

[Email protected] redis7]#/usr/local/redis7/bin/redis-server/opt/redis307/redis.conf >/dev/null 2>&1 &

[[email protected] redis307]# Vim/etc/init.d/redis # #编写redis configuration script
#!/bin/bash
#chkconfig: 345 86 14
#description: Startup and shutdown script for Redis

cli= "/usr/local/redis7/bin/redis-cli-p 6000"
pro= "/usr/local/redis7/bin/redis-server"
Config= "/opt/redis307/redis.conf"
Scriptname= "/etc/rc.d/init.d/redis"


Status ()
{
ping= ' $CLI ping ' >/dev/null
If [-Z $ping]
Then ping= ' 0 '
Fi
}


Start ()
{
Status
if [$ping = = ' PONG ']
Then
Echo-e "Redis already started"
Else
$PRO $CONFIG >/dev/null 2>&1 &
Echo-e "Start Redis OK"
Fi
}

Stop ()
{
Status
if [$ping = = ' PONG ']
Then
$CLI Save >/dev/null
echo "Save OK"
$CLI bgrewriteaof >/dev/null
echo "AoF rewrite OK"
$CLI Shutdown >/dev/null
echo "Redis shutdown OK"
Else
Echo-e "Redis already stoped"
Fi
}

Restart ()
{
Stop
Start
}

Save_aof ()
{
$CLI bgrewriteaof
}

Case $ in
Start
Start
;;
Stop
Stop
;;
Restart
Restart
;;
SAVE_AOF)
Save_aof
;;

*)
echo "Usage: $SCRIPTNAME {start|stop|restart|save_aof}" >&2
Exit 1
;;
Esac
Exit 0

[Email protected] redis307]# chmod +x/etc/init.d/redis
[Email protected] redis307]#/etc/init.d/redis restart
Save OK
AoF rewrite OK
Redis shutdown OK

[Email protected] redis307]# vim/etc/rc.d/rc.local
/etc/init.d/redis start

###########################################

The Redis configuration is as follows:

######################################################
IP 192.168.16.211 zkdb2
[Email protected] ~]# Mkdir/home/softwares
[Email protected] ~]# cd/home/softwares/
[Email protected] softwares]# wget http://download.redis.io/releases/redis-3.0.7.tar.gz
[Email protected] softwares]# TAR-XVF redis-3.0.7.tar.gz-c/usr/local/
[Email protected] redis7]# cd/usr/local/redis-3.0.7/
[[email protected] redis7]# make PREFIX=/USR/LOCAL/REDIS7 Install

[Email protected] redis7]# mkdir/opt/redis307
[Email protected] redis7]# cd/opt/redis307
[Email protected] redis7]# cp/usr/local/redis-3.0.7/redis.conf/opt/redis307/
[Email protected] redis7]#./bin/redis-server/opt/redis307/redis.conf
5 Kernels and other tweaks
Add to

[Email protected] redis-3.0.7]# vi/etc/sysctl.conf
Net.core.somaxconn =8192
Vm.overcommit_memory=1


Echo ' Rename-command flushall ' >> redis.conf
Echo ' Rename-command flushdb ' >> redis.conf
Echo ' Rename-command KEYS ' ' >> redis.conf

Configuration file

Vim/opt/redis307/redis.conf
#更改端口
Port 6000
Change numbers
Save 900 1
Save 300 10000
Save 60 200000
Dbfilename Dump.rdb
Slave-read-only Yes
# # #添加
Dir/opt/redis307/dbdata
# # Change Yes
AppendOnly Yes
# # Change the numbers
MaxClients 30000
Appendfsync everysec
Appendfilename "Appendonly.aof"
LogFile "/tmp/redis307.log"
Timeout 0
slaveof 192.168.16.210 6000 # # from the IP that joins this line of the master

/usr/local/redis7/bin/redis-server/opt/redis307/redis.conf >/dev/null 2>&1 &

[Email protected] redis307]# Vim/etc/init.d/redis
#!/bin/bash
#chkconfig: 345 86 14
#description: Startup and shutdown script for Redis

cli= "/usr/local/redis7/bin/redis-cli-p 6000"
pro= "/usr/local/redis7/bin/redis-server"
Config= "/opt/redis307/redis.conf"
Scriptname= "/etc/rc.d/init.d/redis"


Status ()
{
ping= ' $CLI ping ' >/dev/null
If [-Z $ping]
Then ping= ' 0 '
Fi
}


Start ()
{
Status
if [$ping = = ' PONG ']
Then
Echo-e "Redis already started"
Else
$PRO $CONFIG >/dev/null 2>&1 &
Echo-e "Start Redis OK"
Fi
}

Stop ()
{
Status
if [$ping = = ' PONG ']
Then
$CLI Save >/dev/null
echo "Save OK"
$CLI bgrewriteaof >/dev/null
echo "AoF rewrite OK"
$CLI Shutdown >/dev/null
echo "Redis shutdown OK"
Else
Echo-e "Redis already stoped"
Fi
}

Restart ()
{
Stop
Start
}

Save_aof ()
{
$CLI bgrewriteaof
}

Case $ in
Start
Start
;;
Stop
Stop
;;
Restart
Restart
;;
SAVE_AOF)
Save_aof
;;

*)
echo "Usage: $SCRIPTNAME {start|stop|restart|save_aof}" >&2
Exit 1
;;
Esac
Exit 0

[Email protected] redis307]# chmod +x/etc/init.d/redis
[Email protected] redis307]#/etc/init.d/redis restart
Save OK
AoF rewrite OK
Redis shutdown OK

[Email protected] redis307]# vim/etc/rc.d/rc.local
/etc/init.d/redis start

You need to fill in two Redis configuration files

Vim/etc/profile

Export Path=/usr/local/redis7/bin: $PATH

Source/etc/profile
Verify:
Main
REDIS-CLI-P 6000
Create a Set key Valus (Create a key followed by a value)
Get key
From
REDIS-CLI-P 6000
Get the file


This article from "Ignorance is better than nothing" blog, please be sure to keep this source http://19930412.blog.51cto.com/6974556/1762623

CentOS 6.7 builds Redis master-slave Service

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.