BenjaminYang In solitude, where we are least alone

使用windos电脑模拟搭建集群(四)web环境 linux+nginx+jdk+tomcat

1.使用ansible的playbook自动安装两台web主机的nginx

1.配置模块 主机清单

2.创建 playbook目录并编写安装nginx的playbook

mkdir -p playbookDir/ansible-nginx

 

[root@mage-monitor-01 ansible-nginx]# cat install_nginx.yml   
- hosts: web
  tasks:
    - name: NGINX | Installing NGINX repo rpm
      yum:
       name: http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
    - name: NGINX | Installing NGINX
      yum:
        name: nginx
        state: latest
    - name: NGINX | Starting NGINX
      service:
        name: nginx
        state: started

3.执行playbook

4.查看nginx服务

5.将nginx设置成开启启动项

2.使用playbook自动安装java环境

1.创建java的playbook目录并编写playbook

[root@mage-monitor-01 playbookDir]# mkdir ansible-java

2.编写设置远端主机的jdk环境变量配置脚本 set_jdk.sh

#!/bin/bash

echo "export JAVA_HOME=${HOME}/jdk" >> ~/.bash_profile
echo 'export CLASSPATH=.:${JAVA_HOME}/lib' >> ~/.bash_profile
echo 'export PATH=${JAVA_HOME}/bin:$PATH' >> ~/.bash_profile
source ~/.bash_profile

 

 

3.编写 安装java 环境的 playbook

---
- hosts: web 
  tasks:
    - name: 1.copy jdk to remote host
      copy: src=jdk-8u161-linux-x64.tar.gz dest=~
    - name: 2.tar jdk 
      shell: tar zxf jdk-8u161-linux-x64.tar.gz
    - name: 3.create soft link
      shell: ln -s ~/jdk1.8.0_161 jdk 
    - name: 4.copy script to remote
      copy: src=set_jdk.sh dest=~
    - name: 5.execute script
      shell: /bin/bash set_jdk.sh
    - name: 6.copy tomcat to remote host
      copy: src=apache-tomcat-8.0.50.tar.gz dest=~
    - name: 7.tar  tomcat
      shell: tar zxf apache-tomcat-8.0.50.tar.gz
    - name: 8.start tomcat
      shell: /apache-tomcat-8.0.50/bin/startup.sh 

4.执行playbook

[root@mage-monitor-01 ansible-java]# ansible-playbook intall-java.yml  

5.检查tomcat进程,如果存在进程,标识jdk环境变量没问题和tomcat也安装成功了,如果环境变量配置不成功,tomcat压根无法启动。

5.页面测试一下

 

 

posted @ 2018-07-13 17:39  benjamin杨  阅读(264)  评论(0编辑  收藏  举报