最近折腾了一下本身的 Orange Pi PC,意图使之从新焕发青春活力。linux
很快,我发现了 Armbian 这一为 ARM 开发板定制的 Debian GNU/Linux 操做系统。官网上有 Orange Pi PC 的主页,并为其提供了 Armbian Stretch (Linux Kernel 4.14) 版本的稳定版镜像(下载)。Armbian 推荐使用全平台的 SD 刷写工具 etcher。并提供了完整的使用手册。git
开机,root 用户登陆,默认密码 1234,根据提示重设用户密码。github
本想从软件源中直接安装 redis。不过,先将软件源从 debian 官方切换到 USTC。redis
deb https://mirrors.ustc.edu.cn/debian stretch main contrib non-free deb https://mirrors.ustc.edu.cn/debian stretch-updates main contrib non-free deb https://mirrors.ustc.edu.cn/debian stretch-backports main contrib non-free #deb https://mirrors.ustc.edu.cn/debian stretch/updates main contrib non-free
注意 armbian 会自动天天更新软件包,所以可能会与手动执行 apt 产生抢锁的冲突。shell
而后,发现 debian stretch 提供的 redis 是 4.0 版本,但其依赖的 redis-server 仍然是 3.2 版本,这致使 apt install redis
根本装不上,不知道软件源的维护者是怎么想的。macos
思来想去仍是本身编译吧,毕竟不难,也常常在 x86_64 的云服务器上这么作。json
从 Redis 官网下载最新版源码,而后解压编译安装,大体有如下几步:vim
wget http://download.redis.io/redis-stable.tar.gz tar xf redis-stable.tar.gz cd redis-stable make && make test make install
想象是很美好的,可是 make 失败了。根据提示,是在编译 hiredis 和 lua 时出了问题。bash
hiredis 遇到的问题是:服务器
cc -std=c99 -pedantic -c -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb arm net.c cc: error: arm: No such file or directory
查看 Makefile 文件发现,这里的 arm
说的应该是环境变量 ARCH
。根据 gcc(1) 的描述,看起来这里把 arm
改成 -marm
才对。
比较 trick 的作法是把环境变量 ARCH
临时改掉(以下),改掉后果真没问题了。
# in redis-stable/ ARCH="-marm" make && make test
这已在 GitHub 上有了报告 issue #579,我也将上文所述的解决方案贴了上去。
lua 遇到的问题是:
LINK redis-server cc: error: ../deps/lua/src/liblua.a: No such file or directory
尝试去 deps/lua
目录下手动 make,发现须要手动指定平台。
where PLATFORM is one of these: aix ansi bsd freebsd generic linux macosx mingw posix solaris
第一次,我使用了 make generic
编译经过,可是在 make test
时遇到测试 lua 脚本时全局变量 cjson 不存在,也就是说 cjson 库没有被编译进去。
第二次,我使用 make linux
编译不经过,由于缺乏 readline 和 ncurses 的头文件,安装一下就行了。
apt install libreadline-dev libncurses-dev
如今,便可以成功地编译了,而后 make install
安装便可。接下来,建立运行 redis 所需的配置文件、用户、目录及 systemd 服务。
配置文件能够复制 redis 源码包中的 redis.conf。
# in redis-stable/ cp redis.conf /etc/redis.conf
咱们须要以名为 redis 的用户身份来运行 redis-server,这样可最大地限制程序的权限,下降出现漏洞带来的风险。
adduser redis --system --no-create-home --group --shell /sbin/nologin
系统级目录自己属于 root:root,而 redis 用户是无权写入的,常见作法是建立属于 redis 用户的子目录。
redis 的目录须要与 redis.conf 中的配置相对应。
# redis.conf pidfile "/var/run/redis/6379.pid" logfile "/var/log/redis/6379.log" dir "/var/lib/redis/"
(cd /var/run && mkdir redis && chown redis:redis redis) (cd /var/log && mkdir redis && chown redis:redis redis) (cd /var/lib && mkdir redis && chown redis:redis redis)
接下来配置 systemd 服务,此类服务通常位于 /lib/systemd/system/
。依样画葫芦便可。
vim /lib/systemd/system/redis.service
[Unit] Description=Redis After=network.target [Service] Type=forking User=redis Group=redis PIDFile=/var/run/redis/6379.pid ExecStart=/usr/local/bin/redis-server /etc/redis.conf --daemonize yes --supervised systemd ExecStop=/usr/local/bin/redis-cli shutdown ExecReload=/bin/kill -USR2 $MAINPID [Install] WantedBy=multi-user.target
# 从新加载配置 systemctl daemon-reload # 启动 systemctl start redis
# 开机启动 systemctl enable redis
这会在 /etc/systemd/system/multi-user.target.wants
下创建符号连接,效果等同于
ln -s /lib/systemd/system/redis.service /etc/systemd/system/multi-user.target.wants/redis.service
好比在启动服务的过程当中若是遇到什么问题,可根据提示查看 journalctl -xe
排错。
未尽事宜,已与谷歌深度合做,请。