内存数据库Redis安装笔记【Linux版】

来源:互联网 发布:百度怎样做优化推广 编辑:程序博客网 时间:2024/05/17 04:27

     之前的工作中有几个项目的数据库架构中都以免费开源的内存数据库Redis作为辅助数据库(auxiliary database)。Redis的内存缓存和磁盘写出设计,保证了数据库系统赖以生存的性能和安全。


①安装

     Linux上建议源码编译安装,一方面Redis非常小(1M+)源码安装很快很方便;另一方面高级软件包管理工具apt或yum可能并未更新到最新版的Redis。这里安装当下最新的4.0.1版本。

cd /usr/local/wget http://download.redis.io/releases/redis-4.0.1.tar.gztar xzf redis-4.0.1.tar.gzcd redis-4.0.1make

②配置

     做一些简单常用的配置。我这里主要是做一些启用远程访问、守护进程、修改文件目录和开启AOF记录的设置。

cp src/redis-server /usr/local/bin/redis-servercp src/redis-cli /usr/local/bin/redis-climkdir /etc/redismkdir -p /var/redis/6379cp redis.conf /etc/redis/6379.confvim /etc/redis/6379.confbind 0.0.0.0unixsocket /tmp/redis.sockdaemonize yespidfile /var/run/redis_6379.pidlogfile /var/log/redis_6379.logstop-writes-on-bgsave-error nodir /var/redis/6379appendonly yes

③开启服务

grep ^# utils/redis_init_script > /etc/init.d/redis_6379sed -ne '6, 19p' /etc/init.d/skeleton | sed -e '1, $s/skeleton/Redis/g' >> /etc/init.d/redis_6379grep -v ^# utils/redis_init_script >> /etc/init.d/redis_6379update-rc.d redis_6379 defaultsservice redis_6379 start

④连接调试

root@ubuntu:/usr/local/redis-4.0.1# redis-cli127.0.0.1:6379> set welcome "Hello Redis"OK127.0.0.1:6379> get welcome"Hello Redis"127.0.0.1:6379> del welcome(integer) 1127.0.0.1:6379> shutdown8103:M 18 Sep 00:15:11.972 # User requested shutdown...8103:M 18 Sep 00:15:11.972 * Calling fsync() on the AOF file.8103:M 18 Sep 00:15:11.972 * Saving the final RDB snapshot before exiting.8103:M 18 Sep 00:15:11.976 * DB saved on disk8103:M 18 Sep 00:15:11.976 * Removing the pid file.8103:M 18 Sep 00:15:11.977 # Redis is now ready to exit, bye bye...not connected> not connected> quit[1]+  完成                  ./src/redis-server redis.confroot@ubuntu:/usr/local/redis-4.0.1# 



参考:

https://redis.io/download

https://redis.io/topics/quickstart

《Redis in Action》( https://book.douban.com/subject/10597898/ )