[Redis] How to install Redis manually in Centos7, simple installation

Installation package

Manual official website download

redis-4.0.1.tar.gz
demonstrates the version of redis

download using wget

# centos 自带了wget
wget http://download.redis.io/releases/redis-4.0.1.tar.gz

Installation Environment

Install the environment components, the installation of redis is often abnormal, because the environment is not installed;

yum -y install gcc gcc-c++

Install Redis

Installation directory settings

Ready to install to /usr/local unified management

#新建 /usr/local/redis 文件夹
mkdir /usr/local/redis

#在安装包复制安装包至 安装目录
cp redis-4.0.1.tar.gz /usr/local/redis 

cd  /usr/local/redis 
#解压安装包
tar -zxvf redis-4.0.1.tar.gz

insert image description here

Install

#准备开始安装
cd redis-4.0.1
#开始编译安装
make
#开始安装
make install

insert image description here
The picture above indicates that the installation is successful,
you can customize the installation to another folder

Common commands

#内网端口开放,这里不提示了,正式服务器只需要开放安装组的端口即可
#进入安装目录
cd /usr/local/redis/redis-4.0.1
#修改默认配置文件
vim /usr/local/redis/redis-4.0.1/redis.conf
#运行redis
redis-server /usr/local/redis/redis-4.0.1/redis.conf
#查看nginx是否已运行
ps -ef|grep redis

#设置后台启动
#编辑 redis.conf 文件,将 daemonize 修改为yes

Set up autostart

#编辑文件 redis.service
vi /lib/systemd/system/redis.service
##----------------------输入以下内容-----------------------------##
[Unit]
Description=redis
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/redis/redis-4.0.1/redis-server /usr/local/redis/redis-4.0.1/redis.conf
PrivateTmp=true

[Install]
WantedBy=multi-user.target
##----------------------输入以上内容-----------------------------##

# 以上内容描述
#Description:描述服务
#After:描述服务类别
#[Service]服务运行参数的设置
#Type=forking是后台运行的形式
#ExecStart为服务的具体运行命令
#ExecReload为重启命令
#ExecStop为停止命令
#PrivateTmp=True表示给服务分配独立的临时空间
#注意:[Service]的启动、重启、停止命令全部要求使用绝对路径
#[Install]运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3

just save

#启动redis服务 
systemctl start redis.service 
#设置开机自启动 
systemctl enable redis.service
#停止开机自启动 
systemctl disable redis.service 
#查看服务当前状态 
systemctl status redis.service 
#重新启动服务 
systemctl restart redis.service 
#查看所有已启动的服务 
systemctl list-units --type=service

Guess you like

Origin blog.csdn.net/qq_1498869403/article/details/131373324