如何在FreeBSD11或者FreeBSD12上安装Redis 5.x


原文地址:如何在FreeBSD11或者FreeBSD12上安装Redis 5.x

本篇分享如何在FreeBSD上安装Redis,以及如何将Redis注册为系统服务使用service命令管理,包括redis在FreeBSD系统中开机启动。

最近在FreeBSD上安装MySQL和Nginx时一起把Redis安装了,本篇记录一下如何在FreeBSD上安装Redis。过程也非常简单,几个命令即可安装完成。

1.更新FreeBSD的仓库(ports)

输入下面的命令即可更新仓库,更新仓库源之后有很多软件的新版本,同时也保留旧版本。

portsnap fetch update

提示:更新如果很慢的话可以更改一下FreeBSD的源,可以直接在本站搜索“FreeBSD更换仓库源”。网上很多人说FreeBSD的仓库源只能用官方的,其实不然。

2.直接使用pkg命令安装Redis

在使用pkg安装nginx之前可以搜索一下有哪些Redis版本可以安装,运行以下命令:

pkg search redis

输出如下,可以看到和redis相关的软件很多,在这里可以带上redis版本,例如redis5或者redis-5。

credis-0.2.3                   Library for communicating with Redis servers
erlang-eredis-1.1.0            Non-blocking Redis client for Erlang
hiredis-0.13.3                 Minimalistic C client library for the Redis database
lua-resty-redis-0.27_1         Redis client driver for the ngx_lua nginx module
nagios-check_redis-0.1_1       Nagios plugin to check redis server
p5-AnyEvent-Redis-0.24_2       Non-blocking Redis client written in Perl
p5-CHI-Driver-Redis-0.10       Redis driver for CHI
p5-Dancer-Plugin-Redis-0.8_1   Redis database connector for Dancer
p5-Redis-1.9950                Perl binding for Redis database
p5-Redis-Fast-0.26             Perl binding for Redis database
p5-Redis-JobQueue-1.19         Job queue management implemented using Redis server
p5-Redis-RateLimit-1.0002      Sliding window rate limiting with Redis
p5-Redis-hiredis-0.11.0_2      Simple wrapper around hiredis C client
p5-RedisDB-2.53                Perl extension to access redis database
p5-RedisDB-Parser-2.22         Perl extension for Redis protocol parser
p5-Test-Mock-Redis-0.22        Use in place of Redis for unit testing
php72-pecl-redis-5.3.1         Extension to access Redis
php73-pecl-redis-5.3.1         Extension to access Redis
php74-pecl-redis-5.3.1         Extension to access Redis
py27-hiredis-0.2.0             Python extension that wraps hiredis
py27-redis-3.5.3               Python client for Redis key-value store
py27-redis2-2.10.6_1           Python client for Redis key-value store
py27-txredisapi-1.4.7          Non-blocking redis client for python
py37-aioredis-1.3.1            Python asyncio (PEP 3156) Redis client library
py37-azure-mgmt-redis-7.0.0.r1 Microsoft Azure Redis Cache Management Client Library for Python
py37-django-redis-4.12.1       Full featured Redis cache/session backend for Django
py37-fakeredis-1.4.3           Fake version of databases/py-redis for unit testing
py37-hiredis-0.2.0             Python extension that wraps hiredis
py37-redis-3.5.3               Python client for Redis key-value store
py37-redis2-2.10.6_1           Python client for Redis key-value store
py37-txredisapi-1.4.7          Non-blocking redis client for python
redis-5.0.9                    Persistent key-value database with built-in net interface
redis-devel-6.0.8.20200910     Persistent key-value database with built-in net interface
redis4-4.0.14_1                Persistent key-value database with built-in net interface
redis_exporter-1.10.0          Prometheus exporter for redis stats
redisearch-1.6.14              Full-text search over Redis
rubygem-azure_mgmt_redis-0.17.4 Microsoft Azure Redis Management Client Library for Ruby
rubygem-brpoplpush-redis_script-0.1.1 Bring your own LUA scripts into redis
rubygem-em-redis-unified-1.0.1 Eventmachine-based implementation of the Redis protocol
rubygem-hiredis-0.6.3_3        Ruby wrapper for hiredis
rubygem-mario-redis-lock-1.2.1 Ruby distributed lock using Redis, with emphasis in transparency
rubygem-openid-redis-store-0.0.2_1 Redis store for OpenID
rubygem-peek-redis-rails52-1.2.0 Provide a peek into the Redis calls made
rubygem-redis-4.2.2            Ruby client library for Redis, the key value storage server
rubygem-redis-actionpack-5.2.0 Redis session store for ActionPack
rubygem-redis-actionpack-rails5-5.2.0 Redis session store for ActionPack
rubygem-redis-actionpack-rails50-5.2.0 Redis session store for ActionPack
rubygem-redis-actionpack-rails52-5.2.0 Redis session store for ActionPack
rubygem-redis-actionpack-rails60-5.2.0 Redis session store for ActionPack
rubygem-redis-activesupport-5.2.0 Redis store for ActiveSupport::Cache
rubygem-redis-activesupport-rails5-5.2.0 Redis store for ActiveSupport::Cache
rubygem-redis-activesupport-rails50-5.2.0 Redis store for ActiveSupport::Cache
rubygem-redis-activesupport-rails52-5.2.0 Redis store for ActiveSupport::Cache
rubygem-redis-activesupport-rails60-5.2.0 Redis store for ActiveSupport::Cache
rubygem-redis-namespace-1.8.0  Ruby client class for Redis with namespace support
rubygem-redis-namespace16-1.6.0 Ruby client class for Redis with namespace support
rubygem-redis-namespace17-1.7.0 Ruby client class for Redis with namespace support
rubygem-redis-rack-2.1.2       Redis Store for Rack
rubygem-redis-rack1-1.6.0_1    Redis Store for Rack
rubygem-redis-rails-5.0.2      Redis for Ruby on Rails
rubygem-redis-rails-rails5-5.0.2 Redis for Ruby on Rails
rubygem-redis-rails-rails50-5.0.2 Redis for Ruby on Rails
rubygem-redis-rails-rails52-5.0.2 Redis for Ruby on Rails
rubygem-redis-rails-rails60-5.0.2 Redis for Ruby on Rails
rubygem-redis-store-1.5.0      Namespaced Redis stores for Ruby web frameworks
rubygem-uri-redis-0.4.2        Support for parsing redis://host:port/dbindex/keyname

