一、交叉编译
1、下载源码
最新Redis:Download | Redis
wget https://github.com/redis/redis/archive/7.0.2.tar.gz
2、在Ubuntu系统里解压
tar zxvf 7.0.2.tar.gz
3、进入源码目录
cd redis-7.0.2/
4、以此输入如下命令
make distclean ;
make clean ;
make MALLOC=libc CC=/work/qtsrc/xtool/mc/gcc-linaro-arm-linux-gnueabihf-4.7-2013.03-20130313_linux/bin/arm-linux-gnueabihf-gcc USE_SYSTEMD=no -j40
说明:CC更换为自己的交叉工具路径
5、将 src 下生成的可执行文件 使用filezilla 传输到 嵌入式的设备中执行
两个执行文件:redis-server,redis-cli,一个配置文件:redis.conf
二、放入嵌入式设备里面测试
1、在嵌入式设备里面新建文件夹Redis,把以上三个文件通过ftp软件放入
2、执行./redis-server redis.conf
3、执行./redis-cli ,
4、set test 1234
5、get test
三、测试记录如下
[jeason@centos7:~/redis]$ wget https://github.com/redis/redis/archive/7.0.2.tar.gz --2022-07-02 17:47:33-- https://github.com/redis/redis/archive/7.0.2.tar.gz Resolving github.com (github.com)... 20.205.243.166 Connecting to github.com (github.com)|20.205.243.166|:443... connected. HTTP request sent, awaiting response... 302 Found Location: https://codeload.github.com/redis/redis/tar.gz/refs/tags/7.0.2 [following] --2022-07-02 17:47:34-- https://codeload.github.com/redis/redis/tar.gz/refs/tags/7.0.2 Resolving codeload.github.com (codeload.github.com)... 20.205.243.165 Connecting to codeload.github.com (codeload.github.com)|20.205.243.165|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 2987656 (2.8M) [application/x-gzip] Saving to: ‘7.0.2.tar.gz’ 100%[====================================================================>] 2,987,656 7.50MB/s in 0.4s 2022-07-02 17:47:35 (7.50 MB/s) - ‘7.0.2.tar.gz’ saved [2987656/2987656] [jeason@centos7:~/redis]$ tar zxvf 7.0.2.tar.gz redis-7.0.2/ redis-7.0.2/.codespell/ redis-7.0.2/.codespell/.codespellrc redis-7.0.2/.codespell/requirements.txt # ........... [jeason@centos7:~/redis]$ cd redis-7.0.2/ [jeason@centos7:~/redis]$ make distclean ; make clean ;make MALLOC=libc CC=/home/jeason/100ask_imx6ull-sdk/ToolChain/gcc-linaro-6.2.1-2016.11-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc USE_SYSTEMD=no -j40 [jeason@centos7:~/redis/redis-7.0.2]$ ls ./src/redis-server -lh -rwxrwxr-x. 1 jeason jeason 5.5M Jul 2 17:52 ./src/redis-server [jeason@centos7:~/redis/redis-7.0.2]$ file ./src/redis-server ./src/redis-server: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=4915dac25c3db4d8f359db5d79c3e8a367adf80f, not stripped [jeason@centos7:~/redis/redis-7.0.2]$
[root@xxxxx test2]# ls redis-cli redis-server [root@xxxxx test2]# ls -l total 6504 -rwxr-xr-x 1 root root 893376 Jul 2 09:56 redis-cli -rwxr-xr-x 1 root root 5737420 Jul 2 09:56 redis-server [root@xxxxx test2]# ./redis-server 22555:C 02 Jul 2022 09:56:53.780 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 22555:C 02 Jul 2022 09:56:53.780 # Redis version=7.0.2, bits=32, commit=00000000, modified=0, pid=22555, just started 22555:C 02 Jul 2022 09:56:53.781 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf 22555:M 02 Jul 2022 09:56:53.785 * Increased maximum number of open files to 10032 (it was originally set to 1024). 22555:M 02 Jul 2022 09:56:53.786 * monotonic clock: POSIX clock_gettime 22555:M 02 Jul 2022 09:56:53.787 # Warning: 32 bit instance detected but no memory limit set. Setting 3 GB maxmemory limit with 'noeviction' policy now. _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 7.0.2 (00000000/0) 32 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 22555 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | https://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' 22555:M 02 Jul 2022 09:56:53.791 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. 22555:M 02 Jul 2022 09:56:53.791 # Server initialized 22555:M 02 Jul 2022 09:56:53.792 * Ready to accept connections ###################### 客户端执行如下 [root@xxxxx test2]# ./redis-cli 127.0.0.1:6379> set test 1234 OK 127.0.0.1:6379> get test "1234" 127.0.0.1:6379>
四、远程访问redis
1、说明
必须做两点:注释掉bind 127.0.0.1;增加访问密码
redis默认是不支持远程连接,需要手动开启,在redis.conf文件中,找到下方法代码:
#bind 127.0.0.1
这里只允许127.0.0.1登录,注释掉
开启密码校验,去掉requirepass的注释
requirepass password //设置密码为password(自定义的,随便设)
改完之后,保存退出,启动redis
redis-server redis.conf