首页 > 代码库 > ansible部署tocmat
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
[root@haixiao 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 [root@haixiao 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.
[root@centos67 ~]# cd /opt/lansgg/ansible_playbook/ [root@centos67 ansible_playbook]# pwd /opt/lansgg/ansible_playbook
2.
[root@centos67 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
[root@centos67 ansible_playbook]#
3.
[root@centos67 ansible_playbook]# cat site.yml --- - name: Install tomcat application prod enviroment hosts:tomcat become:True roles: - http [root@centos67 ansible_playbook]# cat hosts [tomcat] 172.16.1.10 [root@centos67 ansible_playbook]#
4.
[root@centos67 tasks]# pwd /opt/lansgg/ansible_playbook/roles/http/tasks [root@centos67 tasks]# cat main.yml - name: 将jdk压缩包copy到远程主机jdk-7u72-linux-x64.tar.gz copy:src=http://www.mamicode.com/jdk-8u101-linux-x64.rpm dest=/opt/lansgg/>meta/testdest=/opt/lansgg/tomcat/webapps/ tags: -updateconf notify: - stop tomcat service - starttomcat service - name: 将某些模板文件 copy 到远程主机template:src=http://www.mamicode.com/opt/lansgg/ansible_playbook/roles/http/template/test.htmldest=/opt/lansgg/tomcat/webapps/test/test.html5
[root@centos67 handlers]# pwd /opt/lansgg/ansible_playbook/roles/http/handlers [root@centos67 handlers]# [root@centos67 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 & [root@centos67 handlers]#6
[root@centos67 ansible_playbook]# pwd /opt/lansgg/ansible_playbook [root@centos67 ansible_playbook]#ansible-playbook -i hosts site.yml7
[root@centos67 handlers]# curlhttp://172.16.1.10:8080/test/test.html 1234 [root@centos67 handlers]#
本文出自 “砖家博客” 博客,请务必保留此出处http://wsxxsl.blog.51cto.com/9085838/1853168
ansible部署tocmat
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。