ansible部署tocmat
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ansible部署tocmat相关的知识,希望对你有一定的参考价值。
说明:ansible-palybook批量部署tomcat以及tomcat所需要的jdk环境,以及分发站点文件
1.安装python
yum -y install zlib zlib-devel openssl openssl-devel #后期安装ansible会依赖所以 wgethttp://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgz gunzip Python-2.7.11.tgz #查看解压的结果 tar xf Python-2.7.11.tar cd Python-2.7.11 mkdir -p /application/python2.7.11 ./configure --prefix=/application/python2.7.11 make make install mv /usr/bin/python /usr/bin/python_old ln -s /application/python2.7.11/bin/python2 /usr/bin/python
2.python安装需要解决的问题
错误1
[[email protected] Python-2.7.11]# yum -y install lrzsz /usr/bin/python: error while loading sharedlibraries: libpython2.7.so.1.0: cannot open shared object file: No such file ordirectory 解决办法: vim /usr/bin/yum #!/usr/bin/python 改成 /usr/bin/python_old 错误2 [[email protected] bin]# python -V python: error while loading shared libraries:libpython2.7.so.1.0: cannot open shared object file: No such file or directory 解决办法: echo "/application/python2.7.6/lib">>/etc/ld.so.conf ldconfig python -V
3.安装pip命令为了安装特定版本的ansible
wget https://bootstrap.pypa.io/get-pip.py pip命令在python安装的路径下的bin下 /opt/service/python2.7.11/bin 所以: 把python的这个环境变量导进入 export PATH=/opt/service/python2.7.11/bin:$PATH python get-pip.py
4.安装ansible
pip install ansible==2.0.2
5.ansible基础的命令就不讲解了,直接在另外一台服务器上安装tomcat
ansible分发机:10.0.0.9 内网Ip:172.16.1.9 ansible被分发机:10.0.0.10 内网IP:172.16.1.10 #在此台机器上安装tomcat
6.在10.0.0.9
1.
[[email protected] ~]# cd /opt/lansgg/ansible_playbook/ [[email protected] ansible_playbook]# pwd /opt/lansgg/ansible_playbook
2.
[[email protected] ansible_playbook]# tree
. ├── hosts
├── roles │ └── http │ ├── default │ ├── files │ │ ├── apache-tomcat-8.0.27.tar.gz │ │ └── jdk-8u101-linux-x64.rpm │ ├── handlers │ │ └── main.yml │ ├── meta │ │ └── test │ │ └── index.html │ ├── tasks │ │ └── main.yml │ ├── template │ │ └── test.html │ └── vars └── site.yml 10 directories, 8 files
[[email protected] ansible_playbook]#
3.
[[email protected] ansible_playbook]# cat site.yml --- - name: Install tomcat application prod enviroment hosts:tomcat become:True roles: - http [[email protected] ansible_playbook]# cat hosts [tomcat] 172.16.1.10 [[email protected] ansible_playbook]#
4.
[[email protected] tasks]# pwd /opt/lansgg/ansible_playbook/roles/http/tasks [[email protected] tasks]# cat main.yml - name: 将jdk压缩包copy到远程主机jdk-7u72-linux-x64.tar.gz copy:src=jdk-8u101-linux-x64.rpm dest=/opt/lansgg/ - name: 解压jdk压缩包jdk-7u72-linux-x64.tar.gz yum:name=/opt/lansgg/jdk-8u101-linux-x64.rpm state=present - name: 将tomcat压缩包copy到远程主机apache-tomcat-7.0.68.tar.gz copy:src=apache-tomcat-8.0.27.tar.gz dest=/opt/lansgg - name: 解压tomcat压缩包 shell:chdir=/opt/lansgg tar zxvf apache-tomcat-8.0.27.tar.gz - name: 做软连接 shell:chdir=/opt/lansgg ln -sapache-tomcat-8.0.27 tomcat - name: 将tomcat压缩包 重新命名为 tomcat shell:chdir=/opt/lansgg mv apache-tomcat-8.0.27.tar.gz /tmp/ - name: 首次启动tomcat shell:chdir=/opt/lansgg/tomcat/bin nohup ./startup.sh & - name: 将 test 工程 copy 到远程主机 copy:src=/opt/lansgg/ansible_playbook/roles/http/
meta/testdest=/opt/lansgg/tomcat/webapps/ tags: -updateconf notify: - stop tomcat service - starttomcat service - name: 将某些模板文件 copy 到远程主机
template:src=/opt/lansgg/ansible_playbook/roles/http/template/test.htmldest=/opt/lansgg/tomcat/webapps/test/test.html
5
[[email protected] handlers]# pwd /opt/lansgg/ansible_playbook/roles/http/handlers [[email protected] handlers]# [[email protected] handlers]# cat main.yml #- name: stop tomcat service # command:"ps -ef |grep /opt/lansgg/tomcat |grep -v grep |awk ‘{print $2}‘ |xargskill -9" - name: start tomcat service shell:chdir=/opt/lansgg/tomcat/bin nohup ./startup.sh & [[email protected] handlers]#
6
[[email protected] ansible_playbook]# pwd /opt/lansgg/ansible_playbook [[email protected] ansible_playbook]#ansible-playbook -i hosts site.yml
7
[[email protected] handlers]# curlhttp://172.16.1.10:8080/test/test.html 1234 [[email protected] handlers]#
本文出自 “砖家博客” 博客,请务必保留此出处http://wsxxsl.blog.51cto.com/9085838/1853168
以上是关于ansible部署tocmat的主要内容,如果未能解决你的问题,请参考以下文章