# Modify Redis conf
vim /etc/redis/redis.conf
# bind 127.0.0.1
bind 0.0.0.0
# protected-mode yes
protected-mode no
systemctl restart redis
2023/04/19
Ubuntu 22.04 LTS Redis 7.0.10 開啟外部連線
Redis 3.2以後預設配置僅允許localhost連線
2019/03/28
Redis Cluster 3.0.2 on CentOS 7
這篇其實寫完很久,但一直忘記按發佈XD
Redis Cluster是Redis用於解決分散式的方案,又稱為Redis叢集
是一個讓數據再多個Node之間相互傳輸的服務,Redis Cluster的優勢主要有以下兩個點
不過Redis Cluster並不支持處理多個keys的命令,在不同Node移動數據並不像Redis那樣高性能,高負載時有可能會遇到不可預期錯誤
Redis Cluster並非採用Consistent Hashing而是用Hash Slots,它其實就是代表一個Keys的集合
Redis Cluster共有16384 Hash Slots,將Key做CRC16校驗接著Mod 16384決定Key會放置於哪個Slot,Redis Cluster每個Node負責一部分的Hash Slots。例如,目前Cluster中有三個Master Node,則:
如果新增了Node D,僅需將原本Node上的Hash Slots添加至Node D上;相對的要刪除一個Node A,將Node A上的Hash Slots遷移至Node B / C / D上,再將沒有任何Hash Slots的Node A移除即可;且新增、刪除或搬遷Hash Slots時無須停止任何服務。
Redis Cluster為了使部分Node失敗或大部分的Node無法通訊時仍可以使用,Redis Cluster使用Master-Slave複製模型,則每個Master Node則最少有會1個Slave Node;以上述的例子而言,如果沒有使用該模型的情況下,Node A失效則會導致Cluster因0到3000的Hash Slots不可用而失效。
最後Redis Cluster並不保證數據的一致性,這也意味著Redis Cluster在特定條件下有可能會丟失數據。
讓我們開始來建置Redis Cluster吧
接著我們開始來建立Redis Cluster吧,根據官方文獻建置一個Redis Cluster最少需要三個Master,也意味著還需要三個Slave來確保每個Master失效時才能將角色轉移至Slave上。
所以需先準備6台Host或container,系統為CentOS 7 minimal
Redis Cluster是Redis用於解決分散式的方案,又稱為Redis叢集
是一個讓數據再多個Node之間相互傳輸的服務,Redis Cluster的優勢主要有以下兩個點
- 自動分割數據到不同Node
- 部分Node當機或不可用情況能夠繼續維持服務
不過Redis Cluster並不支持處理多個keys的命令,在不同Node移動數據並不像Redis那樣高性能,高負載時有可能會遇到不可預期錯誤
Redis Cluster並非採用Consistent Hashing而是用Hash Slots,它其實就是代表一個Keys的集合
Redis Cluster共有16384 Hash Slots,將Key做CRC16校驗接著Mod 16384決定Key會放置於哪個Slot,Redis Cluster每個Node負責一部分的Hash Slots。例如,目前Cluster中有三個Master Node,則:
- Node A包含0到3000 Hash Slots
- Node B包含3001到9000 Hash Slots
- Node C包含9001到16383 Hash Slots
如果新增了Node D,僅需將原本Node上的Hash Slots添加至Node D上;相對的要刪除一個Node A,將Node A上的Hash Slots遷移至Node B / C / D上,再將沒有任何Hash Slots的Node A移除即可;且新增、刪除或搬遷Hash Slots時無須停止任何服務。
Redis Cluster為了使部分Node失敗或大部分的Node無法通訊時仍可以使用,Redis Cluster使用Master-Slave複製模型,則每個Master Node則最少有會1個Slave Node;以上述的例子而言,如果沒有使用該模型的情況下,Node A失效則會導致Cluster因0到3000的Hash Slots不可用而失效。
最後Redis Cluster並不保證數據的一致性,這也意味著Redis Cluster在特定條件下有可能會丟失數據。
讓我們開始來建置Redis Cluster吧
接著我們開始來建立Redis Cluster吧,根據官方文獻建置一個Redis Cluster最少需要三個Master,也意味著還需要三個Slave來確保每個Master失效時才能將角色轉移至Slave上。
所以需先準備6台Host或container,系統為CentOS 7 minimal
Name | IP | Port | Cluster BUS Port |
Master 1 | 192.168.126.135 | 6379 | 16379 |
Master 2 | 192.168.126.136 | 6380 | 16380 |
Master 3 | 192.168.126.141 | 6381 | 16381 |
Slave 1 | 192.168.126.142 | 6382 | 6382 |
Slave 2 | 192.168.126.143 | 6383 | 6383 |
Slave 3 | 192.168.126.144 | 6384 | 6384 |
2019/03/20
Redis 無法啟動問題
failed (Result: exit-code) since Tue 2019-03-19 21:33:14 EDT; 17s ago
ExecStop=/usr/libexec/redis-shutdown (code=exited, status=1/FAILURE)
ExecStart=/usr/bin/redis-server /etc/redis.conf --supervised systemd (code=exited, status=1/FAILURE)
上述問題是執行Redis service start時需要redis來執行
但他執行時無法讀寫redis.conf,所以有可能是因為/etc/redis.conf的擁有者不是redis
Tue 19 21:33:14 systemd supervision requested, but NOTIFY_SOCKET not found
Tue 19 21:33:14 systemd[1]: Main process exited, code=exited, status=1/FAILURE
Tue 19 21:33:14 systemd[1]: Unit entered failed state.
Tue 19 21:33:14 systemd[1]: Failed with result 'exit-code'.
Tue 19 21:33:14 systemd[1]: Service hold-off time over, scheduling restart.
Tue 19 21:33:14 systemd[1]: Stopped Redis In-Memory Data Store.
上述問題則是因為/etc/redis.conf的supervised不是systemd
WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
參考資料:
https://blog.csdn.net/jiangshouzhuang/article/details/50864933
ExecStop=/usr/libexec/redis-shutdown (code=exited, status=1/FAILURE)
ExecStart=/usr/bin/redis-server /etc/redis.conf --supervised systemd (code=exited, status=1/FAILURE)
上述問題是執行Redis service start時需要redis來執行
但他執行時無法讀寫redis.conf,所以有可能是因為/etc/redis.conf的擁有者不是redis
解決方式:
chown redis /etc/redis.conf
Tue 19 21:33:14 systemd supervision requested, but NOTIFY_SOCKET not found
Tue 19 21:33:14 systemd[1]: Main process exited, code=exited, status=1/FAILURE
Tue 19 21:33:14 systemd[1]: Unit entered failed state.
Tue 19 21:33:14 systemd[1]: Failed with result 'exit-code'.
Tue 19 21:33:14 systemd[1]: Service hold-off time over, scheduling restart.
Tue 19 21:33:14 systemd[1]: Stopped Redis In-Memory Data Store.
上述問題則是因為/etc/redis.conf的supervised不是systemd
解決方是:
將supervised的值改成systemd
並在終端機輸入systemctl daemon-reload
reboot即可修正
WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
解決方法:
vi /etc/sysctl.conf
net.core.somaxconn= n>128
reboot
參考資料:
https://blog.csdn.net/jiangshouzhuang/article/details/50864933
Upgrade Redis 5.0.3 / 5.0.4 on CentOS 7
方法一
# Download Redis-5.0.3-1
wget http://rpms.remirepo.net/enterprise/7/remi/x86_64//redis-5.0.3-1.el7.remi.x86_64.rpm
# Install rpm
rpm -Uvh redis-5.0.3-1.el7.remi.x86_64.rpm
# Install Redis 5.0.3-1
yum --enablerepo=remi install -y redis
2019/03/18
Redis HA Master / Slave + Redis Sentinel on CentOS 7
有鑑於網路上有很多前輩都有寫Redis的介紹,我在此就不寫了XD
不過推薦可以看大陸有很多牛逼得前輩文章寫得不錯
那這次實驗的配置有4台host
不過推薦可以看大陸有很多牛逼得前輩文章寫得不錯
那這次實驗的配置有4台host
- 1台Redis Sentinel,IP為192.168.126.136 Port 26379
- 1台Redis Master,IP為192.168.126.133 Port 6379
- 2台Redis Slave,IP為192.168.126.134 Port 6380和192.168.126.135 Port 6381
2019/03/09
使用Node.js和Redis建立一個HTML5聊天室
這篇程式碼主要由IBM Developerworks所提供
我建置的專案如下圖
這篇想法就是透過WebSocket來建立通訊
將接收到的值以JSON方式存進Redis的list內
並透過Broadcast filter到的訊息將其加入至聊天室內
app.js
www.js
我建置的專案如下圖
這篇想法就是透過WebSocket來建立通訊
將接收到的值以JSON方式存進Redis的list內
並透過Broadcast filter到的訊息將其加入至聊天室內
app.js
var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var indexRouter = require('./routes/index');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', indexRouter);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
next(createError(404));
});
// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
res.render('error');
});
module.exports = app;
www.js
2019/03/08
CentOS 7 安裝PhpRedisAdmin再Nginx
首先輸入下方命令安裝套件
# Install EPEL
yum install -y epel-release
# Update Package
yum update -y
# Install PHP PHP-FPM PHP-mbstring Nginx Redis
yum install -y git php php-fpm php-mbstring nginx redis
接著用Git下載PhpRedisAdmin
# Download PhpRedisAdmin
cd /var/www
git clone https://github.com/ErikDubbelboer/phpRedisAdmin.git
cd phpRedisAdmin
git clone https://github.com/nrk/predis.git vendor
修改Nginx
# 修改Nginx設定
vi /etc/nginx/nginx.conf
server_name localhost;
location / {
root /var/www;
index index.php;
}
location ~ \.php$ {
root /var/www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
2019/02/24
Install Redis Server on CentOS 7
# Install Epel
yum install -y epel-release
# Update
yum update -y
# Install Redis server
yum install -y redis
# Redis start at Redis
systemctl enable redis
# Start Redis server
systemctl start redis
Install Redis-stat on CentOS 7
# Install Ruby
yum install -y ruby
# Install RubyGems
yum install -y rubygems
# Install Ruby devel/gcc/gcc-c++
yum install -y ruby-devel gcc gcc-c++
# Install Redis stat
gem install redis-stat
# Start Web Server
# Default port 63790
redis-stat --server
不是在本機上要看網頁需將防火牆加上
ex:
# 開啟63790 port並永久保存
firewall-cmd --add-port=63790/tcp --permanent
訂閱:
文章 (Atom)