如何编译安装redisd
这篇文章给大家分享的是有关如何编译安装redisd的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
安装方法:yum安装查看yum仓库redis版本
[root@centos~]#yumlistredisLoadedplugins:fastestmirror,langpacksLoadingmirrorspeedsfromcachedhostfileAvailablePackagesredis.x86_643.2.12-2.el7myepelyum安装
[root@centos ~]# yum install redis -y
启动服务并设为开机启动
[root@centos~]#systemctlenable--nowredisCreatedsymlinkfrom/etc/systemd/system/multi-user.target.wants/redis.serviceto/usr/lib/systemd/system/redis.service.
查看redis端口
[root@centos~]#ss-ntlStateRecv-QSend-QLocalAddress:PortPeerAddress:PortLISTEN0128127.0.0.1:631*:*LISTEN0100127.0.0.1:25*:*LISTEN0128127.0.0.1:6010*:*LISTEN0128*:54909*:*LISTEN0128127.0.0.1:6379*:*#这个是redis端口LISTEN0128*:111*:*LISTEN05192.168.122.1:53*:*
测试登录redis
[root@centos~]#redis-cli127.0.0.1:6379>info#Serverredis_version:3.2.12redis_git_sha1:00000000redis_git_dirty:0redis_build_id:7897e7d0e13773fredis_mode:standaloneos:Linux3.10.0-1062.el7.x86_64x86_64arch_bits:64multiplexing_api:epollgcc_version:4.8.5process_id:2914run_id:c75137717c54caa78bb05757d05c91471ef5817ftcp_port:6379uptime_in_seconds:175uptime_in_days:0hz:10lru_clock:4329484executable:/usr/bin/redis-serverconfig_file:/etc/redis.conf#Clientsconnected_clients:1client_longest_output_list:0client_biggest_input_buf:0blocked_clients:0
测试使用
127.0.0.1:6379>setkey1value1OK127.0.0.1:6379>getkey1"value1"
编译安装
下载当前最新release版本redis源码包:http://download.redis.io/releases/
编译安装命令
官方安装命令:https://redis.io/download
#源码包存放目录[root@centos~]#cd/usr/local/src/#下载源码包[root@centossrc]#wgethttp://download.redis.io/releases/redis-5.0.7.tar.gz--2020-02-1110:37:54--http://download.redis.io/releases/redis-5.0.7.tar.gzResolvingdownload.redis.io(download.redis.io)...109.74.203.151Connectingtodownload.redis.io(download.redis.io)|109.74.203.151|:80...connected.HTTPrequestsent,awaitingresponse...200OKLength:1984203(1.9M)[application/x-gzip]Savingto:‘redis-5.0.7.tar.gz'100%[===============================================>]1,984,2036.75KB/sin3m35s2020-02-1110:41:39(9.02KB/s)-‘redis-5.0.7.tar.gz'saved[1984203/1984203]#查看下载好的源码包[root@centossrc]#lltotal1940-rw-r--r--1rootroot1984203Nov2001:06redis-5.0.7.tar.gz
解压源码包
[root@centossrc]#tarxfredis-5.0.7.tar.gz[root@centossrc]#lltotal1940drwxrwxr-x6rootroot334Nov2001:05redis-5.0.7-rw-r--r--1rootroot1984203Nov2001:06redis-5.0.7.tar.gz
创建配置文件、日志、数据等目录
[root@centos~]#mkdir/apps/redis/{etc,logs,data,run}-p#查看目录结构[root@centos~]#tree/apps//apps/└──redis├──data├──etc├──logs└──run
进入redis目录编译安装
[root@centos~]#cd/usr/local/src/redis-5.0.7/[root@centosredis-5.0.7]#makePREFIX=/apps/redisinstallcdsrc&&makeinstallmake[1]:Enteringdirectory`/usr/local/src/redis-5.0.7/src'CCMakefile.depmake[1]:Leavingdirectory`/usr/local/src/redis-5.0.7/src'make[1]:Enteringdirectory`/usr/local/src/redis-5.0.7/src'CCadlist.o/bin/sh:cc:commandnotfoundmake[1]:***[adlist.o]Error127make[1]:Leavingdirectory`/usr/local/src/redis-5.0.7/src'make:***[install]Error2#出现以上报错是没有gcc编译器导致的#下载gcc编译器[root@centosredis-5.0.7]#yuminstallgcc#记得这里要把之前的redis目录删除重新解压[root@centossrc]#rm-rfredis-5.0.7[root@centossrc]#tarxfredis-5.0.7.tar.gz#重新进入目录进行编译[root@centossrc]#cdredis-5.0.7/[root@centosredis-5.0.7]#makePREFIX=/apps/redisinstall#指定安装目录cdsrc&&makeinstallmake[1]:Enteringdirectory`/usr/local/src/redis-5.0.7/src'CCMakefile.depmake[1]:Leavingdirectory`/usr/local/src/redis-5.0.7/src'make[1]:Enteringdirectory`/usr/local/src/redis-5.0.7/src'rm-rfredis-serverredis-sentinelredis-cliredis-benchmarkredis-check-rdbredis-check-aof*.o*.gcda*.gcno*.gcovredis.infolcov-htmlMakefile.depdict-benchmark(cd../deps&&makedistclean)make[2]:Enteringdirectory`/usr/local/src/redis-5.0.7/deps'(cdhiredis&&makeclean)>/dev/null||true(cdlinenoise&&makeclean)>/dev/null||true(cdlua&&makeclean)>/dev/null||true(cdjemalloc&&[-fMakefile]&&makedistclean)>/dev/null||true(rm-f.make-*)make[2]:Leavingdirectory`/usr/local/src/redis-5.0.7/deps'(rm-f.make-*)....(省略)Hint:It'sagoodideatorun'maketest';)INSTALLinstallINSTALLinstallINSTALLinstallINSTALLinstallINSTALLinstallmake[1]:Leavingdirectory`/usr/local/src/redis-5.0.7/src'#最后报这个就是编译完成
拷贝配置文件
[root@centosredis-5.0.7]#lltotal276-rw-rw-r--1rootroot115100Nov2001:0500-RELEASENOTES-rw-rw-r--1rootroot53Nov2001:05BUGS-rw-rw-r--1rootroot2381Nov2001:05CONTRIBUTING-rw-rw-r--1rootroot1487Nov2001:05COPYINGdrwxrwxr-x6rootroot192Feb1111:32deps-rw-rw-r--1rootroot11Nov2001:05INSTALL-rw-rw-r--1rootroot151Nov2001:05Makefile-rw-rw-r--1rootroot6888Nov2001:05MANIFESTO-rw-rw-r--1rootroot20555Nov2001:05README.md-rw-rw-r--1rootroot61797Nov2001:05redis.conf-rwxrwxr-x1rootroot275Nov2001:05runtest-rwxrwxr-x1rootroot280Nov2001:05runtest-cluster-rwxrwxr-x1rootroot373Nov2001:05runtest-moduleapi-rwxrwxr-x1rootroot281Nov2001:05runtest-sentinel-rw-rw-r--1rootroot9710Nov2001:05sentinel.confdrwxrwxr-x3rootroot8192Feb1111:33srcdrwxrwxr-x11rootroot182Nov2001:05testsdrwxrwxr-x8rootroot4096Nov2001:05utils[root@centosredis-5.0.7]#cpredis.conf/apps/redis/etc/
启动redis(这个启动方式)
[root@centosredis-5.0.7]#/apps/redis/bin/redis-server/apps/redis/etc/redis.conf8315:C11Feb202011:40:12.016#oO0OoO0OoO0OoRedisisstartingoO0OoO0OoO0Oo8315:C11Feb202011:40:12.016#Redisversion=5.0.7,bits=64,commit=00000000,modified=0,pid=8315,juststarted8315:C11Feb202011:40:12.016#Configurationloaded8315:M11Feb202011:40:12.017*Increasedmaximumnumberofopenfilesto10032(itwasoriginallysetto1024)._.__.-``__''-.__.-```.`_.''-._Redis5.0.7(00000000/0)64bit.-``.-```.```\/_.,_''-._(',.-`|`,)Runninginstandalonemode|`-._`-...-`__...-.``-._|'`_.-'|Port:6379|`-._`._/_.-'|PID:8315`-._`-._`-./_.-'_.-'|`-._`-._`-.__.-'_.-'_.-'||`-._`-.__.-'_.-'|http://redis.io`-._`-._`-.__.-'_.-'_.-'|`-._`-._`-.__.-'_.-'_.-'||`-._`-.__.-'_.-'|`-._`-._`-.__.-'_.-'_.-'`-._`-.__.-'_.-'`-.__.-'`-.__.-'8315:M11Feb202011:40:12.017#WARNING:TheTCPbacklogsettingof511cannotbeenforcedbecause/proc/sys/net/core/somaxconnissettothelowervalueof128.8315:M11Feb202011:40:12.017#Serverinitialized8315:M11Feb202011:40:12.017#WARNINGovercommit_memoryissetto0!Backgroundsavemayfailunderlowmemorycondition.Tofixthisissueadd'vm.overcommit_memory=1'to/etc/sysctl.confandthenrebootorrunthecommand'sysctlvm.overcommit_memory=1'forthistotakeeffect.8315:M11Feb202011:40:12.017#WARNINGyouhaveTransparentHugePages(THP)supportenabledinyourkernel.ThiswillcreatelatencyandmemoryusageissueswithRedis.Tofixthisissuerunthecommand'echonever>/sys/kernel/mm/transparent_hugepage/enabled'asroot,andaddittoyour/etc/rc.localinordertoretainthesettingafterareboot.RedismustberestartedafterTHPisdisabled.8315:M11Feb202011:40:12.018*Readytoacceptconnections
解决当前的警告提示
tcp-backlog
The backlog argument defines the maximum length to which the queue of pending connections for sockfdmay grow. If a connection request arrives when the queue is full, the client may receive an error with an indication of ECONNREFUSED or, if the underlying protocol supports retransmission, the request may be ignored so that a later reattempt at connection succeeds.
backlog参数控制的是三次握手的时候server端收到client ack确认号之后的队列值。
[root@centos~]#echo511>/proc/sys/net/core/somaxconnvm.overcommit_memory
0、表示内核将检查是否有足够的可用内存供应用进程使用;如果有足够的可用内存,内存申请允许;否则,内存申请失败,并把错误返回给应用进程。 1、表示内核允许分配所有的物理内存,而不管当前的内存状态如何。 2、表示内核允许分配超过所有物理内存和交换空间总和的内存
[root@centos~]#echo"vm.overcommit_memory=1">/etc/sysctl.conftransparenthugepage大页内存动态分配,需要关闭让redis负责内存管理。[root@centos~]#echonever>/sys/kernel/mm/transparent_hugepage/enabled
重启一下服务
#再次启动服务,警告信息没有了。[root@centos~]#/apps/redis/bin/redis-server/apps/redis/etc/redis.conf1847:C13Feb202012:03:59.281#oO0OoO0OoO0OoRedisisstartingoO0OoO0OoO0Oo1847:C13Feb202012:03:59.281#Redisversion=5.0.7,bits=64,commit=00000000,modified=0,pid=1847,juststarted1847:C13Feb202012:03:59.281#Configurationloaded1847:M13Feb202012:03:59.282*Increasedmaximumnumberofopenfilesto10032(itwasoriginallysetto1024)._.__.-``__''-.__.-```.`_.''-._Redis5.0.7(00000000/0)64bit.-``.-```.```\/_.,_''-._(',.-`|`,)Runninginstandalonemode|`-._`-...-`__...-.``-._|'`_.-'|Port:6379|`-._`._/_.-'|PID:1847`-._`-._`-./_.-'_.-'|`-._`-._`-.__.-'_.-'_.-'||`-._`-.__.-'_.-'|http://redis.io`-._`-._`-.__.-'_.-'_.-'|`-._`-._`-.__.-'_.-'_.-'||`-._`-.__.-'_.-'|`-._`-._`-.__.-'_.-'_.-'`-._`-.__.-'_.-'`-.__.-'`-.__.-'1847:M13Feb202012:03:59.282#Serverinitialized1847:M13Feb202012:03:59.282*DBloadedfromdisk:0.000seconds1847:M13Feb202012:03:59.282*Readytoacceptconnections
编辑redis服务启动脚本
[root@centos~]#cat/usr/lib/systemd/system/redis.service[Unit]Description=Redispersistentkey-valuedatabaseAfter=network.targetAfter=network-online.targetWants=network-online.target[Service]#ExecStart=/usr/bin/redis-server/etc/redis.conf--supervisedsystemdExecStart=/apps/redis/bin/redis-server/apps/redis/etc/redis.conf--supervisedsystemdExecReload=/bin/kill-sHUP$MAINPIDExecStop=/bin/kill-sQUIT$MAINPIDType=notifyUser=redisGroup=redisRuntimeDirectory=redisRuntimeDirectoryMode=0755[Install]WantedBy=multi-user.target
添加redis用户
#添加用户和组[root@centos~]#groupadd-g1001redis&&useradd-u1001-g1001redis-s/sbin/nologin#数据目录设置所有者所属组[root@centos~]#chownredis.redis-R/apps/redis/system启动测试#开启redis并设为开机启动[root@centos~]#systemctlenable--nowredisCreatedsymlinkfrom/etc/systemd/system/multi-user.target.wants/redis.serviceto/usr/lib/systemd/system/redis.service.#查看端口[root@centos~]#ss-tnlStateRecv-QSend-QLocalAddress:PortPeerAddress:PortLISTEN0128127.0.0.1:631*:*LISTEN0100127.0.0.1:25*:*LISTEN0128127.0.0.1:6010*:*LISTEN0128127.0.0.1:6011*:*LISTEN0128*:43108*:*LISTEN0511127.0.0.1:6379*:*#这个为redis端口LISTEN0128*:111*:*LISTEN05192.168.122.1:53*:*LISTEN0128*:22*:*LISTEN0128[::1]:631[::]:*LISTEN0100[::1]:25[::]:*LISTEN0128[::1]:6010[::]:*LISTEN0128[::1]:6011[::]:*LISTEN0128[::]:59279[::]:*LISTEN0128[::]:111[::]:*LISTEN0128[::]:22[::]:*
客户端连接redis测试
#这里还没有把这个命令加到PATH变量里[root@centos~]#/apps/redis/bin/redis-cli127.0.0.1:6379>info#Serverredis_version:5.0.7redis_git_sha1:00000000redis_git_dirty:0redis_build_id:b0887378c143d6e9redis_mode:standaloneos:Linux3.10.0-1062.el7.x86_64x86_64arch_bits:64multiplexing_api:epollatomicvar_api:atomic-builtingcc_version:4.8.5process_id:2088run_id:e0bbd2dc1561d1610565c6c8fb61aa817e30924ctcp_port:6379
创建命令软连接(也可以把这个路径加到PATH变量里面)
[root@centos~]#ln-sv/apps/redis/bin/redis-*/usr/bin/‘/usr/bin/redis-benchmark'->‘/apps/redis/bin/redis-benchmark'‘/usr/bin/redis-check-aof'->‘/apps/redis/bin/redis-check-aof'‘/usr/bin/redis-check-rdb'->‘/apps/redis/bin/redis-check-rdb'‘/usr/bin/redis-cli'->‘/apps/redis/bin/redis-cli'‘/usr/bin/redis-sentinel'->‘/apps/redis/bin/redis-sentinel'‘/usr/bin/redis-server'->‘/apps/redis/bin/redis-server'#命令连接测试[root@centos~]#redis-cli127.0.0.1:6379>info#Serverredis_version:5.0.7redis_git_sha1:00000000redis_git_dirty:0redis_build_id:b0887378c143d6e9redis_mode:standaloneos:Linux3.10.0-1062.el7.x86_64x86_64arch_bits:64multiplexing_api:epollatomicvar_api:atomic-builtingcc_version:4.8.5process_id:2088run_id:e0bbd2dc1561d1610565c6c8fb61aa817e30924ctcp_port:6379uptime_in_seconds:755uptime_in_days:0[root@centos~]#ll/apps/redis/bin/total32772-rwxr-xr-x1redisredis4366824Feb1111:33redis-benchmark#redis性能测试工具-rwxr-xr-x1redisredis8125216Feb1111:33redis-check-aof#AOF文件检查工具-rwxr-xr-x1redisredis8125216Feb1111:33redis-check-rdb#RDB文件检查工具-rwxr-xr-x1redisredis4807896Feb1111:33redis-cli#客户端工具lrwxrwxrwx1redisredis12Feb1111:33redis-sentinel->redis-server#哨兵软连接到server-rwxr-xr-x1redisredis8125216Feb1111:33redis-server#redis服务启动命令
感谢各位的阅读!关于“如何编译安装redisd”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。