Home Database Mysql Tutorial Linux下Redis的编译安装

Linux下Redis的编译安装

Jun 07, 2016 pm 04:40 PM

redis是一个key-value存储系统。和Memcached类似,它支持存储的value类型相对更多,包括string(字符串)、list(链表)、set(集合)、

介绍

redis是一个key-value存储系统。和Memcached类似,它支持存储的value类型相对更多,包括string(字符串)、list(链表)、set(集合)、zset(sorted set --有序集合)和hash(哈希类型)。这些数据类型都支持push/pop、add/remove及取交集并集和差集及更丰富的操作,而且这些操作都是原子性的。在此基础上,redis支持各种不同方式的排序。与memcached一样,为了保证效率,数据都是缓存在内存中。区别的是redis会周期性的把更新的数据写入磁盘或者把修改操作写入追加的记录文件,并且在此基础上实现了master-slave(主从)同步。

Linux下编译安装

下载redis
############目前最新稳定版##########
[root@redis ~]# wget

解压缩redis
[root@redis ~]# tar xzf redis-2.8.19.tar.gz

编译redis

redis的编译非常简单,已经有现成的Makefile文件,直接运行make命令即可
[root@redis redis-2.8.19]# cd redis-2.8.19
[root@redis redis-2.8.19]# make

make命令执行完成后,会在src目录下生成6个可执行文件,分别是redis-server、redis-cli、redis-benchmark、redis-check-aof、redis-check-dump、redis-sentinel,它们的作用如下:
redis-server:            Redis服务器的daemon启动程序
redis-cli:                Redis命令行操作工具。当然,你也可以用telnet根据其纯文本协议来操作
redis-benchmark:          Redis性能测试工具,测试Redis在你的系统及你的配置下的读写性能
redis-check-aof:          更新日志检查
redis-check-dump:        用于本地数据库检查
redis-sentinel:          Redis实例的监控管理、通知和实例失效备援服务,是Redis集群的管理工具

安装redis
[root@redis src]# make install

配置redis的配置文件
[root@redis redis-2.8.19]# cp redis.conf /etc/
##########编辑Redis配置文件###################
[root@redis redis-2.8.19]# vim /etc/redis.conf
    daemonize yes                      #37行    #是否以后台daemon方式运行,默认不是后台运行
    pidfile /var/run/redis/redis.pid    #41行    #redis的PID文件路径
    bind 10.168.85.25                  #64行    #绑定主机IP,默认值为127.0.0.1,我们是跨机器运行,所以需要更改
    logfile /var/log/redis/redis.log    #104行  #定义log文件位置,模式log信息定向到stdout,输出到/dev/null
    save 60 1000                        #145行  #重新定义快照的频率
    dir /usr/local/rdbfile              #188行  #本地数据库存放路径,默认为./,编译安装默认存在在/usr/local/bin下

启动测试Redis服务器
#############启动Redis服务器############
[root@redis redis-2.8.19]# redis-server /etc/redis.conf
#############查看是否启动成功###########
[root@redis redis-2.8.19]# ss -tanlp | grep redis
LISTEN    0      128            10.168.85.25:6379                    *:*      users:(("redis-server",17379,4))
#############测试Redis##################
[root@redis redis-2.8.19]# redis-cli -h 10.168.85.25 -p 6379
10.168.85.25:6379> set test hello
OK
10.168.85.25:6379> get test
"hello"

更改内核信息
#############查看日志信息###############
[root@redis redis-2.8.19]# tail -f /var/log/redis/redis.log
[5033] 04 Jan 15:47:05.378 # Server started, Redis version 2.8.19
[5033] 04 Jan 15:47:05.379 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
[5033] 04 Jan 15:47:05.379 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
[5033] 04 Jan 15:47:05.380 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
[5033] 04 Jan 15:47:05.380 * DB loaded from disk: 0.000 seconds
[5033] 04 Jan 15:47:05.380 * The server is now ready to accept connections on port 6379
日志显示有两个关于内核设置的警告信息!
##############sysctl文件###############
[root@redis ~]# echo "vm.overcommit_memory=1" >> /etc/sysctl.conf
[root@redis ~]# sysctl -p
#############kerbel####################
[root@redis ~]# echo never > /sys/kernel/mm/transparent_hugepage/enabled
 


重新启动Redis服务器
#######将缓存保存到硬盘上#####
[root@redis ~]# redis-cli -h 10.168.85.25 -p 6379 BGSAVE
Background saving started
#######关闭Redis#############
[root@redis ~]# redis-cli -h 10.168.85.25 -p 6379 SHUTDOWN
########启动Redis############
[root@redis ~]# redis-server /etc/redis.conf

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How do you alter a table in MySQL using the ALTER TABLE statement? How do you alter a table in MySQL using the ALTER TABLE statement? Mar 19, 2025 pm 03:51 PM

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

How do I configure SSL/TLS encryption for MySQL connections? How do I configure SSL/TLS encryption for MySQL connections? Mar 18, 2025 pm 12:01 PM

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

How do you handle large datasets in MySQL? How do you handle large datasets in MySQL? Mar 21, 2025 pm 12:15 PM

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)? What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)? Mar 21, 2025 pm 06:28 PM

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

How do you drop a table in MySQL using the DROP TABLE statement? How do you drop a table in MySQL using the DROP TABLE statement? Mar 19, 2025 pm 03:52 PM

The article discusses dropping tables in MySQL using the DROP TABLE statement, emphasizing precautions and risks. It highlights that the action is irreversible without backups, detailing recovery methods and potential production environment hazards.

How do you create indexes on JSON columns? How do you create indexes on JSON columns? Mar 21, 2025 pm 12:13 PM

The article discusses creating indexes on JSON columns in various databases like PostgreSQL, MySQL, and MongoDB to enhance query performance. It explains the syntax and benefits of indexing specific JSON paths, and lists supported database systems.

How do you represent relationships using foreign keys? How do you represent relationships using foreign keys? Mar 19, 2025 pm 03:48 PM

Article discusses using foreign keys to represent relationships in databases, focusing on best practices, data integrity, and common pitfalls to avoid.

How do I secure MySQL against common vulnerabilities (SQL injection, brute-force attacks)? How do I secure MySQL against common vulnerabilities (SQL injection, brute-force attacks)? Mar 18, 2025 pm 12:00 PM

Article discusses securing MySQL against SQL injection and brute-force attacks using prepared statements, input validation, and strong password policies.(159 characters)

See all articles