apt 安装redis-server $ sudo apt search redis-server$ sudo apt install redis-server -y #安装# 安装redis查看服务进程webrx@us:~$ sudo systemctl status redis-server● redis-server.service - Advanced key-value store Loaded: loaded (
apt 安装redis-server
$ sudo apt search redis-server $ sudo apt install redis-server -y #安装 # 安装redis查看服务进程 webrx@us:~$ sudo systemctl status redis-server ● redis-server.service - Advanced key-value store Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled) Active: active (running) since Mon 2021-12-06 11:35:38 CST; 23s ago Docs: http://redis.io/documentation, man:redis-server(1) Main PID: 4990 (redis-server) Tasks: 4 (limit: 4583) Memory: 2.0M CGroup: /system.slice/redis-server.service └─4990 /usr/bin/redis-server 127.0.0.1:6379 12月 06 11:35:38 us systemd[1]: Starting Advanced key-value store... 12月 06 11:35:38 us systemd[1]: redis-server.service: Can't open PID file /run/redis/redis-server.pid (yet?) after start: Operatio> 12月 06 11:35:38 us systemd[1]: Started Advanced key-value store. webrx@us:~$ ps -ef | grep redis redis 4990 1 0 11:35 ? 00:00:00 /usr/bin/redis-server 127.0.0.1:6379 webrx 5292 1192 0 11:37 pts/0 00:00:00 grep --color=auto redis webrx@us:~$ ## 查看redis版本信息 webrx@us:~$ redis-server -v Redis server v=5.0.7 sha=00000000:0 malloc=jemalloc-5.2.1 bits=64 build=636cde3b5c7a3923 webrx@us:~$ redis-cli --version redis-cli 5.0.7 webrx@us:~$ redis-server --version Redis server v=5.0.7 sha=00000000:0 malloc=jemalloc-5.2.1 bits=64 build=636cde3b5c7a3923 ## 使用客户端登录连接redis 默认端口号 6379 webrx@us:~$ redis-cli -h localhost -p 6379 localhost:6379> get n "18" localhost:6379> exit webrx@us:~$ redis-cli 127.0.0.1:6379> get n "18" 127.0.0.1:6379> ping PONG 127.0.0.1:6379> ## 设置远程访问 编辑/etc/redis/redis.conf 注释 127.0.0.1 保护设置为 no webrx@us:~$ ls /lib/systemd/system/redis-server.service /lib/systemd/system/redis-server.service webrx@us:~$ cat /lib/systemd/system/redis-server.service [Unit] Description=Advanced key-value store After=network.target Documentation=http://redis.io/documentation, man:redis-server(1) [Service] Type=forking ExecStart=/usr/bin/redis-server /etc/redis/redis.conf PIDFile=/run/redis/redis-server.pid TimeoutStopSec=0 Restart=always User=redis Group=redis RuntimeDirectory=redis RuntimeDirectoryMode=2755 UMask=007 PrivateTmp=yes LimitNOFILE=65535 PrivateDevices=yes ProtectHome=yes ReadOnlyDirectories=/ ReadWritePaths=-/var/lib/redis ReadWritePaths=-/var/log/redis ReadWritePaths=-/var/run/redis NoNewPrivileges=true CapabilityBoundingSet=CAP_SETGID CAP_SETUID CAP_SYS_RESOURCE MemoryDenyWriteExecute=true ProtectKernelModules=true ProtectKernelTunables=true ProtectControlGroups=true RestrictRealtime=true RestrictNamespaces=true RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX # redis-server can write to its own config file when in cluster mode so we # permit writing there by default. If you are not using this feature, it is # recommended that you replace the following lines with "ProtectSystem=full". ProtectSystem=true ReadWriteDirectories=-/etc/redis [Install] WantedBy=multi-user.target Alias=redis.service webrx@us:~$源码编译安装6.2.6
$ sudo apt install gcc make -y $ wget https://download.redis.io/releases/redis-6.2.6.tar.gz $ tar xzf redis-6.2.6.tar.gz $ cd redis-6.2.6 $ make $ cd src #只显示可执行的程序 $ ls -F | grep "*" webrx@us:~/redis-6.2.6/src$ ls -F | grep '*' mkreleasehdr.sh* redis-benchmark* redis-check-aof* redis-check-rdb* redis-cli* redis-sentinel* redis-server* redis-trib.rb*redis.io下载
tar解压
cd make install 安装
$ cd redis-6.2.6 $ sudo make PREFIX=/usr/local/redis install建立data logs conf
修改配置/usr/local/redis/conf/redis.conf 文件
75 bind 127.0.0.1 -::1 注释此行 #bind 127.0.0.1 -::1 94 protected-mode yes 修改为 protected-mode no 98 port 6379 此行不用修改 257 daemonize no 修改为 daemonize yes 289 pidfile /var/run/redis_6379.pid 此行不变和/etc/systemd/system/redis.service内容一样 302 logfile "" 修改为 logfile "/usr/local/redis/logs/redis.log" 431 dbfilename dump.rdb #此行不变,为数据库名 454 #dir ./ 修改为 dir /usr/local/redis/data/ 901 # requirepass foobared 修改为取消注释,设置密码 requirepass 123456 #/usr/local/redis/redis_6379.conf #导入默认配置文件(公共配置) include /usr/local/redis/redis.conf protected-mode no #服务器端口号 port 6379 daemonize yes #服务器进程文件 pidfile /var/run/redis_6379.pid #日志文件 logfile "/usr/local/redis/6379.log" #数据库文件 dbfilename dump_6379.rdb #数据库dump_6379.rdb文件所在的目录 dir /usr/local/redis/ #密码 requirepass 123456建立/redis.service服务配置文件
#建立文件 sudo vim /etc/systemd/system/redis6380.service #内容如下: [Unit] Description=Advanced key-value store After=network.target [Service] Type=forking ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/conf/redis.conf ExecStop=/bin/kill -s TERM $MAINPID PIDFile=/var/run/redis_6379.pid Restart=always RestartSec=5s Restart=on-failure [Install] WantedBy=multi-user.target Alias=redis.service安装启动服务
#别名 $ alias redis='/usr/local/redis/bin/redis-cli' #redis客户端登录 -h 主机 -p 端口 -n 数据库代号 -a $ redis -h localhost -p 6379 -n 0 -a 123456redis安装步骤
1、sudo apt install gcc make pkg-config -y 2、wget https://download.redis.io/releases/redis-6.2.6.tar.gz 3、tar -zxvf redis-6.2.6.tar.gz 4、cd redis-6.2.6 5、sudo make PREFIX=/usr/local/redis install #编译安装后,可执行的程序在 /usr/local/redis/bin 目录 redis-server 服务器 redis-cli客户端 6、sudo cp redis.conf /usr/local/redis #复制配置文件到 /usr/local/redis 7、sudo ln -s /usr/local/redis/bin/redis-cli /usr/bin/redis #建立软连接,就是快捷方式,可以直接输入redis客户端登录服务器 #cd /usr/local/redis/bin 目录下 # ./redis-cli 才能登录 8、编辑sudo vim /usr/local/redis/redis.conf 75 bind 127.0.0.1 -::1 注释此行 #bind 127.0.0.1 -::1 94 protected-mode yes 修改为 protected-mode no 98 port 6379 此行不用修改 257 daemonize no 修改为 daemonize yes 289 pidfile /var/run/redis_6379.pid 此行不变和/etc/systemd/system/redis.service内容一样 302 logfile "" 修改为 logfile "/usr/local/redis/logs/redis.log" 431 dbfilename dump.rdb #此行不变,为数据库名 454 #dir ./ 修改为 dir /usr/local/redis/data/ 901 # requirepass foobared 修改为取消注释,设置密码 requirepass 123456 9、建立服务文件 sudo vim /etc/systemd/system/redis.service #建立文件 sudo vim /etc/systemd/system/redis.service #内容如下: [Unit] Description=Advanced key-value store After=network.target [Service] Type=forking ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf ExecStop=/bin/kill -s TERM $MAINPID PIDFile=/var/run/redis_6379.pid Restart=always RestartSec=5s Restart=on-failure [Install] WantedBy=multi-user.target Alias=redis.service 10、sudo systemctl enable redis.service #将redis服务器设置开机启动 sudo systemctl start redis #直接手动启动redis服务 sudo systemctl status redis #可以查看redis服务状态 #查看redis相关的进程 ps -ef | grep redis root 826 1 0 12月09 ? 00:01:19 /usr/local/redis/bin/redis-server *:6379 root 1348 1 0 12月09 ? 00:01:21 ./redis-server *:6380 webrx 24789 24774 0 10:55 pts/0 00:00:00 grep --color=auto redis 11、redis 回车 默认是本机 localhost 端口6379 -n 0 127.0.0.1>ping PONG 127.0.0.1>shutdown #给服务器发送一个关闭命令 #临时关闭服务,下次开机redis自动启动 sudo systemctl stop redis 【本文来源:武汉seo公司 http://www.5h5q.com复制请保留原URL】