redis主从部署,脚本
#/bin/bash
wget http://download.redis.io/releases/redis-3.0.7.tar.gz
wget http://downloads.sourceforge.net/tcl/tcl8.6.4-src.tar.gz
tar xzf redis-3.0.7.tar.gz >/dev/null 2>&1
mv redis-3.0.7 /usr/local/redis
yum install gcc* -y
cd /usr/local/redis
make >/dev/null 2>&1
cd /root
tar zxvf tcl8.6.4-src.tar.gz >/dev/null 2>&1
cd tcl8.6.4
cd unix
./configure --prefix=/usr --mandir=/usr/share/man --without-tzdata&&make >/dev/null 2>&1
sed -e "s@^\(TCL_SRC_DIR='\).*@\1/usr/include'@" -e "/TCL_B/s@='\(-L\)\?.*unix@='\1/usr/lib@" -i tclConfig.sh
make install >/dev/null 2>&1
make install-private-headers &&ln -v -sf tclsh /usr/bin/tclsh &&chmod -v 755 /usr/lib/libtcl8.6.so >/dev/null 2>&1
cd /usr/local/redis/src
make test >/dev/null 2>&1
make install
make MALLOC=libc >/dev/null 2>&1
#创建bin etc
mkdir -p /usr/local/redis/bin /usr/local/redis/etc
mv /usr/local/redis/redis.conf /usr/local/redis/etc/
mv mkreleasehdr.sh redis-benchmark redis-check-aof redis-check-dump redis-cli redis-sentinel redis-server redis-trib.rb /usr/local/redis/bin/
#后台启动
sed -i 42s/no/yes/g /usr/local/redis/etc/redis.conf
./usr/local/redis/utils/install_server.sh
cp /root/redisd /etc/init.d/redisd
chmod +x /etc/init.d/redisd&&chkconfig --add redisd&&chkconfig --level 345 redisd on&&chkconfig --list redisd
mkdir /usr/local/redis/data
sed -i -e 's#^dir ./#dir /usr/local/redis/data#g' /usr/local/redis/etc/redis.conf
sed -i -e 's#^appendonly no#appendonly yes#g' /usr/local/redis/etc/redis.conf
service redisd start
netstat -antup |grep 6379
测试
/usr/local/redis/bin/redis-cli
set hh ee
get hh
"ee"
service redis stop
mkdir /home/redis/
mv /usr/local/redis/* /home/redis/
ln -s /home/redis/* /usr/local/redis/
主从配置
从服务器redis.conf的
210行下面添加
# slaveof <masterip> <masterport>
slaveof 192.168.1.30 6379 (主服务器的地址和端口号)
主从复制测试:
主:
[root@redis-1 bin]# redis-cli -h 192.168.1.30
192.168.1.30:6379> set test master
OK
192.168.1.30:6379> get test
"master"
从:
root@redis-2 bin]# redis-cli -h 192.168.1.31
192.168.1.31:6379> get test
"master"
192.168.1.31:6379>
- 点赞
- 收藏
- 关注作者
评论(0)