ansible管理机:192.168.8.35 名称:kick
tomcat主机: 192.168.8.247,192.168.8.246
memcache : 192.168.8.243,192.168.8.242
系统版本: Centos7.2
MSM--memcached session manager是一个高可用的Tomcat session共享解决方案,除了可以从本机内存快速读取Session信息(仅针对黏性Session)外,同时可使用memcached存取Session,以实现高可用,对于非黏性Session,memcached直接存储session
################ 首先需要创一个.ssh目录 ###############
#!/usr/bin/expect
#
set timeout 30
spawn ssh [email protected]
expect {
"yes/no" {
send "yes\r";exp_continue
}
"password" {
send "xiong123\r"
}
}
expect "~]# "
send "mkdir /root/.ssh\r"
send "ls /root -la\r"
expect eof
exit
# 建立双机互信
[[email protected] ~]# scp .ssh/id_rsa .ssh/authorized_keys [email protected]:/root/.ssh/
[[email protected] ~]# scp .ssh/id_rsa .ssh/authorized_keys [email protected]:/root/.ssh/
[[email protected] ~]# scp .ssh/id_rsa .ssh/authorized_keys [email protected]:/root/.ssh/
[[email protected] ~]# scp .ssh/id_rsa .ssh/authorized_keys [email protected]:/root/.ssh/
# 安装tomcat启动并开机自动启动
[[email protected] ~]# ansible tomcat -m yum -a "name=tomcat state=installed"
[[email protected] ~]# ansible tomcat -m shell -a "systemctl start tomcat"
[[email protected] ~]# ansible tomcat -m shell -a "systemctl enable tomcat"
# 复制主机中的server.xml配置文件至本地进行简单配置
[[email protected] ~]# scp 192.168.8.247:/etc/tomcat/server.xml .
# Host段增加访问路径为/www/html
[[email protected] ~]# vim server.xml
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context path="" docBase="/www/html"
reloadable="true" crossContext="true"/>
# 将配置文件直接复制到各服务器中
[[email protected] ~]# ansible tomcat -m copy -a "src=server.xml dest=/etc/tomcat/"
# 创建访问项目目录,并新建一个index.html文件并直接使用http://ipaddr:8080访问
[[email protected] ~]# ansible tomcat -m shell -a "mkdir /www/html -pv"
# 安装启动并设置开机自动启动
[[email protected] ~]# ansible memc -m yum -a "name=memcached state=installed"
[[email protected] ~]# ansible memc -m shell -a "systemctl start memcached"
[[email protected] ~]# ansible memc -m shell -a "systemctl enable memcached"
# 查看memcacehd服务器状态
[[email protected] ~]# ansible memc -m shell -a "systemctl status memcached"
# 如果需要理改选项需要在/etc/sysconfig/memcached中options中增加
# 检查服务是否安装成功
[[email protected] ~]# telnet 192.168.8.243 11211
#测试: set 定义值的名称 检索 超时时长秒 长度
set mykey 0 60 6
123456
STORED
get mykey
VALUE mykey 0 6
123456
END
# 另外一台一样的操作
# quit直接退出 stats查看状态信息
# 下载msm软件包 下载地址:https://github.com/magro/memcached-session-manager/wiki/SetupAndConfiguration#overview-over-memcached-session-manager-configuration-attributes
# 软件包:
javolution-5.4.3.1.jar
memcached-session-manager-2.1.1.jar
memcached-session-manager-tc7-2.1.1.jar # tomcat是1.7那么就下tc7其它的一样,比如8就下8
msm-javolution-serializer-2.1.1.jar
spymemcached-2.11.1.jar
# 两个tomcat机器都需要复制文件
[[email protected] msm]# scp *.jar [email protected]:/usr/share/tomcat/lib/
# 再次配置ansbile 本地的tomcat配置文件 新增如下信息
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context path="" docBase="/www/html"
reloadable="true" crossContext="true">
#管理名称为memcached
<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
# memcached节点有哪些定义
memcachedNodes="n1:192.168.8.243:11211,n2:192.168.8.242:11211"
# 故障转换节点(备份节点是哪一个)
failoverNodes="n1"
requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"
transcoderFactoryClass="de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory"
/>
</Context>
# 将修改的.xml文件复制到tomcat节点中去,然后重启服务并查看状态值
[[email protected] ~]# ansible tomcat -m copy -a "src=server.xml dest=/etc/tomcat/server.xml"
[[email protected] ~]# ansible tomcat -m shell -a "systemctl restart tomcat"
[[email protected] ~]# ansible tomcat -m shell -a "systemctl status tomcat"
##########nginx负载 ##########
http://xiong51.blog.51cto.com/5239058/1941194