## CentOS操作系統下的源碼編譯安裝
### 一、安裝
1. 創建一個存放源碼的目錄
~~~
[root@ff4da083e253 ~]# mkdir ~/soft
~~~
2. 切換到上述創建的目錄下,在Redis[官網](http://redis.cn)下載源碼
~~~
[root@ff4da083e253 ~]# cd soft/
[root@ff4da083e253 soft]# wget http://download.redis.io/releases/redis-6.0.6.tar.gz
~~~
3. 解壓下載的源碼包
~~~
[root@ff4da083e253 soft]# tar -zxvf redis-6.0.6.tar.gz
~~~
4. 安裝gcc并進入解壓目錄,編譯源碼(因為源碼是C語言寫的,需要gcc編譯)
~~~
[root@ff4da083e253 soft]# yum install -y gcc
[root@ff4da083e253 soft]# cd redis-6.0.6
[root@ff4da083e253 redis-6.0.6]# make
~~~
5. 編譯完成后,安裝在指定目錄下(如果不知道目錄,則會安裝在默認目錄`/usr/local/bin`)
~~~
[root@ff4da083e253 redis-6.0.6]# make install PREFIX=/opt/wuliang/redis6
~~~
### 二、啟動
1. 添加Redis環境變量
~~~
[root@ff4da083e253 redis-6.0.6]# vi /etc/profile
# 打開文件后,在末尾追加如下內容:
export REDIS_HOME=/opt/wuliang/redis6
export PATH=$PATH:$REDIS_HOME/bin
~~~
2. 根據源碼提供的腳本,啟動Redis
~~~
[root@ff4da083e253 redis-6.0.6]# ./utils/install_server.sh
...
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 [/opt/wuliang/redis6/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 ? ? : /opt/wuliang/redis6/bin/redis-server
Cli Executable : /opt/wuliang/redis6/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實例以及對應配置文件、日志文件、數據持久化目錄等資源。
3. 查看服務狀態
> 上述腳本執行完成后,同時會自動創建一個service服務(/etc/init.d目錄下,就可以看到,此處為:redis\_6379)
~~~
[root@ff4da083e253 redis-6.0.6]# service redis_6379 status
Redis is running (13917)
~~~