Redis安装
官网
中文版的的弊端你懂得。要是看官网能解决的就不要看别人写的文章,哈哈
安装
首先获取redis安装包
yum install wget
wget http://download.redis.io/releases/redis-5.0.3.tar.gz
解压压缩包
tar xf redis-5.0.3.tar.gz
进入redis目录中
cd redis-5.0.3
任何开源软件都有仔细阅读README.md后再动手,开始make,缺啥少啥就install
make
yum install gcc-c++
yum install gcc
如果第一次make失败要清理一下
make disclean
可以直接install,可执行文件就会在当前目录下生产,防止混乱,install的时候用PREFIX指定目录
make install PREFIX=/opt/redis5
加入到环境变量中,在任何位置都可以实行redis的可执行文件了。
vi /etc/profile
在最后两行加入
export REDIS_HOME=/opt/redis5
export PATH=$PATH:$REDIS_HOME/bin
:wq保存后source一下
source /etc/profile
这样可执行文件就单独存放了,也将redis的命令加入到了环境变量中
[root@basic bin]# ll
total 32672
-rwxr-xr-x. 1 root root 4366592 Jan 27 23:17 redis-benchmark
-rwxr-xr-x. 1 root root 8090064 Jan 27 23:17 redis-check-aof
-rwxr-xr-x. 1 root root 8090064 Jan 27 23:17 redis-check-rdb
-rwxr-xr-x. 1 root root 4801840 Jan 27 23:17 redis-cli
lrwxrwxrwx. 1 root root 12 Jan 27 23:17 redis-sentinel -> redis-server
-rwxr-xr-x. 1 root root 8090064 Jan 27 23:17 redis-server
[root@basic bin]# pwd
/opt/redis5/bin
将redis制作成service
源码中就提供了将redis制作成service的可执行文件了
[root@basic redis-5.0.3]# cd utils/
[root@basic utils]# ll
total 52
-rw-rw-r--. 1 root root 593 Dec 12 2018 build-static-symbols.tcl
-rw-rw-r--. 1 root root 1303 Dec 12 2018 cluster_fail_time.tcl
-rw-rw-r--. 1 root root 1070 Dec 12 2018 corrupt_rdb.c
drwxrwxr-x. 2 root root 60 Dec 12 2018 create-cluster
-rwxrwxr-x. 1 root root 2149 Dec 12 2018 generate-command-help.rb
drwxrwxr-x. 3 root root 31 Dec 12 2018 graphs
drwxrwxr-x. 2 root root 39 Dec 12 2018 hashtable
drwxrwxr-x. 2 root root 70 Dec 12 2018 hyperloglog
-rwxrwxr-x. 1 root root 9567 Dec 12 2018 install_server.sh
drwxrwxr-x. 2 root root 63 Dec 12 2018 lru
-rw-rw-r--. 1 root root 1277 Dec 12 2018 redis-copy.rb
-rwxrwxr-x. 1 root root 1352 Dec 12 2018 redis_init_script
-rwxrwxr-x. 1 root root 1047 Dec 12 2018 redis_init_script.tpl
-rw-rw-r--. 1 root root 1762 Dec 12 2018 redis-sha1.rb
drwxrwxr-x. 2 root root 135 Dec 12 2018 releasetools
-rwxrwxr-x. 1 root root 3787 Dec 12 2018 speed-regression.tcl
-rwxrwxr-x. 1 root root 693 Dec 12 2018 whatisdoing.sh
[root@basic utils]# pwd
/opt/redis-5.0.3/utils
在utils目录下,install_server.sh
[root@basic 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]
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]
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.
根据提示可以配置redis,也可以使用默认的,只要使用的端口号不一样,配置就不会出现覆盖的情况。
如果是初次安装的话一路回车就可以了。
最后会将redis加入到service中并且启动,/etc/init.d 目录下也多了redis_6379这个可执行文件。
通过chkconfig查看,也是运行在2、3、4、5级别上了
[root@basic ~]# chkconfig --list redis_6379
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
redis_6379 0:off 1:off 2:on 3:on 4:on 5:on 6:off
启动
service redis_6379 start
停止
service redis_6379 stop