2,配置redis
#cd /opt/redis/
#vi redis.conf
主节点配置:
#bind 127.0.0.0 --把本地注释掉
port 6000 #设定端口
protected-mode no
pidfile "/var/run/redis_6000.pid"
从节点配置:
#bind 127.0.0.0
port 6000 #设定端口
protected-mode no
pidfile "/var/run/redis_6000.pid"
slaveof 10.200.36.166 6000
3,配置Tomcat连接Redis
这里需要先将jar包传到/opt/apache-tomcat-9.0.13/lib/
commons-pool2-2.4.2.jar
jedis-2.9.0.jar
tomcat-redis-session-manager.jar
接下来修改context.xml(主备机一样):
#vi /opt/apache-tomcat-9.0.13/conf/context.xml
<Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve"/>
<Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager"
host="10.200.36.166"
port="6000"
maxInactiveInterval="180"/>
4,启动Redis,检测是否正常
#cd /opt/redis
#./bin/redis-server ./redis.conf &--启动
主机启动成功示例:
30472:C 08 Mar 2019 16:45:58.778 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
30472:C 08 Mar 2019 16:45:58.778 # Redis version=5.0.3, bits=64, commit=00000000, modified=0, pid=30472, just started
30472:C 08 Mar 2019 16:45:58.778 # Configuration loaded
30472:M 08 Mar 2019 16:45:58.779 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 5.0.3 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6000
| `-._ `._ / _.-' | PID: 30472
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
30472:M 08 Mar 2019 16:45:58.780 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
30472:M 08 Mar 2019 16:45:58.780 # Server initialized
30472:M 08 Mar 2019 16:45:58.780 # 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.
30472:M 08 Mar 2019 16:45:58.780 # 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.
30472:M 08 Mar 2019 16:45:58.780 * DB loaded from disk: 0.000 seconds
30472:M 08 Mar 2019 16:45:58.780 * Ready to accept connections
30472:M 08 Mar 2019 16:45:58.782 * Replica 10.200.36.167:6000 asks for synchronization
30472:M 08 Mar 2019 16:45:58.782 * Partial resynchronization not accepted: Replication ID mismatch (Replica asked for 'cf37ef581b1ca03add649e6c8de36524a28acc02', my replication IDs are '007ccfcf163d9117ac34710be5d623e031d10779' and '0000000000000000000000000000000000000000')
30472:M 08 Mar 2019 16:45:58.782 * Starting BGSAVE for SYNC with target: disk
30472:M 08 Mar 2019 16:45:58.784 * Background saving started by pid 30476
30476:C 08 Mar 2019 16:45:58.787 * DB saved on disk
30476:C 08 Mar 2019 16:45:58.788 * RDB: 4 MB of memory used by copy-on-write
30472:M 08 Mar 2019 16:45:58.881 * Background saving terminated with success
30472:M 08 Mar 2019 16:45:58.881 * Synchronization with replica 10.200.36.167:6000 succeeded
从机启动成功示例:
12452:C 08 Mar 2019 16:45:58.747 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
12452:C 08 Mar 2019 16:45:58.747 # Redis version=5.0.3, bits=64, commit=00000000, modified=0, pid=12452, just started
12452:C 08 Mar 2019 16:45:58.747 # Configuration loaded
12452:S 08 Mar 2019 16:45:58.748 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 5.0.3 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6000
| `-._ `._ / _.-' | PID: 12452
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
12452:S 08 Mar 2019 16:45:58.749 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
12452:S 08 Mar 2019 16:45:58.749 # Server initialized
12452:S 08 Mar 2019 16:45:58.749 # 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.
12452:S 08 Mar 2019 16:45:58.749 # 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.
12452:S 08 Mar 2019 16:45:58.749 * DB loaded from disk: 0.000 seconds
12452:S 08 Mar 2019 16:45:58.749 * Before turning into a replica, using my master parameters to synthesize a cached master: I may be able to synchronize with the new master with just a partial transfer.
12452:S 08 Mar 2019 16:45:58.749 * Ready to accept connections
12452:S 08 Mar 2019 16:45:58.750 * Connecting to MASTER 10.200.36.166:6000
12452:S 08 Mar 2019 16:45:58.750 * MASTER <-> REPLICA sync started
12452:S 08 Mar 2019 16:45:58.750 * Non blocking connect for SYNC fired the event.
12452:S 08 Mar 2019 16:45:58.750 * Master replied to PING, replication can continue...
12452:S 08 Mar 2019 16:45:58.751 * Trying a partial resynchronization (request cf37ef581b1ca03add649e6c8de36524a28acc02:12329042).
12452:S 08 Mar 2019 16:45:58.754 * Full resync from master: 3a676503f92e3403f9d4a20097d8f16f7dfa2b5d:0
12452:S 08 Mar 2019 16:45:58.754 * Discarding previously cached master state.
12452:S 08 Mar 2019 16:45:58.850 * MASTER <-> REPLICA sync: receiving 175 bytes from master
12452:S 08 Mar 2019 16:45:58.851 * MASTER <-> REPLICA sync: Flushing old data
12452:S 08 Mar 2019 16:45:58.851 * MASTER <-> REPLICA sync: Loading DB in memory
12452:S 08 Mar 2019 16:45:58.851 * MASTER <-> REPLICA sync: Finished with success
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-111706-3.html
不惜一战
就是和韩国都没得比