ansible部署tomcat8
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ansible部署tomcat8相关的知识,希望对你有一定的参考价值。
其实大部分是参考别人的博文做的,自己做了修改 准备 tomcat.tar.gz 经过优化后的 参考 http://vekergu.blog.51cto.com/9966832/1672931进行优化 apr模式开启 tomcat都使用root默认目录 文件 tomcat.sh server.xml 建立一些目录,并赋予权限 /opt/src/logs 启动 sh /opt/ea/tomcat.sh cat tomcat.sh #!/bin/bash JAVA_OPTS="-Xms2048m -Xmx2048m -Xmn384m" Java_Home=/usr/java/jdk Tomcat_Home=/opt/ea/tomcat Tomcat_User=tomcat chown $Tomcat_User:$Tomcat_User -R /opt/ea/tomcat chown $Tomcat_User:$Tomcat_User -R /opt/src/logs JAVA_HOME=`echo $Java_Home` CATALINA_HOME=`echo $Tomcat_Home` CATALINA_BASE=`echo $New_instance` export JAVA_HOME JAVA_OPTS CATALINA_HOME CATALINA_BASE su `echo $Tomcat_User` $CATALINA_HOME/bin/startup.sh 客户端 /etc/profile新增 export JAVA_HOME=/usr/java/jdk export JRE_HOME=/usr/java/jdk/jre exportCLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib export PATH=$JAVA_HOME/bin:$PATH export MAVEN_HOME=/usr/java/apache-maven-3.3.1 开始吧 mkdir -p playbook 以下是playbook例子结构,具体参考http://lansgg.blog.51cto.com/5675165/1749179 参考ansible部署tomcat及 include机制 写的非常详细。 ├── hosts ├── roles │ └── http │ ├── default │ ├── files │ │ ├── apache-tomcat-8.0.33.tar.gz │ │ ├── jdk-8u65-linux-x64.tar.gz │ │ └── ROOT │ │ └── test.html │ ├── handlers │ │ └── main.yml │ ├── meta │ │ └── test │ │ └── test.html │ ├── tasks │ │ ├── bak.yml │ │ └── main.yml │ ├── templates │ │ └── test.yml │ └── vars └── site.yml cd /etc/anisble/playbook mkdir -pv roles/http/{tasks,handlers,files,vars,templates,meta,default} touch site.yml mkdir -p roles/http/files/ROOT touch roles/http/files/ROOT/test.html echo "xx">>./roles/http/files/ROOT/test.html mkdir -p /etc/ansible/playbook/roles/http/meta/test echo "xx">/etc/ansible/playbook/roles/http/meta/test/test.html vim roles/http/tasks/main.yml - name: copy jdk copy: src=/opt/src/jdk.tar.gz dest=/usr/java/ - name: tar shell: chdir=/usr/java tar xvzf jdk.tar.gz - name: rm file: dest=/usr/java/jdk.tar.gz state=absent - name: copy maven copy: src=/opt/src/mvn.tar.gz dest=/usr/java/ - name: tar shell: chdir=/usr/java tar xvzf mvn.tar.gz - name: rm file: dest=/usr/java/mvn.tar.gz state=absent - name: copy tomcat copy: src=/opt/src/tomcat.tar.gz dest=/opt/ea/ - name: tar shell: chdir=/opt/ea tar xvzf tomcat.tar.gz - name: rm file: dest=/opt/ea/tomcat.tar.gz state=absent - name: copy apr copy: src=/opt/src/apr.tar.gz dest=/usr/local - name: tar shell: chdir=/usr/local tar xvzf apr.tar.gz - name: rm file: dest=/usr/local/apr.tar.gz state=absent - name: copy tomcat.sh copy: src=/opt/src/tomcat.sh dest=/opt/ea/tomcat.sh - name: add user action: user name=tomcat password=faJxjj/6hKXPs update_password=always shell=/bin/bash home=/opt/ea - name: Modify file: path=/opt/ea/tomcat/ owner=tomcat group=tomcat mode=0755 - name: 首次启动tomcat shell: chdir=/opt/ea nohup sh tomcat.sh & - name: copy test copy: src=/etc/ansible/playbook/roles/http/meta/test dest=/opt/ea/tomcat/webapps/ tags: - updateconf notify: - stop tomcat service - start tomcat service vim roles/http/handlers/main.yml - name: stop tomcat service shell: "ps -ef |grep /opt/ea/tomcat |grep -v grep |awk ‘{print $2}‘ |xargs kill -9" - name: start tomcat service shell: chdir=/opt/ea nohup sh tomcat.sh & vim site.yml - hosts: web remote_user: root roles: - http ansible-playbook -i hosts site.yml 报错 1.server.xml要改 2.-DappHome=/opt/src/xx/db cat setenv.sh JAVA_OPTS="$JAVA_OPTS -DappHome=/opt/src/xx/db" 3.start启动时启动不了的,因为没有环境变量,所以只能用脚本 4.var 变量例子参考 Listen {{listen.0}}:{{listen.1}} listen: - "{{ansible_all_ipv4_addresses.0}}" - 8080 host_fqdn: - "{{ansible_nodename}}" 5.测试 echo "abcdefg" >> roles/http/meta/test/test.html ansible-playbook -i hosts site.yml --tags=updateconf http://ip:8080/test/test.html
本文出自 “人,要有自己的想法” 博客,请务必保留此出处http://szgb2014.blog.51cto.com/340201/1782082
以上是关于ansible部署tomcat8的主要内容,如果未能解决你的问题,请参考以下文章