linux环境(centos 7.2)下redis5.0.5安装
1.安装 gcc
yum install -y gcc
2.下载redis5.0.5
wget http://download.redis.io/releases/redis-5.0.5.tar.gz
3.解压缩
tar -xzvf redis-5.0.5.tar.gz
4.编译redis源码
cd /root/soft/redis-5.0.5
make
注: 这里执行make, 需要安装gcc, 未安装导致编译失败,可以先执行下make disclean ,再重新执行make进行编译.可参考redis中的说明readme.md
编译结果如下
... CC siphash.o CC rax.o CC t_stream.o CC listpack.o CC localtime.o CC lolwut.o CC lolwut5.o LINK redis-server INSTALL redis-sentinel CC redis-cli.o LINK redis-cli CC redis-benchmark.o LINK redis-benchmark INSTALL redis-check-rdb INSTALL redis-check-aof Hint: It's a good idea to run 'make test' ;) make[1]: Leaving directory `/root/soft/redis-5.0.5/src'
5.安装redis服务
mkdir -p /opt/myprogram/redis5.0.5 cd /root/soft/redis-5.0.5 make install PREFIX=/opt/myprogram/redis5.0.5
执行结果
[root@VM-0-7-centos redis-5.0.5]# make install PREFIX=/opt/myprogram/redis5.0.5 cd src && make install make[1]: Entering directory `/root/soft/redis-5.0.5/src' CC Makefile.dep make[1]: Leaving directory `/root/soft/redis-5.0.5/src' make[1]: Entering directory `/root/soft/redis-5.0.5/src' Hint: It's a good idea to run 'make test' ;) INSTALL install INSTALL install INSTALL install INSTALL install INSTALL install make[1]: Leaving directory `/root/soft/redis-5.0.5/src'
6.修改环境变量
vi /etc/profile
修改内容
export REDIS_HOME=/opt/myprogram/redis5.0.5 export PATH=$PATH:$REDIS_HOME/bin
生效配置
source /etc/profile
7. 安装redis实例
cd /root/soft/redis-5.0.5/utils ./install_server.sh
操作过程中取默认值, 按回车键
[root@VM-0-7-centos utils]# ./install_server.sh Welcome to the redis service installer This script will help you easily set up a running redis server Please select the redis port for this instance: [6379] Selecting default: 6379 Please select the redis config file name [/etc/redis/6379.conf] Selected default - /etc/redis/6379.conf Please select the redis log file name [/var/log/redis_6379.log] Selected default - /var/log/redis_6379.log Please select the data directory for this instance [/var/lib/redis/6379] Selected default - /var/lib/redis/6379 Please select the redis executable path [/opt/myprogram/redis5.0.5/bin/redis-server] Selected config: Port : 6379 Config file : /etc/redis/6379.conf Log file : /var/log/redis_6379.log Data dir : /var/lib/redis/6379 Executable : /opt/myprogram/redis5.0.5/bin/redis-server Cli Executable : /opt/myprogram/redis5.0.5/bin/redis-cli Is this ok? Then press ENTER to go on or Ctrl-C to abort. Copied /tmp/6379.conf => /etc/init.d/redis_6379 Installing service... Successfully added to chkconfig! Successfully added to runlevels 345! Starting Redis server... Installation successful! [root@VM-0-7-centos utils]#
8. 测试
[root@VM-0-7-centos utils]# redis-cli 127.0.0.1:6379> GET A (nil) 127.0.0.1:6379> set a "1" OK 127.0.0.1:6379> get a "1"
9.增加访问密码
[root@VM-0-7-centos bin]# vi /etc/redis/6379.conf ################################## NETWORK ##################################### # By default, if no "bind" configuration directive is specified, Redis listens # for connections from all the network interfaces available on the server. # It is possible to listen to just one or multiple selected interfaces using # the "bind" configuration directive, followed by one or more IP addresses. # # Examples: # # bind 192.168.1.100 10.0.0.1 # bind 127.0.0.1 ::1 # # ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the # internet, binding to all the interfaces is dangerous and will expose the # instance to everybody on the internet. So by default we uncomment the # following bind directive, that will force Redis to listen only into # the IPv4 loopback interface address (this means Redis will be able to # accept connections only from clients running into the same computer it # is running). # # IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES # JUST COMMENT THE FOLLOWING LINE. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #bind 127.0.0.1 ################################## SECURITY ################################### # Require clients to issue AUTH <PASSWORD> before processing any other # commands. This might be useful in environments in which you do not trust # others with access to the host running redis-server. # # This should stay commented out for backward compatibility and because most # people do not need auth (e.g. they run their own servers). # # Warning: since Redis is pretty fast an outside user can try up to # 150k passwords per second against a good box. This means that you should # use a very strong password otherwise it will be very easy to break. # requirepass 123456
[root@VM-0-7-centos bin]# service redis_6379 restart
9.重启服务
[root@VM-0-7-centos utils]# redis-cli -a 123456 Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. 127.0.0.1:6379> SHUTDOWN not connected> exit [root@VM-0-7-centos utils]# service redis_6379 status cat: /var/run/redis_6379.pid: No such file or directory Redis is running () [root@VM-0-7-centos utils]# service redis_6379 start Starting Redis server... [root@VM-0-7-centos utils]# service redis_6379 staus Please use start, stop, restart or status as first argument [root@VM-0-7-centos utils]# service redis_6379 status Redis is running (12065) [root@VM-0-7-centos utils]# redis-cli 127.0.0.1:6379> get a (error) NOAUTH Authentication required. 127.0.0.1:6379> auth 123456 OK 127.0.0.1:6379> get a "1"