centos 7 安装 redis-5.0.5
[root@localhost ~]# yum -y install gcc make [root@localhost ~]# wget http://download.redis.io/releases/redis-5.0.5.tar.gz -P /usr/local/src //下载 redis (Nosol DataBase) [root@localhost ~]# cd /usr/local/src/ //进入目录 [root@localhost src]# tar -zxvf redis-5.0.5.tar.gz //解压 [root@localhost src]# cd redis-5.0.5/ //进入目录 [root@localhost redis-5.0.5]# make //安装 [...] Hint: It's a good idea to run 'make test' ;) make[1]: Leaving directory `/usr/local/src/redis-5.0.5/src' [root@localhost redis-5.0.5]# cd src/ //进入目录 [root@localhost src]# make install PREFIX=/usr/local/redis-5.0.5 CC Makefile.dep Hint: It's a good idea to run 'make test' ;) INSTALL install INSTALL install INSTALL install INSTALL install INSTALL [root@localhost src]# cp redis-server redis-cli /usr/local/bin [root@localhost src]# cp redis-sentinel redis-benchmark redis-check-aof redis-check-rdb /usr/local/bin [root@localhost src]# mkdir /etc/redis [root@localhost src]# mkdir -p /var/lib/redis/6379 [root@localhost src]# sysctl -w vm.overcommit_memory=1 //为了使Redis正常工作,您需要设置一些内核选项,将 vm.overcommit_memory 设置为1,这意味着总是这样,这将避免数据被截断 vm.overcommit_memory = 1 [root@localhost src]# sysctl -w net.core.somaxconn=512. //将backlog连接的最大数量更改为比 redis.conf 的 tcp-backlog 选项的值(默认为511)更高的值,您可以在 kernel.org 网站上的基于sysctl的ip网络"tunning"中找到更多信息 sysctl: setting key "net.core.somaxconn": Invalid argument net.core.somaxconn = 512. [root@localhost src]# echo never > /sys/kernel/mm/transparent_hugepage/enabled //禁用透明的大页面支持,这已知会导致Redis的延迟和内存访问问题 [root@localhost src]# find /|grep redis.conf /usr/local/src/redis-5.0.5/redis.conf [root@localhost src]# cp /usr/local/src/redis-5.0.5/redis.conf /etc/redis/6379.conf //将样本 redis.conf 复制到 /etc/redis/6379.conf 中 [root@localhost redis-5.0.5]# vi /etc/redis/6379.conf #bind 127.0.0.1 protected-mode no daemonize no dir /usr/local/redis-5.0.5/data appendfilename "appendonly.aof" daemonize no pidfile /var/run/redis_6379.pid port 6379 loglevel notice logfile /var/log/redis_6379.log dir /var/lib/redis/6379 [root@localhost redis-5.0.5]# mkdir -p /usr/local/redis-5.0.5/data [root@localhost redis-5.0.5]# /usr/local/bin/redis-server & 14414:C 26 Sep 2019 07:34:18.107 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 14414:C 26 Sep 2019 07:34:18.107 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=14414, just started 14414:C 26 Sep 2019 07:34:18.107 # Warning: no config file specified, using the default config. In order to specify a config file use /usr/local/bin/redis-server /path/to/redis.conf 14414:M 26 Sep 2019 07:34:18.107 * Increased maximum number of open files to 10032 (it was originally set to 1024). _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 5.0.5 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 14414 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' 14414:M 26 Sep 2019 07:34:18.211 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. 14414:M 26 Sep 2019 07:34:18.211 # Server initialized 14414:M 26 Sep 2019 07:34:18.211 * Ready to accept connections //回车 [root@localhost redis-5.0.5]# pgrep -l redis 14526 redis-server [root@localhost redis-5.0.5]# find /|grep redis_init_script /usr/local/src/redis-5.0.5/utils/redis_init_script /usr/local/src/redis-5.0.5/utils/redis_init_script.tpl [root@localhost redis-5.0.5]# cp /usr/local/src/redis-5.0.5/utils/redis_init_script /etc/init.d/redis-5.0.5_6379 [root@localhost redis-5.0.5]# vi /etc/systemd/system/redis-5.0.5_6379.service [Unit] Description=Redis on port 6379 [Service] Type=forking ExecStart=/etc/init.d/redis-5.0.5_6379 start & ExecStop=/etc/init.d/redis-5.0.5_6379 stop & [Install] WantedBy=multi-user.target echo -e "vm.overcommit_memory = 1\nnet.core.somaxconn=512" >> /etc/sysctl.conf [root@localhost redis-5.0.5]# cat /etc/sysctl.conf # sysctl settings are defined through files in # /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/. # # Vendors settings live in /usr/lib/sysctl.d/. # To override a whole file, create a new file with the same in # /etc/sysctl.d/ and put new settings there. To override # only specific settings, add a file with a lexically later # name in /etc/sysctl.d/ and put new settings there. # # For more information, see sysctl.conf(5) and sysctl.d(5). vm.overcommit_memory = 1 net.core.somaxconn=512 [root@localhost redis-5.0.5]# echo "echo never > /sys/kernel/mm/transparent_hugepage/enabled" >> /etc/rc.local [root@localhost redis-5.0.5]# cat /etc/rc.local #!/bin/bash # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES # # It is highly advisable to create own systemd services or udev rules # to run scripts during boot instead of using this file. # # In contrast to previous versions due to parallel execution during boot # this script will NOT be run after all other services. # # Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure # that this script will be executed during boot. touch /var/lock/subsys/local echo never > /sys/kernel/mm/transparent_hugepage/enabled [root@localhost redis-5.0.5]# chmod +x /etc/rc.d/rc.local [root@localhost redis-5.0.5]# pkill redis-server [root@localhost redis-5.0.5]# pgrep -l redis* [root@localhost redis-5.0.5]# /etc/init.d/redis-5.0.5_6379 start & Starting Redis server.. //回车 [root@localhost ~]# ps -ef | grep redis root 1110 1061 0 08:17 pts/0 00:00:00 /bin/sh /etc/init.d/redis-5.0.5_6379 start root 1111 1110 3 08:17 pts/0 00:00:00 /usr/local/bin/redis-server *:6379 root 1116 1061 0 08:17 pts/0 00:00:00 grep --color=auto redis [root@localhost ~]# (cd /usr/local/bin/;./redis-cli) 127.0.0.1:6379> set foo bar OK 127.0.0.1:6379> get foo "bar" 127.0.0.1:6379> exit [root@localhost ~]# //firewall-cmd --zone=public --add-port=6379/tcp --permanent //firewall-cmd --reload
redis 客户端管理工具:Redis Desktop Manager
redis-clent-curl https://redisdesktop.com/
如下图:刚刚创建的foo库命令为bar
// du | sort | awk | sed | grep | egrep | tr | wc 管道抽样输出用法 // [root@localhost src]# du -alh /usr/local/redis-5.0.5/bin/|sort -k 2 '-' -d //显示文件占用资源按字母排列 32M /usr/local/redis-5.0.5/bin/ 4.2M /usr/local/redis-5.0.5/bin/redis-benchmark 7.8M /usr/local/redis-5.0.5/bin/redis-check-aof 7.8M /usr/local/redis-5.0.5/bin/redis-check-rdb 4.6M /usr/local/redis-5.0.5/bin/redis-cli 0 /usr/local/redis-5.0.5/bin/redis-sentinel 7.8M /usr/local/redis-5.0.5/bin/redis-server [root@localhost src]# du -alh /usr/local/redis-5.0.5/bin/|sort -k 2 '-' -d -o sort-redis.txt //将输出写入文件sort-redis.txt [root@localhost src]# cat sort.txt 32M /usr/local/redis-5.0.5/bin/ 4.2M /usr/local/redis-5.0.5/bin/redis-benchmark 7.8M /usr/local/redis-5.0.5/bin/redis-check-aof 7.8M /usr/local/redis-5.0.5/bin/redis-check-rdb 4.6M /usr/local/redis-5.0.5/bin/redis-cli 0 /usr/local/redis-5.0.5/bin/redis-sentinel 7.8M /usr/local/redis-5.0.5/bin/redis-server [root@localhost src]# du -alh /usr/local/redis-5.0.5/bin/|sort -hr //显示文件占用资源按多到少排列 32M /usr/local/redis-5.0.5/bin/ 7.8M /usr/local/redis-5.0.5/bin/redis-server 7.8M /usr/local/redis-5.0.5/bin/redis-check-rdb 7.8M /usr/local/redis-5.0.5/bin/redis-check-aof 4.6M /usr/local/redis-5.0.5/bin/redis-cli 4.2M /usr/local/redis-5.0.5/bin/redis-benchmark 0 /usr/local/redis-5.0.5/bin/redis-sentinel [root@localhost src]# du -alh /usr/local/redis-5.0.5/bin/|sort -h //显示文件占用资源按少到多排列 0 /usr/local/redis-5.0.5/bin/redis-sentinel 4.2M /usr/local/redis-5.0.5/bin/redis-benchmark 4.6M /usr/local/redis-5.0.5/bin/redis-cli 7.8M /usr/local/redis-5.0.5/bin/redis-check-aof 7.8M /usr/local/redis-5.0.5/bin/redis-check-rdb 7.8M /usr/local/redis-5.0.5/bin/redis-server 32M /usr/local/redis-5.0.5/bin/ [root@localhost src]# du -alh /usr/local/redis-5.0.5/bin/|sort -k 2 -t '-'|awk '{print $2}' |uniq|wc -l 7 [root@localhost src]# du -alh /usr/local/redis-5.0.5/bin/|sort -k 2 -t '-'|awk '{print $2}'| grep -v redis-cli /usr/local/redis-5.0.5/bin/ /usr/local/redis-5.0.5/bin/redis-benchmark /usr/local/redis-5.0.5/bin/redis-check-aof /usr/local/redis-5.0.5/bin/redis-check-rdb /usr/local/redis-5.0.5/bin/redis-sentinel /usr/local/redis-5.0.5/bin/redis-server [root@localhost src]# du -alh /usr/local/redis-5.0.5/bin/|sort -k 2 -t '-'|awk 'BEGIN{FS="/"}{print $6}'|sed '/^$/d' redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-sentinel redis-server [root@localhost src]# du -alh /usr/local/redis-5.0.5/bin/|sort -k 2 -t '-'|awk 'BEGIN{FS="-"}{print $0}'|sed '/^$/d' 32M /usr/local/redis-5.0.5/bin/ 4.2M /usr/local/redis-5.0.5/bin/redis-benchmark 7.8M /usr/local/redis-5.0.5/bin/redis-check-aof 7.8M /usr/local/redis-5.0.5/bin/redis-check-rdb 4.6M /usr/local/redis-5.0.5/bin/redis-cli 0 /usr/local/redis-5.0.5/bin/redis-sentinel 7.8M /usr/local/redis-5.0.5/bin/redis-server [root@localhost src]# du -alh /usr/local/redis-5.0.5/bin/|sort -k 2 -t '-'|awk 'BEGIN{FS="-"}{print $1}'|sed '/^$/d' 32M /usr/local/redis 4.2M /usr/local/redis 7.8M /usr/local/redis 7.8M /usr/local/redis 4.6M /usr/local/redis 0 /usr/local/redis 7.8M /usr/local/redis [root@localhost src]# du -alh /usr/local/redis-5.0.5/bin/|sort -k 2 -t '-'|awk 'BEGIN{FS="-"}{print $2}'|sed '/^$/d' 5.0.5/bin/ 5.0.5/bin/redis 5.0.5/bin/redis 5.0.5/bin/redis 5.0.5/bin/redis 5.0.5/bin/redis 5.0.5/bin/redis [root@localhost src]# du -alh /usr/local/redis-5.0.5/bin/|sort -k 2 -t '-'|awk 'BEGIN{FS="-"}{print $3}'|sed '/^$/d' benchmark check check cli sentinel server [root@localhost src]# du -alh /usr/local/redis-5.0.5/bin/|sort -k 2 -t '-'|awk 'BEGIN{FS="/"}{print $6}'|sed '/^$/d'|egrep 'redis-check-aof|redis-benchmark'|grep -v cli redis-benchmark redis-check-aof [root@localhost src]# du -alh /usr/local/redis-5.0.5/bin/|sort -k 2 -t '-'|awk 'BEGIN{FS="/"}{print $6}'|sed '/^$/d'|egrep 'redis-check-*'|grep -v rdb redis-check-aof [root@localhost src]# du -alh /usr/local/redis-5.0.5/bin/|sort -k 2 -t '-'|awk 'BEGIN{FS="-"}{print $1,$2,$3,$4,$5,$6}'|sed '/^$/d' 32M /usr/local/redis 5.0.5/bin/ 4.2M /usr/local/redis 5.0.5/bin/redis benchmark 7.8M /usr/local/redis 5.0.5/bin/redis check aof 7.8M /usr/local/redis 5.0.5/bin/redis check rdb 4.6M /usr/local/redis 5.0.5/bin/redis cli 0 /usr/local/redis 5.0.5/bin/redis sentinel 7.8M /usr/local/redis 5.0.5/bin/redis server [root@localhost src]# du -alh /usr/local/redis-5.0.5/bin/|sort -k 2 -t '-'|awk 'BEGIN{FS="/";OFS=" "}{print $1,$2,$3,$4,$5,$6,1234567,000,888}'|sed '/^$/d' 32M usr local redis-5.0.5 bin 1234567 0 888 4.2M usr local redis-5.0.5 bin redis-benchmark 1234567 0 888 7.8M usr local redis-5.0.5 bin redis-check-aof 1234567 0 888 7.8M usr local redis-5.0.5 bin redis-check-rdb 1234567 0 888 4.6M usr local redis-5.0.5 bin redis-cli 1234567 0 888 0 usr local redis-5.0.5 bin redis-sentinel 1234567 0 888 7.8M usr local redis-5.0.5 bin redis-server 1234567 0 888 [root@localhost src]# du -alh /usr/local/redis-5.0.5/bin/|sort -k 2 -t '-'|awk 'BEGIN{FS="/";OFS=" "}{print $1,$2,$3,$4,$5,$6,1234567,000,888}'|sed '/^$/d'|tr " " ";" 32M ;usr;local;redis-5.0.5;bin;;1234567;0;888 4.2M ;usr;local;redis-5.0.5;bin;redis-benchmark;1234567;0;888 7.8M ;usr;local;redis-5.0.5;bin;redis-check-aof;1234567;0;888 7.8M ;usr;local;redis-5.0.5;bin;redis-check-rdb;1234567;0;888 4.6M ;usr;local;redis-5.0.5;bin;redis-cli;1234567;0;888 0 ;usr;local;redis-5.0.5;bin;redis-sentinel;1234567;0;888 7.8M ;usr;local;redis-5.0.5;bin;redis-server;1234567;0;888 [root@localhost src]# du -alh /usr/local/redis-5.0.5/bin/|sort -k 2 -t '-'|awk 'BEGIN{FS="/";OFS=" "}{print $1,$2,$3,$4,$5,$6,1234567,000,888}'|sed '/^$/d'|tr " " "|" 32M |usr|local|redis-5.0.5|bin||1234567|0|888 4.2M |usr|local|redis-5.0.5|bin|redis-benchmark|1234567|0|888 7.8M |usr|local|redis-5.0.5|bin|redis-check-aof|1234567|0|888 7.8M |usr|local|redis-5.0.5|bin|redis-check-rdb|1234567|0|888 4.6M |usr|local|redis-5.0.5|bin|redis-cli|1234567|0|888 0 |usr|local|redis-5.0.5|bin|redis-sentinel|1234567|0|888 7.8M |usr|local|redis-5.0.5|bin|redis-server|1234567|0|888 [root@localhost src]# du -alh /usr/local/redis-5.0.5/bin/|sort -k 2 -t '-'|awk 'BEGIN{FS="/";OFS=" "}{print $1,$2,$3,$4,$5,$6,1234567,000,888}'|sed '/^$/d'|tr " " "|"|tr "|" " " 32M usr local redis-5.0.5 bin 1234567 0 888 4.2M usr local redis-5.0.5 bin redis-benchmark 1234567 0 888 7.8M usr local redis-5.0.5 bin redis-check-aof 1234567 0 888 7.8M usr local redis-5.0.5 bin redis-check-rdb 1234567 0 888 4.6M usr local redis-5.0.5 bin redis-cli 1234567 0 888 0 usr local redis-5.0.5 bin redis-sentinel 1234567 0 888 7.8M usr local redis-5.0.5 bin redis-server 1234567 0 888 // du | sort | awk | sed | grep | egrep | tr | wc 管道抽样输出用法 //
kings-dev
各路大神,求带飞有什么建议敬请留言。QQ:861996013,李辉 。转载请注明,谢谢。