如何在Ubuntu 16.04上安装并配置Redis

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在Ubuntu 16.04上安装并配置Redis相关的知识,希望对你有一定的参考价值。

参考技术A 下载、编译并安装Redis
接下来对Redis进行build。
下载并提取源代码
由于我们不需要长期保留源代码,因此可以直接在/tmp目录内进行build:
- cd /tmp
12

现在下载Redis最新版本,大家可以使用稳定下载URL:
- curl -O h//download.redis.io/redis-stable.tar.gz
12

解压tar:
- tar xzvf redis-stable.tar.gz
12

前往Redis源目录:
- cd redis-stable
12

Build并安装Redis
现在对Redis二进制代码进行编译:
- make
12

编译完成后,运行测试套件以确保built正确:
- make test
12

这一过程通常需要几分钟。完成后,大家可以使用以下命令进行安装:
- sudo make install
12

配置Redis
Redis已经安装完成,接下来进行配置。首先创建一个配置目录,这里我们使用/etc/redis目录:
- sudo mkdir /etc/redis
12

将Redis源归档文件内的示例Redis配置文件复制进来:
- sudo cp /tmp/redis-stable/redis.conf /etc/redis
12

而后打开文件并进行调整:
- sudo nano /etc/redis/redis.conf
12

在文件中找到supervised命令。现在其被设置为no。由于我们运行的操作系统使用systemd init系统,因此需要将其变更为systemd:
/etc/redis/redis.conf

. . .

# If you run Redis from upstart or systemd, Redis can interact with your
# supervision tree. Options:
# supervised no - no supervision interaction
# supervised upstart - signal upstart by putting Redis into SIGSTOP mode
# supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET
# supervised auto - detect upstart or systemd method based on
# UPSTART_JOB or NOTIFY_SOCKET environment variables
# Note: these supervision methods only signal "process is ready."
# They do not enable continuous liveness pings back to your supervisor.
supervised systemd

. . .
1234567891011121314151617

下面找到dir目录。此选项指定Redis用于放置持久数据的目录。我们需要挑选合适的位置,并确保Redis有权限写入但普通用户无权查看。
这里我们使用/var/lib/redis目录,稍后进行创建:
/etc/redis/redis.conf

. . .

# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
#
# The Append Only File will also be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
dir /var/lib/redis

. . .
12345678910111213141516

完成后保存并退出。
创建Redis systemd Unit文件
接下来,我们可以创建一个systemd unit文件,从而利用该init系统管理Redis进程。
首先创建并打开/etc/systemd/system/redis.service文件:
- sudo nano /etc/systemd/system/redis.service
12

在这里,我们在[Unit]部分处添加一条描述,定义要求网络在服务启动前必须处于可用状态:
/etc/systemd/system/redis.service

[Unit]
Description=Redis In-Memory Data Store
After=network.target
123456

在[Service]部分,我们需要指定该服务的运作方式。出于安全考虑,我们不应以root方式运行服务。我们应当使用专用用户及群组,并以此调用redis。我们稍后再创建这部分内容。
要启动服务,我们只需要在配置中调用redis-server二进制文件。要将其关闭,则可使用Reids的shutdown命令,其可利用redis-cli加以执行。另外,由于我们希望Redis能够在故障情况下得到恢复,因此需要将Restart指令设定为“always”:
/etc/systemd/system/redis.service

[Unit]
Description=Redis In-Memory Data Store
After=network.target

[Service]User=redisGroup=redisExecStart=/usr/local/bin/redis-server /etc/redis/redis.confExecStop=/usr/local/bin/redis-cli shutdownRestart=always
12345678

最后在[Install]部分,我们将systemd定义为在该服务可用时始终关联(即在引导过程中即行启动):
/etc/systemd/system/redis.service

[Unit]
Description=Redis In-Memory Data Store
After=network.target

[Service]
User=redis
Group=redis
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
ExecStop=/usr/local/bin/redis-cli shutdown
Restart=always

[Install]WantedBy=multi-user.target
123456789101112131415

完成后保存并退出。
参考技术B 关羽单刀赴会关羽单刀赴会

如何在ubuntu中搭建网桥?

我电脑上有有两张网卡,现在有一台笔记本想由于地理因素不能直接连接到路由器上,我利用我的主机来与笔记本共享上网,但我用的是ubuntu系统。请高手现招!
台式机有两张网卡,并且是ubuntu系统

