Linux下Redis的编译安装
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

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

InnoDB's full-text search capabilities are very powerful, which can significantly improve database query efficiency and ability to process large amounts of text data. 1) InnoDB implements full-text search through inverted indexing, supporting basic and advanced search queries. 2) Use MATCH and AGAINST keywords to search, support Boolean mode and phrase search. 3) Optimization methods include using word segmentation technology, periodic rebuilding of indexes and adjusting cache size to improve performance and accuracy.

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

The difference between clustered index and non-clustered index is: 1. Clustered index stores data rows in the index structure, which is suitable for querying by primary key and range. 2. The non-clustered index stores index key values and pointers to data rows, and is suitable for non-primary key column queries.

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

MySQL supports four index types: B-Tree, Hash, Full-text, and Spatial. 1.B-Tree index is suitable for equal value search, range query and sorting. 2. Hash index is suitable for equal value searches, but does not support range query and sorting. 3. Full-text index is used for full-text search and is suitable for processing large amounts of text data. 4. Spatial index is used for geospatial data query and is suitable for GIS applications.

In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.

MySQL and MariaDB can coexist, but need to be configured with caution. The key is to allocate different port numbers and data directories to each database, and adjust parameters such as memory allocation and cache size. Connection pooling, application configuration, and version differences also need to be considered and need to be carefully tested and planned to avoid pitfalls. Running two databases simultaneously can cause performance problems in situations where resources are limited.
