第一,程序安装步骤:
1、打开redis官方下载页面:
2、按官方安装说明,安装redis:
cd /usr/local/src wget http://download.redis.io/releases/redis-3.0.6.tar.gz tar xzf redis-3.0.6.tar.gz ln -s redis-3.0.6 redis cd redis make prefix=/usr/local install
3、测试
$ src/redis-server $ src/redis-cli redis> set foo bar OK redis> get foo "bar"
第二,redis配置成服务步骤:
1.新增redis用户及组
groupadd redis useradd -c Redis Server -s /sbin/nologin -d /var/lib/redis -g redis -G root
reids参数解释:
-c 用户描述信息
-s 用户执行脚本,此处为安全考虑,redis用户是不允许远程登录,故使用/sbin/nologin
-d 用户home目录,此处无需在/home目录下创建redis子目录,故将其定位于/var/lib/redis空目录中
-G 扩展用户组,即表示此用户同时属于root用户组
2.将redis配置文件拷贝到/etc/redis/${REDISPORT}.conf
mkdir /etc/redis cp /usr/local/src/redis/redis.conf /etc/redis/6379.conf
这样,redis服务脚本指定的CONF就存在了。默认情况下,Redis未启用认证,可以通过开启6379.conf的requirepass 指定一个验证密码。
3.增加服务
进入/usr/lib/systemd/system目录,增加redis.service文件,并添加如下内容
cd /usr/lib/systemd/system vi redis.service [Unit] Description=Redis Server 3.0.6 After=network.target [Service] ExecStart=/usr/local/bin/redis-server /etc/redis/6379.conf --daemonize no ExecStop=/usr/local/bin/redis-cli -h 127.0.0.1 -p 6379 shutdown Group=redis [Install] WantedBy=multi-user.target
4.redis配置文件调整
daemonize yes pidfile /var/run/redis_6379.pid bind 192.168.100.30 127.0.0.1 appendonly yes dir /var/lib/redis/ logfile /var/log/redis/redis.log
5.启动redis服务
mkdir /var/lib/redis mkdir /var/log/redis systemctl start redis
6.设置开机redis服务自启动
systemctl enable redis
systemctl disable redis.service #关闭开机启动
第三,将Redis的命令所在目录添加到系统参数PATH中
修改profile文件:
vi /etc/profile
在最后行追加:
export PATH="$PATH:/usr/local/bin"
然后马上应用这个文件:
. /etc/profile
这样就可以直接调用redis-cli的命令了,如下所示:
$ redis-cli redis 127.0.0.1:6379> auth superman OK redis 127.0.0.1:6379> ping PONG redis 127.0.0.1:6379>
至此,redis 就成功安装了。
第四,redis启动警告错误解决
WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. echo 511 > /proc/sys/net/core/somaxconn WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect. echo 1 > /proc/sys/vm/overcommit_memory WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled. echo never > /sys/kernel/mm/transparent_hugepage/enabled
Win版:
把redis-server.exe安装成windows 服务。
redis-server.exe --service-install redis.windows.conf --loglevel verbose
在win服务管理器中启动
卸载可以使用
redis-server --service-uninstall
下载:https://files.cnblogs.com/files/xu360/redis_win.zip