基於CentOS-7的redis下載和安裝
阿新 • • 發佈:2020-08-11
1.下載和安裝
在我安裝的虛擬機器中,我把所有自己安裝的軟體都放在了/ph/install 目錄下,具體以自己實際情況為準。
[root@localhost ~]$ cd /ph/install #進入到自己建立的安裝目錄下 #下載壓縮包 [root@localhost ~]$ wget http://download.redis.io/releases/redis-5.0.0.tar.gz #解壓縮 [root@localhost ~]$ tar -zxvf redis-5.0.0.tar.gz -C /ph/install/ #安裝gcc基礎環境, 可以先檢視是否安裝過: gcc --version [root@localhost ~]$ yum -y install gcc [root@localhost ~]$ yum -y install gcc-c++ #編譯redis [root@localhost ~]$ cd /ph/install/redis-5.0.0 [root@localhost redis-5.0.0]$ make MALLOC=libc #安裝 [root@localhost redis-5.0.0]$ cd src [root@localhost src]$ make install #檢視是否安裝成功, 輸入命令: "ll |grep redis-" 如果顯示資訊如下所示, 就是安裝成功 [root@localhost src]$ ll |grep redis- -rwxr-xr-x. 1 root root 353848 6月 26 18:30 redis-benchmark -rw-rw-r--. 1 root root 29605 10月 17 2018 redis-benchmark.c -rw-r--r--. 1 root root 109104 6月 26 18:30 redis-benchmark.o -rwxr-xr-x. 1 root root 4016272 6月 26 18:30 redis-check-aof -rw-rw-r--. 1 root root 7143 10月 17 2018 redis-check-aof.c -rw-r--r--. 1 root root 28744 6月 26 18:30 redis-check-aof.o -rwxr-xr-x. 1 root root 4016272 6月 26 18:30 redis-check-rdb -rw-rw-r--. 1 root root 13541 10月 17 2018 redis-check-rdb.c -rw-r--r--. 1 root root 65872 6月 26 18:30 redis-check-rdb.o -rwxr-xr-x. 1 root root 771056 6月 26 18:30 redis-cli -rw-rw-r--. 1 root root 249486 10月 17 2018 redis-cli.c -rw-r--r--. 1 root root 871040 6月 26 18:30 redis-cli.o -rwxr-xr-x. 1 root root 4016272 6月 26 18:30 redis-sentinel -rwxr-xr-x. 1 root root 4016272 6月 26 18:30 redis-server -rwxrwxr-x. 1 root root 3600 10月 17 2018 redis-trib.rb
#進入到 /ph/install/redis-5.0.0/ 目錄下 [root@localhost /]$ cd /ph/install/redis-5.0.0/ #建立配置檔案的資料夾 和 資料的資料夾 [root@localhost redis-5.0.0]$ mkdir conf [root@localhost redis-5.0.0]$ mkdir data #將預設配置檔案複製一份到conf資料夾下, 同時備份一份 [root@localhost redis-5.0.0]$ cp redis.conf conf/ [root@localhost redis-5.0.0]$ cp redis.conf conf/redis.conf.back
#進入到 redis-5.0.0/src 目錄下, 啟動redis服務, &符號表示後臺執行, 能夠看到如下圖所示,啟動成功 [root@localhost redis-5.0.0]$ cd src [root@localhost src]$ ./redis-server ../redis.conf & 9818:M 26 Jun 2020 19:02:20.243 * Increased maximum number of open files to 10032 (it was originally set to 1024). _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 5.0.0 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 9818 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' 9818:M 26 Jun 2020 19:02:20.244 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. #ctrl + c 回退到命令列出, 檢視程序, 如下所示就證明 [root@localhost src]$ ps -ef|grep redis root 9818 7878 0 19:02 pts/0 00:00:00 ./redis-server 0.0.0.0:6379 root 9832 7878 0 19:02 pts/0 00:00:00 grep --color=auto redis
#本地連線, 如下表示連線成功 [root@localhost conf]$ redis-cli 127.0.0.1:6379> 127.0.0.1:6379> 127.0.0.1:6379> #連線遠端redis [root@localhost conf]$ redis-cli –h 61.129.65.248 –p 6384
#將redis-6379.conf中的註釋等都處理掉 [root@localhost redis-5.0.0]$ cd conf [root@localhost conf]$ cat redis.conf|grep -Ev '^$|#' > redis-6379.conf #進入到conf資料夾對redis-6379.conf檔案進行修改 [root@localhost conf]$ vim redis-6379.conf #bind 127.0.0.1 允許外網訪問 #bind 0.0.0.0 bind 192.168.23.129 #後臺啟動 daemonize yes #日誌檔案 logfile "redis-6379.log" #資料資料夾設定 dir /ph/install/redis-5.0.0/data #:wq 儲存退出 #關閉redis 服務 [root@localhost conf]$ ps -ef|grep redis root 9818 7878 0 19:02 pts/0 00:00:02 ./redis-server 0.0.0.0:6379 root 10675 7878 0 19:45 pts/0 00:00:00 grep --color=auto redis [root@localhost conf]$ [root@localhost conf]$ kill -9 9818 #再次啟動並載入修改後的配置 redis-6379.conf [root@localhost conf]$ redis-server redis-6379.conf #檢視程序是否存在, 如下啟動成功 [root@localhost conf]$ ps -ef|grep redis root 10734 1 0 19:47 ? 00:00:00 redis-server 0.0.0.0:6379 root 10739 7878 0 19:47 pts/0 00:00:00 grep --color=auto redis [root@localhost conf]$