十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
这期内容当中小编将会给大家带来有关Linux系统如何安装redis服务,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
创新互联长期为上1000家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为万安企业提供专业的网站设计、成都网站制作,万安网站改版等技术服务。拥有十年丰富建站经验和众多成功案例,为您定制开发。
准备工作:将包括redis在内的redis-3.2.8.tar.gz安装包放到指定位置(此位置可以自建,为了统一,全部放在/var/software/目录下)
(1)解压redis安装包:
[root@caiji software]# tar -xvf redis-3.2.8.tar.gz ...... ......
进入解压后的文件中:
[root@caiji software]# cd redis-3.2.8 [root@caiji redis-3.2.8]# ls 00-RELEASENOTES COPYING Makefile redis.conf runtest-sentinel tests BUGS deps MANIFESTO runtest sentinel.conf utils CONTRIBUTING INSTALL README.md runtest-cluster src
使用yum命令安装redis所需要的包和编译工具:
[root@caiji software]# yum -y install wget make gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel kernel keyutils patch perl
(以下为输出内容,如果有的包已经安装过的话,输出内容会有所差别,大体是一样的!)
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Setting up Install Process Package wget-1.12-1.8.el6.x86_64 already installed and latest version Package 1:make-3.81-20.el6.x86_64 already installed and latest version Package openssl-1.0.1e-15.el6.x86_64 already installed and latest version Package kernel-2.6.32-431.el6.x86_64 already installed and latest version Package keyutils-1.4-4.el6.x86_64 already installed and latest version Package patch-2.6-6.el6.x86_64 already installed and latest version Package 4:perl-5.10.1-136.el6.x86_64 already installed and latest version Resolving Dependencies --> Running transaction check ---> Package gcc.x86_64 0:4.4.7-4.el6 will be installed --> Processing Dependency: cpp = 4.4.7-4.el6 for package: gcc-4.4.7-4.el6.x86_64 --> Processing Dependency: cloog-ppl >= 0.15 for package: gcc-4.4.7-4.el6.x86_64 ---> Package gcc-c++.x86_64 0:4.4.7-4.el6 will be installed --> Processing Dependency: libstdc++-devel = 4.4.7-4.el6 for package: gcc-c++-4.4.7-4.el6.x86_64 --> Processing Dependency: libmpfr.so.1()(64bit) for package: gcc-c++-4.4.7-4.el6.x86_64 ---> Package openssl-devel.x86_64 0:1.0.1e-15.el6 will be installed --> Processing Dependency: krb5-devel for package: openssl-devel-1.0.1e-15.el6.x86_64 ---> Package pcre-devel.x86_64 0:7.8-6.el6 will be installed ---> Package zlib-devel.x86_64 0:1.2.3-29.el6 will be installed --> Running transaction check ---> Package cloog-ppl.x86_64 0:0.15.7-1.2.el6 will be installed --> Processing Dependency: libppl_c.so.2()(64bit) for package: cloog-ppl-0.15.7-1.2.el6.x86_64 --> Processing Dependency: libppl.so.7()(64bit) for package: cloog-ppl-0.15.7-1.2.el6.x86_64 ---> Package cpp.x86_64 0:4.4.7-4.el6 will be installed ---> Package krb5-devel.x86_64 0:1.10.3-10.el6_4.6 will be installed --> Processing Dependency: libselinux-devel for package: krb5-devel-1.10.3-10.el6_4.6.x86_64 --> Processing Dependency: libcom_err-devel for package: krb5-devel-1.10.3-10.el6_4.6.x86_64 --> Processing Dependency: keyutils-libs-devel for package: krb5-devel-1.10.3-10.el6_4.6.x86_64 ---> Package libstdc++-devel.x86_64 0:4.4.7-4.el6 will be installed ---> Package mpfr.x86_64 0:2.4.1-6.el6 will be installed --> Running transaction check ---> Package keyutils-libs-devel.x86_64 0:1.4-4.el6 will be installed ---> Package libcom_err-devel.x86_64 0:1.41.12-18.el6 will be installed ---> Package libselinux-devel.x86_64 0:2.0.94-5.3.el6_4.1 will be installed --> Processing Dependency: libsepol-devel >= 2.0.32-1 for package: libselinux-devel-2.0.94-5.3.el6_4.1.x86_64 --> Processing Dependency: pkgconfig(libsepol) for package: libselinux-devel-2.0.94-5.3.el6_4.1.x86_64 ---> Package ppl.x86_64 0:0.10.2-11.el6 will be installed --> Running transaction check ---> Package libsepol-devel.x86_64 0:2.0.41-4.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: gcc x86_64 4.4.7-4.el6 local 10 M gcc-c++ x86_64 4.4.7-4.el6 local 4.7 M openssl-devel x86_64 1.0.1e-15.el6 local 1.2 M pcre-devel x86_64 7.8-6.el6 local 318 k zlib-devel x86_64 1.2.3-29.el6 local 44 k Installing for dependencies: cloog-ppl x86_64 0.15.7-1.2.el6 local 93 k cpp x86_64 4.4.7-4.el6 local 3.7 M keyutils-libs-devel x86_64 1.4-4.el6 local 28 k krb5-devel x86_64 1.10.3-10.el6_4.6 local 495 k libcom_err-devel x86_64 1.41.12-18.el6 local 32 k libselinux-devel x86_64 2.0.94-5.3.el6_4.1 local 136 k libsepol-devel x86_64 2.0.41-4.el6 local 64 k libstdc++-devel x86_64 4.4.7-4.el6 local 1.6 M mpfr x86_64 2.4.1-6.el6 local 156 k ppl x86_64 0.10.2-11.el6 local 1.3 M Transaction Summary ================================================================================ Install 15 Package(s) Total download size: 24 M Installed size: 59 M Downloading Packages: -------------------------------------------------------------------------------- Total 48 MB/s | 24 MB 00:00 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Warning: RPMDB altered outside of yum. Installing : mpfr-2.4.1-6.el6.x86_64 1/15 Installing : cpp-4.4.7-4.el6.x86_64 2/15 Installing : ppl-0.10.2-11.el6.x86_64 3/15 Installing : cloog-ppl-0.15.7-1.2.el6.x86_64 4/15 Installing : gcc-4.4.7-4.el6.x86_64 5/15 Installing : zlib-devel-1.2.3-29.el6.x86_64 6/15 Installing : libcom_err-devel-1.41.12-18.el6.x86_64 7/15 Installing : keyutils-libs-devel-1.4-4.el6.x86_64 8/15 Installing : libsepol-devel-2.0.41-4.el6.x86_64 9/15 Installing : libselinux-devel-2.0.94-5.3.el6_4.1.x86_64 10/15 Installing : krb5-devel-1.10.3-10.el6_4.6.x86_64 11/15 Installing : libstdc++-devel-4.4.7-4.el6.x86_64 12/15 Installing : gcc-c++-4.4.7-4.el6.x86_64 13/15 Installing : openssl-devel-1.0.1e-15.el6.x86_64 14/15 Installing : pcre-devel-7.8-6.el6.x86_64 15/15 local/productid | 1.7 kB 00:00 ... Verifying : pcre-devel-7.8-6.el6.x86_64 1/15 Verifying : libstdc++-devel-4.4.7-4.el6.x86_64 2/15 Verifying : libsepol-devel-2.0.41-4.el6.x86_64 3/15 Verifying : keyutils-libs-devel-1.4-4.el6.x86_64 4/15 Verifying : cpp-4.4.7-4.el6.x86_64 5/15 Verifying : libcom_err-devel-1.41.12-18.el6.x86_64 6/15 Verifying : openssl-devel-1.0.1e-15.el6.x86_64 7/15 Verifying : libselinux-devel-2.0.94-5.3.el6_4.1.x86_64 8/15 Verifying : mpfr-2.4.1-6.el6.x86_64 9/15 Verifying : zlib-devel-1.2.3-29.el6.x86_64 10/15 Verifying : gcc-4.4.7-4.el6.x86_64 11/15 Verifying : krb5-devel-1.10.3-10.el6_4.6.x86_64 12/15 Verifying : gcc-c++-4.4.7-4.el6.x86_64 13/15 Verifying : ppl-0.10.2-11.el6.x86_64 14/15 Verifying : cloog-ppl-0.15.7-1.2.el6.x86_64 15/15 Installed: gcc.x86_64 0:4.4.7-4.el6 gcc-c++.x86_64 0:4.4.7-4.el6 openssl-devel.x86_64 0:1.0.1e-15.el6 pcre-devel.x86_64 0:7.8-6.el6 zlib-devel.x86_64 0:1.2.3-29.el6 Dependency Installed: cloog-ppl.x86_64 0:0.15.7-1.2.el6 cpp.x86_64 0:4.4.7-4.el6 keyutils-libs-devel.x86_64 0:1.4-4.el6 krb5-devel.x86_64 0:1.10.3-10.el6_4.6 libcom_err-devel.x86_64 0:1.41.12-18.el6 libselinux-devel.x86_64 0:2.0.94-5.3.el6_4.1 libsepol-devel.x86_64 0:2.0.41-4.el6 libstdc++-devel.x86_64 0:4.4.7-4.el6 mpfr.x86_64 0:2.4.1-6.el6 ppl.x86_64 0:0.10.2-11.el6 Complete!
(以上输出表示包和编译工具安装成功!)
安装成功后在进入redis解压的目录中执行make命令:
[root@caiji redis-3.2.8]# make (以下是命令输出) cd src && make all make[1]: Entering directory `/var/software/redis-3.2.8/src' rm -rf redis-server redis-sentinel redis-cli redis-benchmark redis-check-rdb redis-check-aof *.o *.gcda *.gcno *.gcov redis.info lcov-html (cd ../deps && make distclean) make[2]: Entering directory `/var/software/redis-3.2.8/deps' (cd hiredis && make clean) > /dev/null || true (cd linenoise && make clean) > /dev/null || true (cd lua && make clean) > /dev/null || true (cd geohash-int && make clean) > /dev/null || true (cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true .......... 省略部分输出。。。。。 .......... CC crc16.o CC endianconv.o CC slowlog.o CC scripting.o CC bio.o CC rio.o CC rand.o CC memtest.o CC crc64.o CC bitops.o CC sentinel.o CC notify.o CC setproctitle.o CC blocked.o CC hyperloglog.o CC latency.o CC sparkline.o CC redis-check-rdb.o CC geo.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 CC redis-check-aof.o LINK redis-check-aof Hint: It's a good idea to run 'make test' ;) make[1]: Leaving directory `/var/software/redis-3.2.8/src'
(自此执行make成功!)
PS: 注意如果make显示错误,按照以下方法解决: 如果提示couldn’t execute tcl : no such file or
dicrectory,请自行安装tcl; 如果提示请执行make distclean,然后再make
make成功之后,会在/var/software/redis-3.2.8/src目录下多出一些文件,如下:
然后执行make install:
[root@caiji redis-3.2.8]# make install cd src && make install make[1]: Entering directory `/var/software/redis-3.2.8/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 `/var/software/redis-3.2.8/src'
执行完make install后会在目录/usr/local/bin下生成以下文件:
[root@caiji redis-3.2.8]# ll /usr/local/bin total 26344 -rwxr-xr-x. 1 root root 5578239 May 5 11:01 redis-benchmark -rwxr-xr-x. 1 root root 22185 May 5 11:01 redis-check-aof -rwxr-xr-x. 1 root root 7827882 May 5 11:01 redis-check-rdb -rwxr-xr-x. 1 root root 5707107 May 5 11:01 redis-cli lrwxrwxrwx. 1 root root 12 May 5 11:01 redis-sentinel -> redis-server -rwxr-xr-x. 1 root root 7827882 May 5 11:01 redis-server
查看redis版本号:
[root@caiji redis-3.2.8]# /usr/local/bin/redis-server -v Redis server v=3.2.8 sha=00000000:0 malloc=jemalloc-4.0.3 bits=64 build=1882e7b0ae5da5a3
(自此redis安装完成)
配置redis:
[root@caiji redis-3.2.8]# ./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] ----直接默认下一步,端口号默认为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 [/usr/local/bin/redis-server] ----默认下一步,redis服务路径位置 Selected config: Port : 6379 Config file : /etc/redis/6379.conf Log file : /var/log/redis_6379.log Data dir : /var/lib/redis/6379 Executable : /usr/local/bin/redis-server Cli Executable : /usr/local/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!
(自此redis配置成功,并且为开机启动方式)
然后根据要求对redis的配置文件进行修改:
[root@caiji redis-3.2.8]# vim /etc/redis/6379.conf
修改项看截图,根据截图找到修改项,修改成截图中的值:
配置文件修改完毕后将redis服务停止:
[root@caiji redis-3.2.8]# /etc/init.d/redis_6379 stop Stopping ... Waiting for Redis to shutdown ... Redis stopped
然后重新启动:
[root@caiji redis-3.2.8]# /etc/init.d/redis_6379 start Starting Redis server...
查看进程无误,表示修改成功:
[root@caiji redis-3.2.8]# ps -ef | grep redis root 32106 1 0 11:31 ? 00:00:00 /usr/local/bin/redis-server 0.0.0.0:6379 root 32111 3030 0 11:31 pts/0 00:00:00 grep redis
(自此redis安装配置完毕,并且是启动状态!)
1.通过ps -ef|grep redis命令查看Redis进程:
[root@caiji redis-3.2.8]# ps -ef | grep redis root 32106 1 0 11:31 ? 00:00:00 /usr/local/bin/redis-server 0.0.0.0:6379 root 32111 3030 0 11:31 pts/0 00:00:00 grep redis
2.开启Redis服务操作通过/etc/init.d/redis_6379 start命令,也可通过:service redis_6379 start
3.关闭Redis服务操作通过/etc/init.d/redis_6379 stop命令,也可通过:service redis_6379 stop
为了提高安全性可以对Redis中root用户设置密码。
方法如下:
1.临时修改,重启后失效:
[root@local ~]# cd /usr/local/bin[root@local bin]# ll otal 26344 -rwxr-xr-x. 1 root root 5578239 May 5 11:01 redis-benchmark -rwxr-xr-x. 1 root root 22185 May 5 11:01 redis-check-aof -rwxr-xr-x. 1 root root 7827882 May 5 11:01 redis-check-rdb -rwxr-xr-x. 1 root root 5707107 May 5 11:01 redis-cli lrwxrwxrwx. 1 root root 12 May 5 11:01 redis-sentinel -> redis-server- rwxr-xr-x. 1 root root 7827882 May 5 11:01 redis-server [root@local bin]# ./redis-cli 127.0.0.1:6379> config set requirepass pwtest10 OK 127. 0.0.1:6379> auth pwtest10 OK 127.0.0.1:6379> config get requirepass 1) "requirepass" 2) "pwtest10"
以上设置密码命令 “config set requirepass pwtest10” 将Redis的root用户密码设置为pwtest10,查询密码使用命令 “config get requirepass”,但是这是临时设置,如果重启Redis,密码就会失效。
2.永久设置密码:
打开Redis的配置文件 /etc/redis/6379.conf 找到配置参数 ** # requirepass foobared ** 此参数是备注释掉的,去掉注释修改为 ** requirepass pwtest10 **。
配置文件修改后重启Redis即可。
上述就是小编为大家分享的Linux系统如何安装Redis服务了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注创新互联行业资讯频道。