Spring Boot ã§æ¸ç±ã®è²¸åºç¶æ³ç¢ºèªã»è²¸åºç³è«ãã Web ã¢ããªã±ã¼ã·ã§ã³ãä½ã ( ãã®ï¼ï¼ )( Spring Session ã使ç¨ããï¼ )
æ¦è¦
Spring Boot ã§æ¸ç±ã®è²¸åºç¶æ³ç¢ºèªã»è²¸åºç³è«ãã Web ã¢ããªã±ã¼ã·ã§ã³ãä½ã ( ãã®ï¼ï¼ )( Spring Session ã使ç¨ããï¼ ) ã®ç¶ãã§ãã
- ä»åã®æé ã§ç¢ºèªã§ããã®ã¯ä»¥ä¸ã®å 容ã§ãã
åç §ãããµã¤ãã»æ¸ç±
ç®æ¬¡
æé
Tomcat, Redis ãè¤æ°èµ·åãã¦è©¦ãã¦ã¿ã
Web ã¢ããªã±ã¼ã·ã§ã³ã Redis Sentinel 対å¿ã«è¨å®å¤æ´ãã
Spring Data Redis 㧠Redis Sentinel ãå©ç¨ããå ´åãç¾å¨ master ã¨ãªã£ã¦ãã Redis ã® IPã¢ãã¬ã¹ããã¼ãçªå·ã¯ Redis Sentinel ã®ç®¡çããã»ã¹ããåå¾ãã¾ãã
- src/main/resources ã®ä¸ã® application-develop.properties, application-unittest.properties, application-product.properties ã ãªã³ã¯å ã®å 容 ã«å¤æ´ãã¾ãã
Tomcat ãè¤æ°èµ·åãã¦åä½ç¢ºèªãã
jar ãã¡ã¤ã«ãä½æããå¾ããã¼ãçªå·ãå¤ãã Tomcat ãè¤æ°èµ·åãã¦åä½ç¢ºèªãã¾ãã
Gradle projects View ãã build ã¿ã¹ã¯ãå®è¡ã㦠ksbysample-webapp-lending-1.0.0-SNAPSHOT.jar ãä½æãã¾ããjar ãã¡ã¤ã«ã¯ C:\project-springboot\ksbysample-webapp-lending\build\libs ã®ä¸ã«çæããã¾ãã
ã³ãã³ãã©ã¤ã³ãããã¼ãçªå·ãå¤æ´ãã Tomcat ãï¼å°èµ·åãã¾ãã
Redis ã®ãã¼ã¿ãå ¨ã¦åé¤ãã¾ããç¾å¨ã¯ä¸ã® 6379çªãã¼ãã® Redis ã master ã§ãã
ã¾ãã¯ãã°ã¤ã³ããã°ã¢ã¦ããããæã«ã©ã® Tomcat ã«ã¢ã¯ã»ã¹ãã¦ãèªè¨¼æ å ±ãå ±æããã¦åãç»é¢ã表示ããããã¨ã確èªãã¦ã¿ã¾ãã
ãã©ã¦ã¶ã§ http://localhost:8080/ ã«ã¢ã¯ã»ã¹ãããã°ã¤ã³ç»é¢ã表示ãã¾ããID ã« "[email protected]"ãPassword ã« "taro" ãå ¥åããã次åããèªåçã«ãã°ã¤ã³ãã ãã¯ãã§ãã¯ããããã°ã¤ã³ããã¿ã³ãã¯ãªãã¯ãã¾ããèªè¨¼ã«æåãããã°ã¤ã³æåï¼ãã®ç»é¢ã表示ããã¾ãã
Redis ãè¦ã㨠master, slave ã©ã¡ãã«ãã»ãã·ã§ã³ãã¼ã¿ãä¿åããã¦ãã¾ãã
ãã©ã¦ã¶ã§ http://localhost:8081/loginsuccess ã«ã¢ã¯ã»ã¹ãã¾ãããã°ã¤ã³ç»é¢ã«ã¯é·ç§»ãããããã°ã¤ã³æåï¼ãã®ç»é¢ã表示ããã¾ãã
http://localhost:8082/loginsuccess ã«ã¢ã¯ã»ã¹ãã¦ãããã°ã¤ã³ç»é¢ã«ã¯é·ç§»ãããããã°ã¤ã³æåï¼ãã®ç»é¢ã表示ããã¾ãã
ãã©ã¦ã¶ã§ http://localhost:8082/logout ã«ã¢ã¯ã»ã¹ãã¦ãã°ã¢ã¦ããããã°ã¤ã³ç»é¢ã«æ»ãã¾ãã
ãã©ã¦ã¶ã§ http://localhost:8080/loginsuccess ã«ã¢ã¯ã»ã¹ããã¨ãããã°ã¤ã³æåï¼ãã®ç»é¢ã¯è¡¨ç¤ºãããããã°ã¤ã³ç»é¢ã表示ããã¾ãã
Redis ã®ãã¼ã¿ã®ç¶æ ã¯ä»¥ä¸ã®ããã«ãªã£ã¦ãã¾ããã
次ã«ãã°ã¤ã³å¾ã« Redis ããã§ã¤ã«ãªã¼ãã¼ããã§ã¤ã«ããã¯ãã¦ããã©ã® Tomcat ã«ã¢ã¯ã»ã¹ãã¦ãããã°ã¤ã³ããç¶æ ãç¶æããããã¨ã確èªãã¦ã¿ã¾ãã
ãã©ã¦ã¶ã§ http://localhost:8080/ ã«ã¢ã¯ã»ã¹ãããã°ã¤ã³ç»é¢ã表示ãã¾ããID ã« "[email protected]"ãPassword ã« "taro" ãå ¥åããã次åããèªåçã«ãã°ã¤ã³ãã ãã¯ãã§ãã¯ããããã°ã¤ã³ããã¿ã³ãã¯ãªãã¯ãã¾ããèªè¨¼ã«æåãããã°ã¤ã³æåï¼ãã®ç»é¢ã表示ããã¾ãã
6379çªãã¼ãã® Redis ã shutdown ãã6380çªãã¼ãã® Redis ã master ã«ãã¾ãã
ãã©ã¦ã¶ã§ http://localhost:8080/loginsuccess ã«ã¢ã¯ã»ã¹ãã¾ãããã°ã¤ã³ç»é¢ã«ã¯é·ç§»ãããããã°ã¤ã³æåï¼ãã®ç»é¢ã表示ããã¾ããã
http://localhost:8081/loginsuccess, http://localhost:8082/loginsuccess ã«ã¢ã¯ã»ã¹ãã¦ãããã°ã¤ã³ç»é¢ã«ã¯é·ç§»ãããããã°ã¤ã³æåï¼ãã®ç»é¢ã表示ããããã¨ã確èªã§ãã¾ãã
Web ã¢ããªã±ã¼ã·ã§ã³ã®ãã°ãè¦ã㨠6380çªãã¼ãã® Redis ã«åãæ¿ãã£ã¦ãããã¨ã確èªã§ãã¾ãã
ã»ãã·ã§ã³ ID ãå¤æ´ããããã«ãhttp://localhost:8081/logout ã«ã¢ã¯ã»ã¹ãã¦ãã°ã¤ã³ç»é¢ã«æ»ã£ãå¾ãID ã« "[email protected]"ãPassword ã« "taro" ãå ¥åããã次åããèªåçã«ãã°ã¤ã³ãã ãã¯ãã§ãã¯ããããã°ã¤ã³ããã¿ã³ãã¯ãªãã¯ãã¦ãã°ã¤ã³ãç´ãã¾ããèªè¨¼ã«æåãããã°ã¤ã³æåï¼ãã®ç»é¢ã表示ããã¾ãã
Redis ã®ãã¼ã¿ã¯ä»¥ä¸ã®ç¶æ ã§ãã
ããµã¼ãã¹ãç»é¢ãã 6379çªãã¼ãã® Redis ãèµ·åãã¾ãã
èµ·åããå¾ã¯ 6379çªãã¼ãã® Redis ã slaveã6380çªãã¼ãã® Redis ã master ã§ãã
6380çªãã¼ãã® Redis ã§å¤æ´ãããã¼ã¿ã 6379çªãã¼ãã® Redis ã¸åæ ããã¦ãããã¨ã確èªã§ãã¾ãã
6380çªãã¼ãã® Redis ã shutdown ãã6379çªãã¼ãã® Redis ã master ã«ãã¾ãã
Web ã¢ããªã±ã¼ã·ã§ã³ã®ãã°ãè¦ã㨠6379çªãã¼ãã® Redis ã«åãæ¿ãã£ã¦ãããã¨ã確èªã§ãã¾ãã
http://localhost:8080/loginsuccess, http://localhost:8081/loginsuccess, http://localhost:8082/loginsuccess ã«ã¢ã¯ã»ã¹ããã¨ããã°ã¤ã³ç»é¢ã«ã¯é·ç§»ãããããã°ã¤ã³æåï¼ãã®ç»é¢ã表示ããããã¨ã確èªã§ãã¾ãã
Redis ãå ã®ç¶æ ã«æ»ãã¾ããC:\Redis\2.8.21 ã®ä¸ã® redis2.windows-service.conf ã®æå¾ã«
slaveof 127.0.0.1 6379
ã追å ãã¾ããâ»ä»å㯠redis.windows-service.conf ã®æå¾ã«
slaveof 127.0.0.1 6380
ã®è¨è¿°ãåºåããã¦ããªãã£ãã®ã§ä¸ã®æä½ãããã¦ãã¾ããããåºåããã¦ããå ´åã«ã¯ 6379çªãã¼ãã® Redis ã§slaveof no one
ã³ãã³ããå®è¡ããå¿ è¦ãããã¾ããããµã¼ãã¹ãç»é¢ãã 6380çªãã¼ãã® Redis ãèµ·åãã¾ãã
6379çªãã¼ãã® Redis ã masterã6380çªãã¼ãã® Redis ã slave ã«ãªã£ã¦ãããã¨ã確èªãã¾ãã
以ä¸ã§åä½ç¢ºèªã¯çµããã¾ããèµ·åãã¦ãã Tomcat ï¼ã¤ãçµäºãã¾ãã
Redis Sentinel ã使ã£ã¦ã¿ãææ³
- æå㯠Redis Sentinel ã®ããã»ã¹ãè¤æ°èµ·åããå¿ è¦ãããã¨è¦ãããã®ã§çµæ§é¢åãªã®ããªã¨æãã¾ããããããæ¹ãåããã°ãããªã«é£ãããã®ã§ã¯ããã¾ããã§ããã
- æåã« master - slave æ§æã® Redis ãæ§ç¯ãã¦ãã㦠( ãã®æç¹ã§ã¯ Redis Sentinel ã®ãã¨ãèæ ®ããå¿ è¦ãããã¾ãã )ãå¾ãã Redis Sentinel ã®ç®¡çããã»ã¹ãèµ·åãããã¨ãåºæ¥ãã®ã§ãä»çµã¿ã¨ãã¦ã¯ç°¡åã ã¨æãã¾ãã
- master, slave éã®åãæ¿ããããã«åãæ¿ããã¾ãã ( ãã¼ã«ã« PC ã§ãã㤠sentinel down-after-milliseconds ã®è¨å®ãå°ãããã¦ããããã ã¨ã¯æãã¾ãã )ã
- Spring Data Redis + Redis Sentinel ã®æ§æã application.properties ã«è¨è¿°ãã¦ããã°ããã ããªã®ã§æ¥½ã§ãããããã§èªåçã«åãæ¿ããããã«ãªãã¨ã¯é©ãã§ãã
- Redis Sentinel ã使ãä¸ã§æ°ã«ãªã£ãç¹ãã¡ã¢ãã¦ããã¾ãã
- Redis ãè¨å®ãã¡ã¤ã«ãæ¸ãæãã¦ãã¾ãç¹ã¯è¦æ³¨æã§ããmaster â slave ã«åãæ¿ãã£ãå¾ã§ slave â master ã¸æ»ãéã«ã¯ãè¨å®ãã¡ã¤ã«ãç·¨éãã¦ãã¡ãã¨æåã® master - slave æ§æã«ãªãããè¨å®ããªãã¨ãå ã«æ»ãã¾ããã
- Redis ãï¼å°ã¨ãåæ¢ãã¦ããèµ·åãç´ããå ´åã«ã¯ Redis Sentinel ã®ç®¡çããã»ã¹ã Redis èµ·åå¾ã«èµ·åãç´ãå¿ è¦ãããã¾ããããããªãã¨èªåãã§ã¤ã«ãªã¼ãã¼ããã¦ãããªããªãã¾ãã
commitãPushãPull Requestããã¼ã¸](#2)
commit ãã¾ãããCode Analysisããã¤ã¢ãã°ãåºã¾ãããç¡è¦ãã¦ãCommitããã¿ã³ãã¯ãªãã¯ãã¾ãã
ã³ãã³ãã©ã¤ã³ãã以ä¸ã®ã³ãã³ããå®è¡ã㦠commit ãï¼ã¤ã«ã¾ã¨ãã¾ãã
> git rebase -i HEAD~3
> git commit --amend -m "#13 Spring Session + Redis Sentinel ã使ç¨ããè¨å®ã«å¤æ´ãã¾ããã"GitHub 㸠Pushã1.0.x-use-spring-session -> 1.0.x 㸠Pull Requestã1.0.x ã§ãã¼ã¸ã1.0.x-use-spring-session ãã©ã³ããåé¤ãããã¾ãã
ã½ã¼ã¹ã³ã¼ã
application-develop.properties, application-unittest.properties, application-product.properties
â application-develop.properties
spring.datasource.url=jdbc:log4jdbc:postgresql://localhost/ksbylending spring.datasource.username=ksbylending_user spring.datasource.password=xxxxxxxx spring.datasource.driverClassName=net.sf.log4jdbc.sql.jdbcapi.DriverSpy spring.mail.host=localhost spring.mail.port=25 spring.redis.sentinel.master=mymaster spring.redis.sentinel.nodes=localhost:6381,localhost:6382,localhost:6383 spring.messages.cache-seconds=0 spring.thymeleaf.cache=false spring.velocity.cache=false
spring.redis.host=localhost
,spring.redis.port=6379
ãåé¤ãã¦ãspring.redis.sentinel.master=mymaster
,spring.redis.sentinel.nodes=localhost:6381,localhost:6382,localhost:6383
ã追å ãã¾ãã
â application-unittest.properties
spring.datasource.url=jdbc:postgresql://localhost/ksbylending spring.datasource.username=ksbylending_user spring.datasource.password=xxxxxxxx spring.datasource.driverClassName=org.postgresql.Driver spring.mail.host=localhost spring.mail.port=25 spring.redis.sentinel.master=mymaster spring.redis.sentinel.nodes=localhost:6381,localhost:6382,localhost:6383 spring.thymeleaf.cache=true
â application-product.properties
server.tomcat.basedir=C:/webapps/ksbysample-webapp-lending spring.datasource.url=jdbc:postgresql://localhost/ksbylending spring.datasource.username=ksbylending_user spring.datasource.password=xxxxxxxx spring.datasource.driverClassName=org.postgresql.Driver spring.mail.host=localhost spring.mail.port=25 spring.redis.sentinel.master=mymaster spring.redis.sentinel.nodes=localhost:6381,localhost:6382,localhost:6383 spring.thymeleaf.cache=true
å±¥æ´
2015/08/01
åççºè¡ã