Centos7離線安裝redis

1.1 下載、上傳、解壓redis4.0.11

下載地址:http://download.redis.io/releases/redis-4.0.11.tar.gz
下載後上傳到服務器上,並解壓:
備註:這裏是上傳壓縮包到/opt/redis目錄下。node

[root@CDH-143 redis]# tar -zxvf redis-4.0.11.tar.gz 
redis-4.0.11/
redis-4.0.11/.gitignore
......
redis-4.0.11/utils/whatisdoing.sh
[root@CDH-143 redis]# ls
redis-4.0.11 redis-4.0.11.tar.gz
[root@CDH-143 redis]# cd redis-4.0.11/
[root@CDH-143 redis-4.0.11]# ls
00-RELEASENOTES CONTRIBUTING deps Makefile README.md runtest runtest-sentinel src utils
BUGS COPYING INSTALL MANIFESTO redis.conf runtest-cluster sentinel.conf tests

1.2 安裝gcc

1)若是執行gcc –version出現如下信息,表示已經安裝過gcc,能夠跳過該步驟:linux

[boco@CDH-143 spark_job_monitor]$ gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-4)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[root@CDH-143 redis]# 

2)不然,若是執行make命令報下面錯誤,說明系統上沒有安裝C語言環境,須要安裝,在linux系統上的C環境是gcc,所以須要安裝gcc。git

make[3]: gcc: Command not found
make[3]: *** [net.o] Error 127
make[3]: Leaving directory `/home/work/redis/deps/hiredis'
make[2]: *** [hiredis] Error 2
make[2]: Leaving directory `/home/work/redis/deps'
make[1]: [persist-settings] Error 2 (ignored)
CC adlist.o
/bin/sh: cc: command not found
make[1]: *** [adlist.o] Error 127
make[1]: Leaving directory `/home/work/redis/src'
make: *** [all] Error 2

安裝gcc,redis

方式1:從centos7的系統安裝鏡像中提取:解壓鏡像文件,進入"Packages"目錄,取出以下圖所示rpm包centos

方式2:訪問鏡像網站獲取:http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/ ,而後將其上傳服務器

從裏面packages找出來,這些是從網上整理出來的(15個文件不要漏掉!!)ide


解壓gcc.zip,編譯安裝測試

[root@CDH-143 soft]# unzip gcc.zip
[root@CDH-143 soft]# cd gcc
[root@CDH-143 soft]# rpm -Uvh *.rpm --nodeps --force

查看gcc版本,出現如下信息,表示安裝成功網站

[boco@CDH-143 spark_job_monitor]$ gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-4)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[root@CDH-143 redis]#

1.3 編譯安裝redis

[root@CDH-143 redis-4.0.11]# make MALLOC=libc
cd src && make all
。。。。。。。。
CC rax.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
INSTALL redis-check-aof
Hint: It's a good idea to run 'make test' ;)
make[1]: Leaving directory `/opt/redis/redis-4.0.11/src'
[root@CDH-143 redis-4.0.11]# 
[root@CDH-143 redis-4.0.11]# cd src && make install
CC Makefile.dep

Hint: It's a good idea to run 'make test' ;)
INSTALL install
INSTALL install
INSTALL install
INSTALL install
INSTALL install

編譯安裝成功。this

1.4 啓動redis

[root@CDH-143 src]# ./redis-server
24496:C 11 Mar 13:49:56.298 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
24496:C 11 Mar 13:49:56.298 # Redis version=4.0.11, bits=64, commit=00000000, modified=0, pid=24496, just started
24496:C 11 Mar 13:49:56.298 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 4.0.11 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 18685
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                   
24496:M 11 Mar 13:49:56.302 # Server initialized 24496:M 11 Mar 13:49:56.303 # 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. 24496:M 11 Mar 13:49:56.303 # 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. 24496:M 11 Mar 13:49:56.303 * Ready to accept connections

啓動成功。
如下爲設置redis開機自啓,而且添加到系統服務

1.4.1 複製redis配置文件

[root@CDH-143 src]# mkdir /etc/redis
[root@CDH-143 src]# cd ..
[root@CDH-143 redis-4.0.11]# ls
00-RELEASENOTES CONTRIBUTING deps Makefile README.md runtest runtest-sentinel src utils
BUGS COPYING INSTALL MANIFESTO redis.conf runtest-cluster sentinel.conf tests
[root@CDH-143 redis-4.0.11]# cp redis.conf /etc/redis/6379.conf

修改redis啓動爲後臺啓動:

[root@CDH-143 redis-4.0.11]# vi /etc/redis/6379.conf

1.4.2 將啓動文件拷貝到init.d中

[root@CDH-143 redis-4.0.11]# cp utils/redis_init_script /etc/init.d/redisd

1.4.3 修改啓動腳本參數

[root@CDH-143 redis-4.0.11]# vi /etc/init.d/redisd

添加如下代碼,:wq保存退出

添加

# chkconfig: 2345 10 90
# description: Start and Stop redisd

修改:

EXEC=/opt/redis/redis-4.0.11/src/redis-server
CLIEXEC=/opt/redis/redis-4.0.11/src/redis-cli
PIDFILE=/opt/redis/redis-4.0.11/redis_${REDISPORT}.pid

1.4.4 增長腳本執行權限

[root@CDH-143 redis-4.0.11]# chmod +x /etc/init.d/redisd

1.4.5 增長系統服務

[root@CDH-143 redis-4.0.11]# chkconfig --add redisd
[root@CDH-143 redis-4.0.11]# chkconfig --list redisd

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]'.

redisd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@CDH-143 redis-4.0.11]#

1.4.6 啓動redis服務測試

[root@CDH-143 redis-4.0.11]# service redisd start
Starting Redis server...
9084:C 11 Mar 15:23:36.469 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
9084:C 11 Mar 15:23:36.469 # Redis version=4.0.11, bits=64, commit=00000000, modified=0, pid=9084, just started
9084:C 11 Mar 15:23:36.469 # Configuration loaded
[root@CDH-143 redis-4.0.11]#
[root@CDH-143 redis-4.0.11]# ps -aux | grep redis
root 3575 0.0 0.0 38260 2140 ? Ssl 15:09 0:00 /opt/redis/redis-4.0.11/src/redis-server 127.0.0.1:6379
root 8870 0.0 0.0 112660 956 pts/2 S+ 15:22 0:00 grep --color=auto redis

配置完畢,重啓服務器,測試是否成功

相關文章
相關標籤/搜索