1. Home
  2. /
  3. Web technology
  4. /
  5. Linux
  6. /
  7. [ Linux ] –...

[ Linux ] – HOW TO INSTALL Redis ON UBUNTU 18.04

評等結果
點擊便能為這篇文章進行評等!
[評等總次數: 0,平均評等: 0]

換新工作後又有新需求要裝 Redis ,之前有大概看過 Redis 的功能,但一直沒有機會用到就一直沒實際安裝跟操作,利用此次機會記錄下來以後就會用得到。

安裝指令:apt install redis-server
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following additional packages will be installed:
libjemalloc1 redis-tools
Suggested packages:
ruby-redis
The following NEW packages will be installed:
libjemalloc1 redis-server redis-tools
0 upgraded, 3 newly installed, 0 to remove and 19 not upgraded.
Need to get 634 kB of archives.
After this operation, 3,012 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://us.archive.ubuntu.com/ubuntu bionic/universe amd64 libjemalloc1 amd64 3.6.0-11 [82.4 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 redis-tools amd64 5:4.0.9-1ubuntu0.2 [516 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 redis-server amd64 5:4.0.9-1ubuntu0.2 [35.4 kB]
Fetched 634 kB in 4s (159 kB/s)
Selecting previously unselected package libjemalloc1.
(Reading database … 157645 files and directories currently installed.)
Preparing to unpack …/libjemalloc1_3.6.0-11_amd64.deb …
Unpacking libjemalloc1 (3.6.0-11) …
Selecting previously unselected package redis-tools.
Preparing to unpack …/redis-tools_5%3a4.0.9-1ubuntu0.2_amd64.deb …
Unpacking redis-tools (5:4.0.9-1ubuntu0.2) …
Selecting previously unselected package redis-server.
Preparing to unpack …/redis-server_5%3a4.0.9-1ubuntu0.2_amd64.deb …
Unpacking redis-server (5:4.0.9-1ubuntu0.2) …
Setting up libjemalloc1 (3.6.0-11) …
Setting up redis-tools (5:4.0.9-1ubuntu0.2) …
Setting up redis-server (5:4.0.9-1ubuntu0.2) …
Created symlink /etc/systemd/system/redis.service → /lib/systemd/system/redis-server.service.
Created symlink /etc/systemd/system/multi-user.target.wants/redis-server.service → /lib/systemd/system/redis-server.service.
Processing triggers for libc-bin (2.27-3ubuntu1) …
Processing triggers for systemd (237-3ubuntu10.31) …
Processing triggers for man-db (2.8.3-2ubuntu0.1) …
Processing triggers for ureadahead (0.100.0-21) …

編輯設定檔
指令:nano /etc/redis/redis.conf
修改下列內容
supervised no -> supervised systemd

編輯完成重新啟動
指令:service redis restart

檢示運行狀態 service redis status
● redis-server.service – Advanced key-value store
Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2019-11-07 18:03:19 CST; 14s ago
Docs: http://redis.io/documentation,
man:redis-server(1)
Process: 5814 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=0/SUCCESS)
Process: 5817 ExecStart=/usr/bin/redis-server /etc/redis/redis.conf (code=exited, status=0/SUCCESS)
Main PID: 5818 (redis-server)
Tasks: 4 (limit: 4645)
CGroup: /system.slice/redis-server.service
└─5818 /usr/bin/redis-server 127.0.0.1:6379

Nov 07 18:03:19 ubuntu systemd[1]: Stopped Advanced key-value store.
Nov 07 18:03:19 ubuntu systemd[1]: Starting Advanced key-value store…
Nov 07 18:03:19 ubuntu systemd[1]: redis-server.service: Can’t open PID file /var/run/redis/redis-server.pid (yet?) after start: No such file or directory
Nov 07 18:03:19 ubuntu systemd[1]: Started Advanced key-value store.

指令模式確認是否正常運行
指令:redis-cli

//輸入ping
127.0.0.1:6379> ping

//redis 回覆 PONG 表示正常
PONG

//寫入值 格式 set key value
127.0.0.1:6379> set test “hello word”
OK
//取得某個key的值 格式 get key
127.0.0.1:6379> get test
“hello word”
//離開
127.0.0.1:6379> exit

重新啟用 redis 去確認暫停服務後是否 key value 還有被保留在記憶體中
指令:service redis restart

//再進指令模式
指令:redis-cli
//再次取得 test
127.0.0.1:6379> get test
“hello word”
//有取得之前寫入的值表示 能成功快取

若有修改 bind 及加上登入密碼 請改以下指令
redis-cli -h ip網址 -p 6379 -a 密碼

評等結果
點擊便能為這篇文章進行評等!
[評等總次數: 0,平均評等: 0]

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *