四ansible-playbook案例(nfslnmp+可道云tomcatnginx)

犀渠玉剑良家子,白马金羁侠少年。这篇文章主要讲述四ansible-playbook案例(nfslnmp+可道云tomcatnginx)相关的知识,希望能为你提供帮助。
一、ansible安装并配置nfs服务1、环境准备?192.168.10.128作为nfs服务器
192.168.10.130作为nfs客户端
创建工作目录
mkdir /project/nfs -p?
2、编写主机清单文件?cat /project/nfs/hosts
---------------------------------------------------------------------------------------------

[webserver]
192.168.10.128
[dbserver]
192.168.10.130
[all:vars]
ansible_ssh_port=22
ansible_ssh_user=root
ansible_ssh_pass=\'123456\'
?---------------------------------------------------------------------------------------------
3、编写nfs.yaml?cat /project/nfs/nfs.yaml
?---------------------------------------------------------------------------------------------


---
- hosts: 192.168.10.128
  tasks:?
    - name: Install NFS Server
      yum: name=nfs-utils state=present
    - name: Configure NFS Server
      copy: src=https://www.songbingjia.com/android/exports.j2 dest=/etc/exports backup=yes
    - name: Create NFS Group
      group: name=www gid=666
    - name: Create NFS User
      user: name=www uid=666 group=666 shell=/sbin/nologin create_home=no
    - name: Create NFS Data
      file: path=/data state=directory owner=www group=www recurse=yes
    - name: Service NFS Server
      service: name=nfs state=started enabled=yes


- hosts: 192.168.10.130
  tasks:
    - name: Client Create NFS Data
      file: path=/nfs_tt state=directory
    - name: Client Mount NFS Server
      mount:
        src: 192.168.10.128:/data
        path: /nfs_tt
        fstype: nfs
        opts: defaults
        state: mounted
??---------------------------------------------------------------------------------------------
cat exports.j2
/data 192.168.10.1/24(rw,sync,all_squash,anonuid=666,anongid=666)
???---------------------------------------------------------------------------------------------
?ansible-playbook nfs.yaml -i hosts

四ansible-playbook案例(nfslnmp+可道云tomcatnginx)

文章图片

二、ansible安装并配置httpd服务,根据不同的主机配置不同的网站???---------------------------------------------------------------------------------------------
?cat /project/apache/hosts
[webserver]
192.168.10.128
[dbserver]
192.168.10.130
[all:vars]
ansible_ssh_port=22
ansible_ssh_user=root
ansible_ssh_pass=\'123456\'
???---------------------------------------------------------------------------------------------
?cat /project/apache/httpd.conf.j2 |grep 7788
Listen 7788
??---------------------------------------------------------------------------------------------
cat /project/apache/apache.yaml
?---
- hosts: all
  remote_user: root
  tasks:
    - name: Install Httpd Server
      yum: name=httpd state=present
    - name: Configure Httpd Server
      copy: src=https://www.songbingjia.com/android/httpd.conf.j2 dest=/etc/httpd/conf/httpd.conf
    - name: Create Httpd Group
      group: name=ttt gid=7788 state=present
    - name: Create Httpd User
      user: name=ttt uid=7788 group=7788 shell=/sbin/nologin create_home=no
    - name: Service Httpd Server
      service: name=httpd state=started enabled=yes
    - name: Configure Firewalld Server
      firewalld:
        zone: public
        port: 7788/tcp
        permanent: yes
        immediate: yes
        state: enabled


- hosts: 192.168.10.128
  tasks:
    - name: Configure Web site
      copy: content=\'web-128...\' dest=/var/www/html/index.html
- hosts: 192.168.10.130
  tasks:
    - name: Configure Web site
      copy: content=\'web-130...\' dest=/var/www/html/index.html
??---------------------------------------------------------------------------------------------
ansible-playbook apache.yaml -i hosts
三、lnmp+可道云
创建目录
/project/lnmp
??---------------------------------------------------------------------------------------------
  cat /project/lnmp/hosts
[webserver]
192.168.10.128
[dbserver]
192.168.10.130
[all:vars]
ansible_ssh_port=22
ansible_ssh_user=root
ansible_ssh_pass=\'123456\'
??---------------------------------------------------------------------------------------------
?可道云官网下载kodexplorer4.46.zip
??---------------------------------------------------------------------------------------------
cat lnmp.yaml
---
- hosts: webserver
  tasks:
    - name: Install Httpd PHP Firewalld
      yum: name=httpd,php,php-pdo,php-mbstring,php-gd,firewalld state=present
    - name: Service Httpd Server
      service: name=httpd state=started
    - name: Service Firewalld Server
      service: name=firewalld state=started
    - name: Configure Firewalld
      firewalld: port=80/tcp immediate=yes state=enabled
    - name: Copy kod cloud code
      unarchive: src=https://www.songbingjia.com/android/kodexplorer4.46.zip dest=/var/www/html/ mode=0777
    - name: Chown Directory
      file: path=/var/www/html owner=apache group=apache recurse=yes
???---------------------------------------------------------------------------------------------
ansible-playbook lnmp.yaml -i hosts
直接网页登录查看
??http://192.168.10.128/?? ###可道云用的是index.php页面,之前实验如果有index.html页面记得删掉
error:您的web服务器开启了列目录功能,为安全考虑请禁用该功能!
vi /etc/httpd/conf/httpd.conf
144     Options Indexes FollowSymLinks
改为Options Indexes FollowSymLinks
systemctl restart httpd
?三、tomcat源码包部署

[root@db2 project2]# cat tomcat.yaml
- hosts: webserver
gather_facts: no
vars:
tomcat_version: 8.5.34
tomcat_install_dir: /usr/local
tasks:
- name: install jdk8
yum: name=java-1.8.0-openjdk state=present
- name: download tomcat
get_url: url=http://mirrors.hust.edu.cn/apche/tomcat-8/v{{ tomcat_version }}/bin/apache-tomcat-{{ tomcat_version }}.tar.gz dest=/tmp
- name: unarchive tomcat-{{ tomcat_version }}.tar.gz
unarchive:
src: /tmp/apache-tomcat-{{ tomcat_version }}.tar.gz
dest: "{{ tomcat_install_dir }}"
copy: no
- name: start tomcat
shell: cd {{ tomcat_install_dir }} & &
mv apache-tomcat-{{ tomcat_version }} tomcat8 & &
cd tomcat8/bin & & nohup ./startup.sh &

四、nginx源码包安装【四ansible-playbook案例(nfslnmp+可道云tomcatnginx)】只安装了部分
- name: install deps
yum: name={{ item }} state=present
with_items:
- gcc
- make
- zlib-devel
- openssl-devel
- pcre-devel
- name:copy nginx source pkg
copy: src=https://www.songbingjia.com/android/nginx-{{ nginx_version}}.tar.gz dest=/tmp
- name: install nginx
shell: cd /tmp & &
tar -zxf nginx-{{ nginx_version }}.tar.gz & &
cd nginx-{{ nginx_version }} & &
./configure --prefix=/usr/local/nginx --user=nobody --group=nobody
--with-http_ssl_module --with-http_stub_status_module --with-stream=dynamic & &
make & & make install
- name: mkdir /usr/local/nginx/conf/vhost
file: dest=/usr/local/nginx/conf/vhost state=direstory
- name: copy nginx master configuration file
copy: src=https://www.songbingjia.com/android/nginx.conf dest=/usr/local/nginx/conf/vhost
notify: reload nginx
- name: copy nginx configuration fro wordpress
template: src=https://www.songbingjia.com/android/wordpress.conf dest=/usr/local/nginx/conf/vhost/
notify: reload nginx
- name: copy nginx systemctl service
copy: src=https://www.songbingjia.com/android/nginx.service dest=/usr/lib/systemd/system/
- name: systemctl start service
service: name=nginx state=started enabled=yes


    推荐阅读