redis编译安装

千金一刻莫空度,老大无成空自伤。这篇文章主要讲述redis编译安装相关的知识,希望能为你提供帮助。
????官网:??http://www.redis.cn/??
下载redis源码包:??http://download.redis.io/releases/??
?? http://download.redis.io/releases/redis-5.0.3.tar.gz??
?1.安装环境?

root@ubuntu:~# cat /etc/issue
Ubuntu 18.04.3 LTS \\n \\l

?2.编译安装?
root@ubuntu:/data# tar xf redis-5.0.3.tar.gz
root@ubuntu:/data# ls
lost+foundredis-5.0.3redis-5.0.3.tar.gz
root@ubuntu:/data# cd redis-5.0.3/

root@ubuntu:/data/redis-5.0.3# sudo apt-get update
root@ubuntu:/data/redis-5.0.3# apt-get install gcc
root@ubuntu:/data/redis-5.0.3# apt install make& & apt install make-guile
root@ubuntu:/data/redis-5.0.3# make CFLAGS="-march=x86-64" PREFIX=/usr/local/redis install
root@ubuntu:/data/redis-5.0.3# mkdir /usr/local/redis/etc/
root@ubuntu:/data/redis-5.0.3# cp /data/redis-5.0.3/redis.conf /usr/local/redis/etc/
root@ubuntu:/data/redis-5.0.3# ln -s/usr/local/redis/bin/redis-* /usr/bin/


启动
root@ubuntu:/data/redis-5.0.3# redis-server /usr/local/redis/etc/redis.conf


解决警告
#1.backlog参数控制的是三次握手的时候server端收到client ack确认号之后的队列值
vim /etc/sysctl.conf
-------------------------
net.core.somaxconn=512
-------------------------

#2.
0、表示内核将检查是否有足够的可用内存供应用进程使用;如果有足够的可用内存,内存申请允许;否则,内存申请失败,并把错误返回给应用进程。
1、表示内核允许,分配所有的物理内存,而不管当前的内存状态如何。
2、表示内核允许,分配超过所有物理内存和交换空间总和的内存
vim/etc/sysctl.conf
-------------------------
vm.overcommit_memory=1
-------------------------
sysctl -p

#3.开启大页内存动态分配,需要关闭让redis负责内存管理。
echo never > /sys/kernel/mm/transparent_hugepage/enabled #这种方式临时生效,
Ubuntu 18.04.3默认就是never,但是还是需要以root用户执行一次
[root @centos7_m_1908_3 redis]#cat /sys/kernel/mm/transparent_hugepage/enabled
always madvise [never]

#写到配置文件中,永久保存
vim /etc/rc.d/rc.local#ubuntu没有文件/etc/rc.d/rc.local文件,centos有
echo never > /sys/kernel/mm/transparent_hugepage/enabled
chmod +x /etc/rc.d/rc.local

??3.启动脚本??
vim/usr/lib/systemd/system/redis.service #centos
vim/etc/systemd/system/redis.service#ubuntu

[Unit]
Description=Redispersistentkey-valuedatabase
After=network.target
After=network-online.target
Wants=network-online.target
[Service]
#ExecStart=/usr/bin/redisserver/etc/redis.confsupervisedsystemd
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf --supervised systemd
ExecReload=/bin/kill-s HUP $MAINPID
ExecStop=/bin/kill-s QUIT $MAINPID
Type=notify
User=root
Group=root
RuntimeDirectory=redis
RuntimeDirectoryMode=0755
[Install]
WantedBy=multiuser.target

??4.创建目录及用户??
groupadd -g 1005 redis & & useradd -u 1005 -g 1005 redis -s/sbin/nologin
mkdir -pv /usr/local/redis/logs,data,run
chown redis.redis -R /usr/local/redis/


root@ubuntu:/data/redis-5.0.3# tree/usr/local/redis/
/usr/local/redis/
├──bin
│    ├──redis-benchmark#性能测试工具
│    ├──redis-check-aof#文件检查工具
│    ├──redis-check-rdb#文件检查工具
│    ├──redis-cli#客户端工具
│    ├──redis-sentinel-> redis-server#哨兵,连接到server
│    └──redis-server#服务端
├──data
├──etc
│    └──redis.conf
├──logs
└──run

root@ubuntu:/data/redis-5.0.3# systemctl start redis
root@ubuntu:/data/redis-5.0.3# ss -ntl
StateRecv-QSend-QLocal Address:PortPeer Address:Port
LISTEN0128127.0.0.53%lo:530.0.0.0:*
LISTEN01280.0.0.0:220.0.0.0:*
LISTEN0128127.0.0.1:60100.0.0.0:*
LISTEN0128127.0.0.1:60110.0.0.0:*
LISTEN0511127.0.0.1:63790.0.0.0:*
LISTEN0128[::]:22[::]:*
LISTEN0128[::1]:6010[::]:*
LISTEN0128[::1]:6011[::]:*
root@ubuntu:/data/redis-5.0.3# redis-cli
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379> info

登录
redis-cli#本机非密码连接
redis-cli -h HOSTNAME/IP -p PORT#跨主机非密码连接
redis-cli -h HOSTNAME/IP -p PORT -a PASSWORD#跨主机密码连接

?5.错误解决?
root@ubuntu:/data/redis-5.0.3# make PREFIX=/usr/local/redis install
cd src & & make install
make[1]: Entering directory /data/redis-5.0.3/src
CC adlist.o
In file included from adlist.c:34:0:
zmalloc.h:50:10: fatal error: jemalloc/jemalloc.h: No such file or directory
#include < jemalloc/jemalloc.h>
^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Makefile:248: recipe for target adlist.o failed
make[1]: *** [adlist.o] Error 1
make[1]: Leaving directory /data/redis-5.0.3/src
Makefile:9: recipe for target install failed
make: *** [install] Error 2

【redis编译安装】?解决办法?
make CFLAGS="-march=x86-64" PREFIX=/usr/local/redis install


    推荐阅读