Hướng dẫn cài đặt Redis trên CentOs7


Cài đặt redis trên CentOS7

B1 — Installing Redis
$ sudo yum install epel-release
$ sudo yum install redis –y

B2 — Khởi động redis:
$ sudo systemctl start redis.service
$ sudo systemctl enable redis
$ sudo systemctl status redis.service
$ redis-cli ping

B3 — Cấu hình redis to remote
$ sudo vi /etc/redis.conf
Tìm và sửa dòng sau:

bind 127.0.0.1 ip_adress (bind 127.0.0.1 192.168.25.39)

$ sudo systemctl restart redis

Sử dụng lệnh ss sau để xác minh rằng máy chủ Redis đang lắng nghe trên giao diện riêng tư của bạn trên cổng 6379.

$ ss -an | grep 6379

tcp    LISTEN     0      128    192.168.121.233:6379            *:*
tcp    LISTEN     0      128    127.0.0.1:6379       

Tiếp theo, bạn sẽ cần thêm quy tắc tường lửa cho phép lưu lượng truy cập từ các máy từ xa của bạn trên cổng TCP 6379.
$ sudo firewall-cmd --new-zone=redis --permanent
$ sudo firewall-cmd --zone=redis --add-port=6379/tcp --permanent
$ sudo firewall-cmd --zone=redis --add-source=192.168.25.39/24 --permanent
$ sudo firewall-cmd --reload


B2 — Bảo mật cho redis
$ sudo vi /etc/redis.conf
Tìm và bỏ comment (bỏ #) rồi đặt 1 mật khẩu đủ mạnh:
$ echo "duythien" | sha1sum //tạo mật khẩu
Out out: d431c7d0bffea52c7def5cb3cb58d4bdbc0f807c
è requirepass d431c7d0bffea52c7def5cb3cb58d4bdbc0f807c
Restart redis:
$ systemctl restart redis.service

Kiểm tra xem đã đẻ xác nhận set password thành công cho redis:
redis-cli
127.0.0.1> set key1 10
(error) NOAUTH Authentication required.
127.0.0.1> auth d431c7d0bffea52c7def5cb3cb58d4bdbc0f807c
OK
127.0.0.1> set key1 10
Ok

è Hoàn thành!




Nhận xét