如何通过源码安装redis

43次阅读
没有评论

共计 4132 个字符,预计需要花费 11 分钟才能阅读完成。

这篇文章给大家分享的是有关如何通过源码安装 redis-3.0.5 的内容。丸趣 TV 小编觉得挺实用的,因此分享给大家做个参考,一起跟随丸趣 TV 小编过来看看吧。

##### 安装 redis-server #####

# 创建运行用户

useradd redis -s /sbin/nologin -M

# 上传软件到指定位置,我的软件保存位置为

mkdir -p /server/tools/

# 解压,配置,编译,安装

cd /server/tools/
tar -zxf redis-3.0.5.tar.gz 
cd redis-3.0.5
make PREFIX=/usr/local/redis
make PREFIX=/usr/local/redis install

# 配置 redis 环境变量

echo       /etc/profile 
echo  PATH for redis-server    /etc/profile 
echo  export PATH=/usr/local/redis/bin/:$PATH    /etc/profile 
tail -3 /etc/profile
source /etc/profile
echo $PATH

# 或者 (重启失效)

export PATH=/usr/local/redis/bin/:$PATH
echo $PATH

# 创建配置文件,数据,日志等相关目录,并拷贝配置文件

# 创建规范的目录结构有助于行成良好习惯,提高效率

mkdir -p /usr/local/redis/conf
mkdir -p /usr/local/redis/data
mkdir -p /usr/local/redis/logs
cp redis.conf /usr/local/redis/conf/
cd /usr/local/redis/conf/
tree /usr/local/redis

# 到此 redis 基本配置便已完成,可以使用 redis 初始配置进行启动

# 启动命令

/usr/local/redis/bin/redis-server /usr/local/redis/conf/redis.conf 

# 查看启动状态,进程和端口

ps -ef |grep redis
netstat -anptl |grep redis

# 测试及使用

# 客户端连接命令为:

/usr/local/redis/bin/redis-cli -p 6379
[root@cache redis]# redis-cli -p 6379
127.0.0.1:6379  set a 1
127.0.0.1:6379  get a 
127.0.0.1:6379  set b 2
127.0.0.1:6379  set c 3
127.0.0.1:6379  keys *
1)  c 
2)  a 
3)  b 
127.0.0.1:6379  exit

# 以上为简单测试,验证安装正确与否

# 安全关闭 redis

/usr/local/redis/bin/redis-cli shutdown

#  关闭 redis 时,数据默认会保存在启动 redis 时候所在的位置, 保存为 dump.rdb

——– 简单优化 redis ——— 

# 以默认配置启动 redis-server 会出现以下警告信息:不影响使用,

# 不过以笔者的习惯自然不会容忍此等警告信息的存在:

[root@cache redis]# redis-server /usr/local/redis/conf/redis.conf  
[1] 4570
[root@cache redis]# [4570] 07 Dec 03:54:50.938 * Increased maximum number of open files to 10032 (it was originally set to 1024).
 _._ 
 _.-``__  -._ 
 _.-`` `. `_.  -._ Redis 3.0.5 (00000000/0) 64 bit
 .-`` .-```. ```\/ _.,_  -._ 
 (   , .-` | `, ) Running in stand alone mode
 |`-._`-...-` __...-.``-._| ` _.- | Port: 6379
 | `-._ `._ / _.-  | PID: 4570
 `-._ `-._ `-./ _.-  _.-  
 |`-._`-._ `-.__.-  _.- _.- | 
 | `-._`-._ _.- _.-  | http://redis.io 
 `-._ `-._`-.__.- _.-  _.-  
 |`-._`-._ `-.__.-  _.- _.- | 
 | `-._`-._ _.- _.-  | 
 `-._ `-._`-.__.- _.-  _.-  
 `-._ `-.__.-  _.-  
 `-._ _.-  
 `-.__.-  
[4570] 07 Dec 03:54:50.939 # Server started, Redis version 3.0.5
[4570] 07 Dec 03:54:50.939 # 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.
[4570] 07 Dec 03:54:50.939 # 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.
[4570] 07 Dec 03:54:50.939 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
[4570] 07 Dec 03:54:50.939 * The server is now ready to accept connections on port 6379

# 根据启动日志提示需要优化一些内核的参数,按提示操作:

echo never   /sys/kernel/mm/transparent_hugepage/enabled
cat /sys/kernel/mm/transparent_hugepage/enabled
echo 511   /proc/sys/net/core/somaxconn
cat /proc/sys/net/core/somaxconn
echo  vm.overcommit_memory = 1   /etc/sysctl.conf
sysctl -p

# 以上操作重启失效,可以按下操作配置下次开机生效,顺便设置 redis 开机自启动

echo       /etc/rc.local
echo  # redis-server by zs in $(date +%F)    /etc/rc.local
echo  echo never   /sys/kernel/mm/transparent_hugepage/enabled    /etc/rc.local
echo  echo 511   /proc/sys/net/core/somaxconn   /etc/rc.local
echo  /usr/local/redis/bin/redis-server /usr/local/redis/conf/redis.conf    /etc/rc.local
tail -5 /etc/rc.local

# 继续优化配置文件

vim /usr/local/redis/conf/redis.conf

# 在配置文件中寻找以下关键字,可以按照以下内容修改:

daemonize yes #  是否后台运行,yes 为后台运行
pidfile /usr/local/redis/logs/redis.pid # redis 的 pid 文件保存位置
port 6379 # redis 监控端口
bind 0.0.0.0 # redis 监控的 IP
timeout 0 #  客户端连接关闭时服务端保持连接的时长,超时
 # 0 为不断开连接,等待客户端再次连接
logfile  /usr/local/redis/logs/redis.log  #  日志文件保存位置
dbfilename redis.rdb # redis 数据文件名
dir /usr/local/redis/data/ # redis 数据保存位置
appendonly yes #  是否写日志,类似于 mysql 的 bin-log

以上为简单的 redis 优化配置

感谢各位的阅读!关于“如何通过源码安装 redis-3.0.5”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-07-20发表,共计4132字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)