以下部分的具体略:

1.wget获取源码

2.make

这里重点说下,如何使用 utils/install_server.sh脚本

使用install_service.sh添加服务

有了这个脚本,那么配置和安装为单机服务就很容易了,因为这个脚本:

1.手动提示输入多个配置参数,对于开发环境快速配置也是不错的选择,因为甚至不需要打开redis.conf文件,并亲自修改它。

2.安装一个服务叫redis_port的服务,如果port=8933 ,那么服务就叫redis_8933

当然,我们可以修改 install_server.sh脚本,生成不一样的服务名称。

注:这个不是一个推荐的方式,毕竟upstart是一个比较反人性的方式,最好还是直接看后文:使用systemctl 添加服务

linux加入systemctl就已经严重地意识到人性化的重要性。

由于是centos7,有systemctl组件,所以执行前得修改下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

之后,进入utils目录,执行

./install_server.sh

输入和输出如下:

[root@lzf-ty 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!
[root@lzf-ty utils]# ./install_server.sh
Welcome to the redis service installer
This script will help you easily set up a running redis server Please select the redis port for this instance: [9736]
Selecting default: 9736
Please select the redis config file name [/etc/redis/9736.conf] /soft/redis-6.2.6/src/redis.conf
Please select the redis log file name [/var/log/redis_9736.log]
Selected default - /var/log/redis_9736.log
Please select the data directory for this instance [/var/lib/redis/9736] /soft/redis-6.2.6/data
Please select the redis executable path [] /soft/redis-6.2.6/src/redis-server
Selected config:
Port : 9736
Config file : /soft/redis-6.2.6/src/redis.conf
Log file : /var/log/redis_9736.log
Data dir : /soft/redis-6.2.6/data
Executable : /soft/redis-6.2.6/src/redis-server
Cli Executable : /soft/redis-6.2.6/src/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/9736.conf => /etc/init.d/redis_9736
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!

使用chkconfig查看下安装好得服务

[root@lzf-ty utils]# chkconfig --list 

Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration. If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'. mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
redis_9736 0:off 1:off 2:on 3:on 4:on 5:on 6:off

最后启动,并验证下服务

[root@lzf-ty utils]# systemctl status redis_9736
● redis_9736.service - LSB: start and stop redis_9736
Loaded: loaded (/etc/rc.d/init.d/redis_9736; bad; vendor preset: disabled)
Active: active (exited) since Wed 2021-11-10 13:46:12 CST; 9s ago
Docs: man:systemd-sysv-generator(8)
Process: 5677 ExecStart=/etc/rc.d/init.d/redis_9736 start (code=exited, status=0/SUCCESS)
[root@lzf-ty src]# ./redis-cli -p 9736
127.0.0.1:9736> set lan java
OK
127.0.0.1:9736> get java
(nil)
127.0.0.1:9736> get lan
"java"
127.0.0.1:9736>

再看看redis日志,真得很贴心!!!

[root@lzf-ty log]# cat redis_9736.log
5632:C 10 Nov 2021 13:44:22.370 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
5632:C 10 Nov 2021 13:44:22.370 # Redis version=6.2.6, bits=64, commit=00000000, modified=0, pid=5632, just started
5632:C 10 Nov 2021 13:44:22.370 # Configuration loaded
5632:M 10 Nov 2021 13:44:22.371 * Increased maximum number of open files to 10032 (it was originally set to 1024).
5632:M 10 Nov 2021 13:44:22.371 * monotonic clock: POSIX clock_gettime
5632:M 10 Nov 2021 13:44:22.371 * Running mode=standalone, port=9736.
5632:M 10 Nov 2021 13:44:22.371 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
5632:M 10 Nov 2021 13:44:22.371 # Server initialized
5632:M 10 Nov 2021 13:44:22.371 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
5632:M 10 Nov 2021 13:44:22.372 * Ready to accept connections

这样,一个单机redis很快就完成了,当然,这些还是不够自动化,如果有必要可以全部编写为一个完全自动安装得脚本,从而至少可以节约30分钟以上!

 

使用systemctl 添加服务

毕竟init.d已经是比较落后的方式,centos/linux会逐渐使用systemctl来控制服务,所以可以使用systemctl来添加注册服务。

如何使用sytemctl注册服务,可以参阅 https://www.jianshu.com/p/79059b06a121

注意:systemctl可以管理两个配置的服务upstart(init.d)和systemd(....service)

在centos7.6中,查看系统服务都是systemd模式的:

这个版本的redis也很贴心地给了一个systemctl服务的模板,分单机和集群的,我们来看下单机的模板:

systemd-redis_server.service

# example systemd service unit file for redis-server
#
# In order to use this as a template for providing a redis service in your
# environment, _at the very least_ make sure to adapt the redis configuration
# file you intend to use as needed (make sure to set "supervised systemd"), and
# to set sane TimeoutStartSec and TimeoutStopSec property values in the unit's
# "[Service]" section to fit your needs.
#
# Some properties, such as User= and Group=, are highly desirable for virtually
# all deployments of redis, but cannot be provided in a manner that fits all
# expectable environments. Some of these properties have been commented out in
# this example service unit file, but you are highly encouraged to set them to
# fit your needs.
#
# Please refer to systemd.unit(5), systemd.service(5), and systemd.exec(5) for
# more information. [Unit]
Description=Redis data structure server
Documentation=https://redis.io/documentation
#Before=your_application.service another_example_application.service
#AssertPathExists=/var/lib/redis
Wants=network-online.target
After=network-online.target [Service]
ExecStart=/usr/local/bin/redis-server --supervised systemd --daemonize no
## Alternatively, have redis-server load a configuration file:
#ExecStart=/usr/local/bin/redis-server /path/to/your/redis.conf
LimitNOFILE=10032
NoNewPrivileges=yes
#OOMScoreAdjust=-900
#PrivateTmp=yes
Type=notify
TimeoutStartSec=infinity
TimeoutStopSec=infinity
UMask=0077
#User=redis
#Group=redis
#WorkingDirectory=/var/lib/redis [Install]
WantedBy=multi-user.target

如果不修改以上文件,则必须把redis.conf放在/etc下,否则会找不到。

如果不想放在/etc下,那么则必须修改redis.conf配置文件,并在配置文件中指定两个选项:

supervised   -- 监护方式

daemonize   -- 守护

来看下样例redis.conf中,关于这个参数的说明:

# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
# When Redis is supervised by upstart or systemd, this parameter has no impact.
# 中文大意:默认不使用守护模式(kill它都会困难,因为会反复重启)。如果使用 systemd的监管方式,那么这个参数如何设置无所谓
daemonize no # If you run Redis from upstart or systemd, Redis can interact with your
# supervision tree. Options:
# supervised no - no supervision interaction --没有交互,不能使用友好的命令的开启,查看,关闭,当然kill之类是可以的。
# supervised upstart - signal upstart by putting Redis into SIGSTOP mode -- upstart,传统的监管方式,就是创建init.d之类的文件
# requires "expect stop" in your upstart job config
# supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET -- centos7之后的新潮监管模式,这是系统推荐的
# on startup, and updating Redis status on a regular
# basis.
# supervised auto - detect upstart or systemd method based on
# UPSTART_JOB or NOTIFY_SOCKET environment variables --自动模式,就看有没有配置环境变量UPSTART_JOB 或者NOTIFY_SOCKET
# Note: these supervision methods only signal "process is ready."
# They do not enable continuous pings back to your supervisor.
#
# The default is "no". To run under upstart/systemd, you can simply uncomment
# the line below:
#
# supervised auto

换言之,上面这一段,可以简化为两条(如果要使用systemctl)

# daemonize 不设置也无所谓

daemonize no 
supervised systemd

当redis.conf中做了如上配置之后,则可以在systemd-redis_server.service,如下操作

[Service]
# 注释掉下面这一句,因为我没有把redis.conf放在/etc下

# ExecStart=/usr/local/bin/redis-server --supervised systemd --daemonize no
## Alternatively, have redis-server load a configuration file:
# 使用下面这个,因为我已经在redis.conf中设置了 daemonize,supervised两个参数
ExecStart=/usr/local/bin/redis-server /path/to/your/redis.conf

天翼云centos7.6安装redis6.2.6的更多相关文章

  1. 阿里云CentOS7.x安装nodejs及pm2

    对之前文章的修订 您将了解 CentOS下如何安装nodejs CentOS下如何安装NVM CentOS下如何安装git CentOS下如何安装pm2 适用对象 本文档介绍如何在阿里云CentOS系 ...

  2. 阿里云CentOs7上安装Tomcat

    一.下载安装tomcat8 cd /usr/ #创建tomcat目录 mkdir tomcat #从网上download 压缩包 wget tomcat8 url #解压 tar -zxvf apac ...

  3. 阿里云 Centos7.3安装mysql5.7.18 rpm安装

    卸载MariaDB CentOS7默认安装MariaDB而不是MySQL,而且yum服务器上也移除了MySQL相关的软件包.因为MariaDB和MySQL可能会冲突,故先卸载MariaDB. 1.安装 ...

  4. 阿里云centos7成功安装和启动nginx,但是外网访问不了的解决方案

    问题环境: 阿里云centos7.4.1708 问题描述:成功配置,启动成功,外网访问不了 解决方案: 经过查阅文档,去阿里云后台查看,原来是新购的服务器都加入和实例安全组. (OMG)立即去配置.加 ...

  5. 阿里云CentOS-7.2安装mysql

    我下载的阿里云的服务器系统centos7.2是纯内核版本,并没有其他的工具,所以这个系统是非常干净的.所以我就需要给系统安装一一些工具,来方便系统的管理与操作,我们上面讲到了关于服务器的yum的配置在 ...

  6. 腾讯云centos7.2安装jdk1.7 tomcat7.0部署项目示例

    说实话win server的性能并不好,所以程序员必须会在Linux上安装环境,部署项目. 第一步,官网下载tomcat和jdk压缩文件*.tar.gz  下载路径如下: jdk:http://www ...

  7. 阿里云CentOs7上安装GitLab

    一.安装 基本上可以根据官网的教程来安装:https://www.gitlab.com.cn/installation/#centos-7 只不过我们暂时没有邮件服务器,所以postfix没有安装. ...

  8. centos7 编译安装 redis-6.0.5

    安装redis sudo yum install redis centos自带的redis才3.2 太旧了所以使用源码编译 需要先安装gcc新版才能编译 centos7 默认的 gcc 版本为:4.8 ...

  9. 腾讯云centos7.2安装宝塔面板和LAMP

    1.安装好centos7.2系统后,登录centos系统输入如下命令: yum install -y wget && wget -O install.sh http://downloa ...

  10. 腾讯云centos7.2安装mysql5.7

    一.查看是否安装mysql rpm -qa | grep mysql 什么都没显示,说明没有安装 二.进入到opt目录下,使用wget下载官方yum源的rpm包 cd /opt wget https: ...

随机推荐

  1. WPF 基于 .NET 5 框架和 .NET 6 的 SDK 进行完全单文件发布

    本文来告诉大家如何基于 .NET 5 框架和 .NET 6 SDK 进行完全单文件发布,这是对 WPF 应用程序进行独立发布,生成的是完全单文件的方法 在之前的版本,尽管也是基于 .NET 5 框架的 ...

  2. WPF 如何在静态资源定义字体大小

    默认的 WPF 的字体大小的单位是像素,如果想要将字体大小使用 pt 点表示,写在 xaml 里面是直接添加 pt 后缀.但是此时如果在静态资源尝试定义的时候写上了 pt 将会在运行的时候提示无法转换 ...

  3. vue项目中element-ui等UI组件自定义样式不生效的解决

    引 在使用element-ui的时候虽然默认的样式已经能够满足很多的需求了,但是有总是有时候要加上些自定义的需求.不过,有的时候样式写上去了,按理说应该是没错的,但却是不生效呢. 其实在vue项目中使 ...

  4. 2.生产环境k8s-1.28.2集群小版本升级到1.28.5

    环境:https://www.cnblogs.com/yangmeichong/p/17956335 # 流程:先升级master,再升级node # 1.备份组件参考:https://kuberne ...

  5. golang向上取整、向下取整和四舍五入

    一.概述 官方的math 包中提供了取整的方法,向上取整math.Ceil() ,向下取整math.Floor() 二.用法 package main import ( "fmt" ...

  6. Vue-Plugin-HiPrint

    Vue-Plugin-HiPrint 是一个Vue.js的插件,旨在提供一个简单而强大的打印解决方案.通过 Vue-Plugin-HiPrint,您可以轻松地在Vue.js应用程序中实现高度定制的打印 ...

  7. Chrome 浏览器插件 Manifest.json V3 中权限(Permissions)字段解析

    一.权限(Permissions) 再使用拓展程序的 API 时,大多数的时候,需要在 manifest.json 文件中声明 permissions 字段. 一.权限类型 在 V3 版本中可以声明以 ...

  8. 常回家看看之off_by_one

    off_by_one这个漏洞比较特殊,它不像上一期的堆溢出,可以溢出很多字节,它只能溢出一个字节,在栈里面也可以通过这个漏洞修改返回地址什么的,在堆里面我们主要利用它来修改堆块的大小,形成fake_c ...

  9. PasteSpider之appsettings.json中的Serilog的配置,分流不同日志层级的信息!

    在实际使用Serilog中,我们通常会有不一样的需求,常见的比如 1.按照等级,高级哪个等级的才记录 2.记录文件每个多大,超过的划分到下一个文件中 3.不同等级的记录到不同的位置中 4.按照不一样的 ...

  10. sass语法嵌套规则与注释讲解

    语法嵌套规则 选择器嵌套 例如有这么一段css,正常CSS的写法 .container{width:1200px; margin: 0 auto;} .container .header{height ...