Deploying Nginx Deployment Redis Installation Redis Redis things server Management commands slow query log master-slave replication Redis-sentinel partition cluster Install Python operations cluser data Deployment Django Program
Deploy Nginx
Configuring Epel sources
See Ali Net Https://opsx.alibaba.com/mirror
Wget-o/etc/yum.repos.d/epel.repo Http://mirrors.aliyun.com/repo/epel-7.repo
# #epel Configuration Method
# # #1, Backup (if configured with other Epel source)
mv/etc/yum.repos.d/epel.repo/etc/yum.repos.d/epel.repo.backup
mv/ Etc/yum.repos.d/epel-testing.repo/etc/yum.repos.d/epel-testing.repo.backup
2, download new repo to/etc/yum.repos.d/
Epel (RHEL 7)
wget-o/etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
Epel (RHEL 6 )
wget-o/etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
Epel (RHEL 5)
Wget-o/ Etc/yum.repos.d/epel.repo Http://mirrors.aliyun.com/repo/epel-5.repo
Yum Repolist
[Root@safly ~]# yum repolist
Loaded plugins:fastestmirror
epel | 4.7 kB 00:00
(1/3): epel/x86_64/ Group_gz | 266 KB 00:01
(2/3): Epel/x86_64/updateinfo | 917 kb 00:05
(3/3): epel/x86_64/ primary_db | 6.3 MB 00:20
Loading mirror speeds from cached hostfile
* base:mirrors.aliyun.com
* epel:mirrors.aliyun.com *
extras:mirrors.aliyun.com *
updates:mirrors.aliyun.com
Repo ID repo name status
base/7/x86_64 CentOS-7-base-mirrors.aliyun.com 9,591
epel/x86_ Extra Packages for Enterprise Linux 7-x86_ 12,509 extras/7/x86_64
CentOS-7 -EXTRAS-MIRRORS.ALIYUN.C Om 448
updates/7/x86_64 CentOS-7-updates-mirrors.aliyun.com 2,416
repolist:24,964
[ Root@safly ~]#
Installation
Yum Install SL cowsay-y
Install Nginx
wget http://nginx.org/download/nginx-1.12.2.tar.gz
yum install pcre-devel openssl-devel-y
#编译安装三部曲:./ Configure make make install
tar XF nginx-1.12.2.tar.gz
cd nginx-1.12.2
./configure--prefix=/ application/nginx-1.12.2--with-http_stub_status_module --with-http_ssl_module
make
#检查语法
/application/nginx-1.12.2/sbin/nginx- t
#启动nginx
/application/nginx-1.12.2/sbin/ Nginx
Reboot
[Root@safly nginx-1.12.2]#/application/nginx-1.12.2/sbin/nginx-s Reload
Deploy Redis Install Redis
Install Redis
[Root@safly/]# ls
application boot dev home lib64 mnt proc run sbin sys usr wyf
bin Data etc lib media opt root safly srv tmp var
[root@safly/]# cd/application/
[root@safly application]# ls
nginx-1.12.2
[ Root@safly application]# wget http://download.redis.io/releases/redis-3.2.10.tar.gz
[Root@safly application]# Tar xzf redis-3.2.10.tar.gz
[root@safly application]# ls
nginx-1.12.2 redis-3.2.10 redis-3.2.10.tar.gz
[root@safly application]# mv redis-3.2.10 redis
[root@safly application]# RM-RF redis-3.2.10.tar.gz
[root@safly application]# ls
nginx-1.12.2 redis
[Root@safly application]# CD Redis
[root@safly redis]# make
src/redis-server
Client Connection Test
[Root@oldboyedu-s6 redis]# src/redis-cli
127.0.0.1:6379>
127.0.0.1:6379> set foo bar
OK
127.0.0.1:6379>
127.0.0.1:6379> get foo
"bar"
127.0.0.1:6379>
127.0.0.1:6379> Shutdown
Configure Redis
Daemonize Yes
port 1111
logfile/var/log/redis.log
dbfilename dump.rdb
Dir/data/redis
AppendOnly Yes
bind 10.0.0.200 127.0.0.1
requirepass 123
Get Current configuration
CONFIG Get *
Start Redis with configuration
Restart Redis
[root@oldboyedu-s6 ~]#/application/redis/src/redis-cli- p 1111
127.0.0.1:1111> after the completion of the add Shutdown
/application/redis/src/redis-server/etc/redis.conf
login test:
[root@safly/]#/application/ Redis/src/redis-cli-h 10.0.0.128-p 1111
Password Authentication Login
/APPLICATION/REDIS/SRC/REDIS-CLI -H 10.0.0.200-a 123 -P 1111
or:
/application/redis/src/ REDIS-CLI- H 10.0.0.200-p 1111 Auth 123
Or
(Error) Noauth Authentication required.
127.0.0.1:1111> Auth 123
OK
Persistence of
Add the following content to the/etc/redis.conf
dbfilename dump.rdb
dir/data/redis
Save 900 1
Save
60 10000
Redis Things
Discard
Cancels the transaction, discarding all commands within the transaction block.
Exec
Executes the commands within all transaction blocks.
MULTI
Marks the beginning of a transaction block.
Unwatch
Cancels the WATCH command's monitoring of all key.
WATCH key [Key ...]
Monitors one or more key keys, and if the key is changed by another command before the transaction is executed, the transaction is interrupted.
Multi
[Root@safly/]#/application/redis/src/redis-cli-p 1111-a 123 127.0.0.1:1111>
OK
127.0.0.1:1111> Discard
OK
127.0.0.1:1111> multi
OK
127.0.0.1:1111> set foo bar
QUEUED
127.0.0.1:1111> exec
1) OK
Watch
127.0.0.1:1111> Get ticket
(nil)
127.0.0.1:1111> set ticket 1
OK
127.0.0.1:1111> Get ticket
"1"
127.0.0.1:1111> Watch ticket
OK
127.0.0.1:1111> multi
OK
127.0.0.1:1111> DECR ticket
QUEUED
127.0.0.1:1111> exec
1) (integer) 0
127.0.0.1:1111>
Open a different client
127.0.0.1:1111> Clear
127.0.0.1:1111> multi
OK
127.0.0.1:1111> decr ticket
QUEUED
127.0.0.1:1111> exec
1) (integer)-1
127.0.0.1:1111> get Ticket
"-1"
127.0.0.1:1111 >
Server Management Commands
Info
clinet list
Client kill Ip:port
config get *
config resetstat reset Statistics
config get/set dynamic modification C31/>dbsize
flushall Clear All data
Select 1
flushdb empty current library
Monitor real-time instructions
SHUTDOWN shutdown Server
Save saves the current data
slaveof host port master and subordinate configuration
slaveof NO one
sync master sync
role return master and subordinate roles
Slow Query Log
Slow log is a log system used by Redis to record query execution time.
slow log is stored in memory, read and write very quickly
can be modified
dynamically by overwriting redis.conf files or using config get and config SET commands Slowlog-log-slower-than 10000 over how many microseconds
config set Slowlog-log-slower-than
config set Slowlog-max-len 1000 Save how many slow log
CONFIG get slow*
slowlog get
slowlog RESET
master-slave replication
Use asynchronous replication.
A master server can have more than one from the server.
From the server can also have their own from the server.
The replication feature does not block the primary server.
You can use replication to keep the primary server from performing persistent operations, from the server to the persistence operation.
Configuring Master-slave replication
Prepare two or two more Redis instances
Mkdir-p/data/6380/
mkdir-p/data/6381/
mkdir-p/data/6382/
Three sets of configuration files Example: vim/data/6380/redis.conf----------------bind 127.0.0.1 10.0.0.128 port 6380 daemonize Yes pidfile/data/6380 /redis.pid loglevel Notice logfile "/data/6380/redis.log" Dbfilename dump.rdb dir/data/6380 appendonly no Appendfilename "Appendonly.aof" Appendfsync everysec Slowlog-log-slower-than 10000 slowlog-max-len 128 Protected-mode no vim/data/638 1/redis.conf----------------bind 127.0.0.1 10.0.0.128 port 6381 daemonize Yes pidfile/data/6381/redis.pid loglevel Noti Ce logfile "/data/6381/redis.log" Dbfilename dump.rdb dir/data/6381 appendonly no Appendfilename "appendonly.aof" append Fsync everysec Slowlog-log-slower-than 10000 slowlog-max-len 128 no Protected-mode---------- ------bind 127.0.0.1 10.0.0.128 port 6382 daemonize Yes pidfile/data/6382/redis.pid loglevel notice logfile "/data/6382/ Redis.log "Dbfilename dump.rdb dir/data/6382 appendonly no appendfilename appendonly.aof" Appendfsync everysec Log-slower-than 10000 SlowlOg-max-len 128 Protected-mode No start:/application/redis/src/redis-server/data/6380/redis.conf/application/redis/src /redis-server/data/6381/redis.conf/application/redis/src/redis-server/data/6382/redis.conf View startup Status netstat-lnp|
grep 638 Ps-ef |grep Redis
Association Master
[Root@safly ~]#/application/redis/src/redis-cli-p 6381
127.0.0.1:6381> slaveof 127.0.0.1 6380
OK
127.0.0.1:6381> exit
[root@safly ~]#/application/redis/src/redis-cli-p 6382 127.0.0.1:6382> SLAVEOF
127.0.0.1 6380
OK
127.0.0.1:6382> exit
[Root@safly ~]#
Master-Slave Library data replication
Main Library
[Root@safly ~]#/application/redis/src/redis-cli-p 6380
127.0.0.1:6380> keys *
(empty list or set)
127.0.0.1:6380> set foo str
OK
From the Library
[Root@safly ~]# /application/redis/src/redis-cli-p 6381
127.0.0.1:6381> keys *
(empty list or set) c17/>127.0.0.1:6381> get foo
"str"
127.0.0.1:6381>
Redis-sentinel
Redis-sentinel is the Redis's official recommended high-availability (HA) solution, and when Master is down, the Redis itself (including many of its clients) does not implement automatic master switching when using Redis as a master-slave high availability solution. And Redis-sentinel itself is a stand-alone process, it can monitor multiple Master-slave cluster, found master downtime can be automatically switched
Function:
Monitoring (Monitoring):
Sentinel will constantly check your home server and from the server for proper operation.
Reminders (Notification):
When a problem occurs on a Redis server that is being monitored, Sentinel can send notifications to administrators or other applications via the API.
Automatic failover (Automatic failover):
When a primary server is not working correctly, Sentinel starts an automatic failover operation that upgrades one of the failed primary servers from the server to the new primary server, and lets the other from the failed master server replicate to the new master server, and when the client attempts to connect to the failed primary server, The cluster also returns the address of the new home server to the client, allowing the cluster to use the new primary server instead of the failed server.
Sentinel Configuration Cluster
mkdir/data/26380
cp/application/redis/src/redis-sentinel/data/26380
cd/data/26380
vim sentinel.conf
Port 26380
dir "/tmp"
Sentinel Monitor MyMaster 127.0.0.1 6380 1
Sentinel Down-after-milliseconds MyMaster 5000
Sentinel Config-epoch mymaster 0
started
./redis-sentinel./sentinel.conf
Python3 Connection Redis Sentinel cluster
Cluser Fragmentation Cluster
Installation
Epel Source install ruby support
yum install ruby rubygems-y
use domestic source
gem Sources-a http://mirrors.aliyun.com/rubygems/
Gem sources --remove http://rubygems.org/
gem sources-l
gem install redis-v 3.3.3
If it is not available, you can use the Aliyun
Gem Sources-a http://mirrors.aliyun.com/rubygems/
Gem Sources–remove http://rubygems.org/
Configuration
Create node directory:
mkdir-p/data/7000
mkdir-p/data/7001
mkdir-p/data/7002
mkdir-p/data/7003
-p/data/7004
mkdir-p/data/7005
Configuration file add:
---------------------