هل ترغب في معرفة كيفية تثبيت خادم Redis على Ubuntu Linux؟ في هذا البرنامج التعليمي ، سوف نعرض لك جميع الخطوات اللازمة لتثبيت خادم Redis وتكوينه على نظام التشغيل Ubuntu Linux.

• إصدار Ubuntu Linux 18.04

البرنامج التعليمي ذات الصلة:

في هذه الصفحة ، نوفر وصولاً سريعًا إلى قائمة من البرامج التعليمية المتعلقة بنظام التشغيل Ubuntu Linux.

1. تكوين التاريخ والوقت باستخدام NTP

قم بتكوين النظام لاستخدام التاريخ والوقت الصحيحين باستخدام NTP.

في وحدة تحكم Linux ، استخدم الأوامر التالية لتعيين المنطقة الزمنية الصحيحة.

# dpkg-reconfigure tzdata

قم بتثبيت حزمة Ntpdate وقم بتعيين التاريخ والوقت الصحيحين على الفور.

# apt-get update
# apt-get install ntpdate
# ntpdate pool.ntp.br

تم استخدام الأمر Ntpdate لضبط التاريخ والوقت الصحيحين باستخدام الخادم: pool.ntp.br

دعونا تثبيت خدمة NTP.

# timedatectl set-ntp 0
# apt-get install ntp

NTP هي الخدمة التي سوف تحافظ على تحديث خادمنا.

استخدم تاريخ الأمر للتحقق من التاريخ والوقت اللذين تم تكوينهما على نظام التشغيل Ubuntu Linux الخاص بك.

# date

2. تثبيت خادم Redis

في وحدة تحكم Linux ، استخدم الأوامر التالية لتثبيت حزمة خادم Redis.

# apt-get update
# apt-get install redis-server

الآن ، تحتاج إلى تحرير الملف sysctl.conf.

# vi /etc/sysctl.conf

At في نهاية الملف ، أضف الأسطر التالية:

vm.overcommit_memory=1
net.core.somaxconn=65535
fs.file-max=100000

أدخل الأمر التالي لإعادة تحميل ملف التكوين

# sysctl -p
# echo never > /sys/kernel/mm/transparent_hugepage/enabled

الآن ، يجب أن تعثر على موقع ملف redis.conf على نظامك.

بعد العثور على ، تحتاج إلى تحرير ملف redis.conf.

# updatedb
# locate redis.conf

# vi /etc/redis/redis.conf

هنا هو الملف الأصلي ، قبل التكوين لدينا وبدون التعليقات.

bind 127.0.0.1 ::1
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /var/run/redis/redis-server.pid
loglevel notice
logfile /var/log/redis/redis-server.log
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /var/lib/redis
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no
appendonly no
appendfilename “appendonly.aof”
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble no
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events “”
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes

أضف الأسطر التالية إلى ملف التكوين:

maxmemory 1024mb
maxmemory-policy allkeys-lru

في مثالنا ، سنقوم بحجز 1 غيغابايت من ذاكرة الوصول العشوائي لخدمة Redis.

تغيير خطوط التكوين الموجودة التالية:

supervised systemd
bind 127.0.0.1 ::1

هنا هو الملف الجديد مع التكوين لدينا.

bind 127.0.0.1 ::1
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised systemd
pidfile /var/run/redis/redis-server.pid
loglevel notice
logfile /var/log/redis/redis-server.log
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /var/lib/redis
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
maxmemory 1024mb
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no
appendonly no
appendfilename “appendonly.aof”
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble no
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events “”
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes

أعد تشغيل خدمة Redis.

تمكين خدمة Redis أثناء التمهيد.

أعد تمهيد الكمبيوتر لاختبار بدء التشغيل التلقائي.

يتم تقديم خدمة Redis على منفذ TCP رقم 6379.

# service redis-server status
# systemctl enable redis-server
# reboot

إذا كان لديك Apache و PHP محليًا ، فاستخدم الأمر التالي لتثبيت وحدة PHP المطلوبة.

# apt-get install php-redis
# service apache2 restart
# /etc/init.d/php7.2-fpm restart

3. اختبر خادم Redis

في وحدة تحكم Linux ، استخدم الأوامر التالية لاختبار خدمة Redis.

# redis-cli
> ping
> set MYSITE “Techexpert.Tips”
> get MYSITE
> exit

اختبر أداء خدمة Redis.

# redis-benchmark -q -n 1000 -c 10 -P 5

PING_INLINE: 142857.14 requests per second
PING_BULK: 142857.14 requests per second
SET: 142857.14 requests per second
GET: 124999.99 requests per second
INCR: 124999.99 requests per second
LPUSH: 142857.14 requests per second
RPUSH: 142857.14 requests per second
LPOP: 124999.99 requests per second
RPOP: 124999.99 requests per second
SADD: 124999.99 requests per second
HSET: 124999.99 requests per second
SPOP: 142857.14 requests per second
LPUSH (needed to benchmark LRANGE): 124999.99 requests per second
LRANGE_100 (first 100 elements): 47619.05 requests per second
LRANGE_300 (first 300 elements): 14925.37 requests per second
LRANGE_500 (first 450 elements): 9433.96 requests per second
LRANGE_600 (first 600 elements): 6578.95 requests per second
MSET (10 keys): 100000.00 requests per second

تهانينا! انتهيت من تثبيت خادم Redis.