该列表有redis5和redis4,我们安装最新的:

pkg install redis

3.检查Redis是否安装成功

运行如下命令检查redis是否安装成功

redis-server --version

输出:

Redis server v=5.0.9 sha=00000000:0 malloc=libc bits=64 build=b677c39380b27608

4.注册redis为系统服务,使用service命令管理redis

FreeBSD注册为系统service是为了使用service管理该软件。使用如下命令注册是为系统service:

echo 'redis_enable="YES"' >> /etc/rc.conf

或者

sysrc redis_enable="YES"

运行完以上命令之后可以使用cat /etc/rc.conf查看一下rc.conf里是否增加了redis服务。redis_enable="YES"出现在rc.conf中。(注:rc.conf规定了哪些应用在系统引导时启动)

root@iZuf6ex1vq9wpu4qyuu2:~ # cat /etc/rc.conf
hostname="AlibabaCloud"
sshd_enable="YES"
dumpdev="NO"
ip6addrctl_enable="NO"
ip6addrctl_policy="ipv4_prefer"
ipv6_activate_all_interfaces="NO"
ipv6_network_interfaces="none"
ifconfig_lo0="inet 127.0.0.1      netmask 255.0.0.0"
ifconfig_vtnet0="inet 172.19.55.205 netmask 255.255.240.0"
defaultrouter="172.19.63.253"
hostname="iZuf6ex1vq9wpu4qyuu"
mysql_enable="YES"
nginx_enable="YES"
redis_enable="YES"

5.启动redis-server

service redis start

如果没有报错说明成功了,可以使用service redis status查看状态

redis is running as pid 90743.

6.FreeBSD Redis配置文件路径

/usr/local/etc/redis/redis.conf

以上就是安装Redis的全过程。以后用的着就收藏吧。

评论

登录后评论

服务器优惠活动

Top