redis环境安装
大约 1 分钟
redis环境安装
此安装教程仅适合ubuntu和debian 此安装教程为源码安装 执行此安装时务必创建对应文件夹
安装
下载源码
首先下载对应的redis源码安装包
wget https://download.redis.io/redis-stable.tar.gz
解压
tar -xzvf redis-stable.tar.gz
cd redis-stable
make
安装
make install
执行
redis-server
注意安装到此只是安装该软件并无将其加入系统服务当中
系统服务加入
进入目录,执行安装服务脚本
cd /home/software/redis-stable/utils
./install_server.sh
如果出现:
Welcome to the redis service installer
This script will help you easily set up a running redis server
This systems seems to use systemd.
Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!
则进入脚本
vim ./install_server.sh
注释以下代码之后,按需求更改对应配置
#bail if this system is managed by systemd
#_pid_1_exe="$(readlink -f /proc/1/exe)"
#if [ "${_pid_1_exe##*/}" = systemd ]
#then
# echo "This systems seems to use systemd."
# echo "Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!"
# exit 1
#fi
再次运行
./install_server.sh
然后创建系统服务
vim /lib/systemd/system/redis.service
文件内容:(在添加之前确保/etc/init.d/redis_6379存在并且可用,认定前缀即可)
[Unit]
Description=redis
After=network.target
[Service]
Type=forking
ExecStart=/etc/init.d/redis_6379 start
ExecStop=/etc/init.d/redis_6379 stop
ExecReload=/etc/init.d/redis_6379 restart
PrivateTmp=true
[Install]
WantedBy=multi-user.target
保存之后执行:
systemctl daemon-reload
systemctl enable redis
systemctl start redis
systemctl status redis
出现:
redis.service - redis
Loaded: loaded (/lib/systemd/system/redis.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2023-07-03 13:49:57 CST; 14min ago
Main PID: 340752 (redis-server)
Tasks: 5 (limit: 9352)
Memory: 2.6M
CGroup: /system.slice/redis.service
└─340752 /usr/local/bin/redis-server 127.0.0.1:6379
7月 03 13:49:57 fyh-MS-7A15 systemd[1]: Starting redis...
7月 03 13:49:57 fyh-MS-7A15 redis_6379[340750]: Starting Redis server...
7月 03 13:49:57 fyh-MS-7A15 systemd[1]: Started redis.
即为成功