扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
【安装redis单实例实战】
目前创新互联公司已为近1000家的企业提供了网站建设、域名、虚拟主机、网站托管、服务器托管、企业网站设计、定南网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。
yum -y install gcc gcc-c++ #安装编译工具 cd /opt wget -c http://download.redis.io/releases/redis-3.0.5.tar.gz #下载包 tar xf redis-3.0.5.tar.gz #解压 cd redis-3.0.5 make MALLOC=libc #编译 make PREFIX=/usr/local/redis install #安装 echo 'PATH=/usr/local/redis/bin:$PATH' >> /etc/profile #配置环境变量 source /etc/profile #或 . /etc/profile mkdir /usr/local/redis/conf #创建目录 cp /opt/redis-3.0.5/redis.conf /usr/local/redis/conf/ #拷贝配置文件 sed -i "46s#/var/run/redis.pid#/usr/local/redis/conf/redis.pid#" /usr/local/redis/conf/redis.conf sed -i "192s#./#/usr/local/redis/conf/#" /usr/local/redis/conf/redis.conf sed -i 509s/no/yes/ /usr/local/redis/conf/redis.conf nohup redis-server /usr/local/redis/conf/redis.conf &> /dev/null & echo vm.overcommit_memory = 1 >> /etc/sysctl.conf sysctl -p lsof -i:6379 #查看端口有没有起来 #redis-cli shutdown
【redis多实例实战】
mkdir -p /usr/local/redis/6380/conf cp /usr/local/redis/conf/redis.conf /usr/local/redis/6380/conf/ sed -i 50s/6379/6380/ /usr/local/redis/6380/conf/redis.conf sed -i "46s#/var/run/redis.pid#/usr/local/redis/6380/conf/redis.pid#" /usr/local/redis/6380/conf/redis.conf sed -i "192s#./#/usr/local/redis/6380/conf/#" /usr/local/redis/6380/conf/redis.conf sed -i 509s/no/yes/ /usr/local/redis/6380/conf/redis.conf redis-server /usr/local/redis/6380/conf/redis.conf & mkdir -p /usr/local/redis/6381/conf cp /usr/local/redis/conf/redis.conf /usr/local/redis/6381/conf/ sed -i 50s/6379/6381/ /usr/local/redis/6381/conf/redis.conf sed -i "46s#/var/run/redis.pid#/usr/local/redis/6381/conf/redis.pid#" /usr/local/redis/6381/conf/redis.conf sed -i "192s#./#/usr/local/redis/6381/conf/#" /usr/local/redis/6381/conf/redis.conf #更改rdb文件存放目录 sed -i 509s/no/yes/ /usr/local/redis/6381/conf/redis.conf #开启aof日志文件 redis-server /usr/local/redis/6380/conf/redis.conf & # redis-cli -p 6381 > set a b > save > quit # ls /usr/local/redis/6381/conf #查看生成的dump.rdb文件 # redis-cli -p 6381 shutdown #关闭服务
【主从同步实战】(主跟从可以在相同服务器,同服务器的时候必须至少要有两个实例)
主:6379 从:6380 -》同一台服务器,不同实例
1)从修改配置文件
sed -i "210a slaveof 192.168.1.103 6379" /usr/local/redis/6380/conf/redis.conf #此处不写主的IP写主的域名也可以 sed -i "217a masterauth wsyht" /usr/local/redis/6380/conf/redis.conf #master没密码可以不做这一步 redis-cli -p 6380 shutdown redis-server /usr/local/redis/6380/conf/redis.conf &
2)建库验证查看,主操作
[root@localhost conf]# redis-cli -p 6379 -a wsyht 127.0.0.1:6379> set name wsyht OK 127.0.0.1:6379> get name "wsyht" 127.0.0.1:6379> select 1 OK 127.0.0.1:6379[1]> set name peter OK 127.0.0.1:6379[1]>info #查看所有信息包括同步 127.0.0.1:6380>info replication #只查看他的同步信息
3)从查看库和状态信息,monitor监控每十秒拼一次
[root@localhost ~]# redis-cli -p 6380 127.0.0.1:6380> monitor OK 1446980247.929617 [0 192.168.1.103:6379] "PING" 1446980257.981266 [0 192.168.1.103:6379] "PING" 1446980268.034426 [0 192.168.1.103:6379] "PING" 1446980273.602672 [0 192.168.1.103:6379] "SELECT" "0" 1446980273.602687 [0 192.168.1.103:6379] "set" "name" "wsyht" 1446980278.089068 [0 192.168.1.103:6379] "PING" 1446980288.140236 [0 192.168.1.103:6379] "PING" 1446980294.722701 [0 192.168.1.103:6379] "SELECT" "1" 1446980294.722721 [1 192.168.1.103:6379] "set" "name" "peter" 1446980298.190898 [1 192.168.1.103:6379] "PING" ^C [root@localhost ~]# redis-cli -p 6380 127.0.0.1:6380> get name #查看同步过来的库 "wsyht" 127.0.0.1:6380>info #查看所有信息包括同步 127.0.0.1:6380>info replication #只查看他的同步信息
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流