网桥工具的安装:
默认Ubuntu是没有网桥设置工具(brctl)的。你需要安装bridge-utils,这里在我的pc2上:
SYSHUNTER-UBUNTU# apt-get install bridge-utils

配置网桥:
先创建一个网桥接口:
SYSHUNTER-UBUNTU# brctl addbr br0

将两块已有的网卡添加到网桥:
SYSHUNTER-UBUNTU# brctl addif br0 eth0
SYSHUNTER-UBUNTU# brctl addif br0 eth1

将两块网卡IP设置为0,它们已经不再需要了:
SYSHUNTER-UBUNTU# ifconfig eth0 0.0.0.0
SYSHUNTER-UBUNTU# ifconfig eth1 0.0.0.0

给新网桥设置一个IP:
SYSHUNTER-UBUNTU# ifconfig br0 192.168.1.10

结束语
经过上面安装网桥工具,配置网桥,简单几步。现在pc1、pc2、lpt1已经在同一个局域网了,pc1、pc2、lpt1可以各自单独拨号并相互共享访问资源了。
参考技术A
    ubuntu搭建网桥ubuntu网桥
    先安装 bridge-utils
    #sudo apt-get install bridge-utils
    #sudo gedit /etc/network/interfaces
    在后面加上这个:
    auto eth0
    iface eth0 inet manual
    auto br0
    iface br0 inet static
    address 10.65.160.104
    network 10.65.128.0
    netmask 255.255.128.0
    broadcast 10.65.255.255
    gateway 10.65.156.27
    bridge_ports eth0
    bridge_fd 9
    bridge_hello 2
    bridge_maxage 12
    bridge_stp off
    sudo /etc/init.d/networking restart (或 sudo restart network-manager)

参考技术B 网桥工具的安装:
默认Ubuntu是没有网桥设置工具(brctl)的。你需要安装bridge-utils,这里在我的pc2上:
SYSHUNTER-UBUNTU# apt-get install bridge-utils

配置网桥:
先创建一个网桥接口:
SYSHUNTER-UBUNTU# brctl addbr br0

将两块已有的网卡添加到网桥:
SYSHUNTER-UBUNTU# brctl addif br0 eth0
SYSHUNTER-UBUNTU# brctl addif br0 eth1

将两块网卡IP设置为0,它们已经不再需要了:
SYSHUNTER-UBUNTU# ifconfig eth0 0.0.0.0
SYSHUNTER-UBUNTU# ifconfig eth1 0.0.0.0

给新网桥设置一个IP:
SYSHUNTER-UBUNTU# ifconfig br0 192.168.1.10

结束语
经过上面安装网桥工具,配置网桥,简单几步。现在pc1、pc2、lpt1已经在同一个局域网了,pc1、pc2、lpt1可以各自单独拨号并相互共享访问资源了
参考技术C 先安装uml-utilities,该工具包含建立虚拟网络设备(所谓的“TAP interfaces”)的工具:
sudo apt-get install uml-utilities

安装 桥接工具 bridge-utils
#sudo apt-get install bridge-utils

#sudo gedit /etc/network/interfaces

在后面加上这个:
auto eth0
iface eth0 inet manual

auto br0
iface br0 inet static
address 192.168.1.104
network 192.168.1.0
netmask 255.255.255.0
broadcast 192.168.1.255
gateway 192.168.1.1
bridge_ports eth0
bridge_fd 9
bridge_hello 2
bridge_maxage 12
bridge_stp off

(上面的ip和网络地址等改成你需要的就行了)
启动网桥
sudo /sbin/ifup br0

sudo /etc/init.d/networking restart (或 sudo restart network-manager)
参考技术D 主机还是笔记本有两个网卡?哪个是ubuntu系统?得说清楚才行呀!
我想应该没问题,我现在就是用笔记本的ubuntu系统,用它的无线网卡连能上网的无线路由器,然后再用有线网卡给一个路由器输出,让一个台式机上网

以上是关于如何在Ubuntu 16.04上安装并配置Redis的主要内容,如果未能解决你的问题,请参考以下文章

如何在64位Ubuntu 16.04系统上卸载openjdk并重新安装配置java8环境

如何在Ubuntu 16.04上安装并配置Postfix作为只发送SMTP服务器

翻译:如何在Ubuntu16.04上安装Mosquitto这个MQTT消息服务器并对其进行安全配置

如何在 ubuntu 16.04 机器上安装和配置 HSQL DB

如何在Ubuntu 16.04上安装和osquitto MQTT消息传递代理

如何安装和配置WordPress(WP)程序