使用nginx搭载小游戏

简单部署小游戏和交作业页面

环境

主机 外网ip 内网ip
web01 10.0.0.7 172.16.1.7
web02 10.0.0.8 172.16.1.8

虚拟主机配置

server {
        listen {{gm_port}};
        server_name {{gm_com}};

        location / {
                root {{gm_site_dir}};
                index index.html;
        }
}

创建角色目录

[root@m01 roles]# ansible-galaxy init games

编辑tasks目录

1.编辑虚拟主机配置
[root@m01 games]# vim tasks/copy.yml 
- name: copy games.conf.j2
  template:
    src: "games.conf.j2"
    dest: "/etc/nginx/conf.d/games.conf"
  notify:
    - "reload nginx"
2.创建站点目录
[root@m01 games]# vim tasks/dir.yml 
- name: create {{gm_site_dir}}
  file:
    path: "{{gm_site_dir}}"
    state: directory
    owner: "{{ww_w}}"
    group: "{{ww_w}}"
    recurse: yes
3.解压软件包
[root@m01 games]# vim tasks/unarchive.yml 
- name: jieya "{{gm_packages}}"
  unarchive:
    src: "{{gm_packages}}"
    dest: "{{gm_site_dir}}"
    owner: "{{ww_w}}"
    group: "{{ww_w}}"
4.include
[root@m01 games]# vim tasks/main.yml 
- include: copy.yml
- include: dir.yml
- include: unarchive.yml
5.上传软件包
[root@m01 files]# ll
total 18324
-rw-r--r-- 1 root root 18704885 Jun 23 14:25 games.tar.gz
-rw-r--r-- 1 root root    53845 Jun 23 14:34 zuoye.tar.gz
6.触发器
[root@m01 games]# vim handlers/main.yml 
- name: reload nginx
  systemd:
    name: nginx
    state: reloaded
7.编辑虚拟主机
[root@m01 games]# vim templates/games.conf.j2 
server {
        listen {{gm_port}};
        server_name {{gm_com}};

        location / {
                root {{gm_site_dir}};
                index index.html;
        }
}
8.编辑变量
#--------------------------------------------小游戏 作业页面等
##小游戏
#gm_port: "80"
#gm_com: "games.com"
#gm_site_dir: "/code/games/"
##包名
#gm_packages: "games.tar.gz"

#作业
gm_port: "80"
gm_com: "zy.com"
gm_site_dir: "/code/zy/"
#包名
gm_packages: "zuoye.tar.gz"

编辑入口文件

[root@m01 roles]# vim site.yml 
    #- { role: rsync_client,when: ansible_fqdn is match 'web*' }
    #- { role: rsync_client,when: ansible_fqdn is match 'nfs*' }
    #- { role: rsync_server,when: ansible_fqdn is match 'backup*' }

    #- { role: nfs_server,when: ansible_fqdn is match 'nfs*' }
    #- { role: nfs_client,when: ansible_fqdn is match 'web*' }

    #- { role: mount_server,when: ansible_fqdn is match 'nfs*' }
    #- { role: mount_client,when: ansible_fqdn is match 'web*' }

    #- { role: sersync,when: ansible_fqdn is match 'nfs' }

    - { role: nginx_web,when: ansible_fqdn is match 'web*' }
    #- { role: nginx_lb,when: ansible_fqdn is match 'lb*' }

    #- { role: keepalived_lb,when: ansible_fqdn is match 'lb*' }

    #- { role: lb_ssl,when: ansible_fqdn is match 'lb*' }

    #- { role: php,when: ansible_fqdn is match 'web*' }

    #- { role: mariadb,when: ansible_fqdn is match 'nfs*' }

    #- { role: wordpress,when: ansible_fqdn is match 'web*' }
    #- { role: wecenter,when: ansible_fqdn is match 'web*' }

    #- { role: mysql_master,when: ansible_fqdn is match 'db01' }
    #- { role: mysql_slave,when: ansible_fqdn is match 'db02' }

    #- { role: zabbix_server,when: ansible_fqdn is match 'nfs' }
    #- { role: zabbix_client,when: ansible_fqdn is match 'web02' }

    #- { role: jumpserver,when: ansible_fqdn is match 'jumpserver' }

    - { role: games,when: ansible_fqdn is match 'web*' }

执行

[root@m01 roles]# ansible-playbook site.yml

#解析,浏览器访问

注意

1.这套代码只适合通过nginx简单的部署一些服务
上传软件包后,通过修改变量运行ansible即可实现项目的部署

你可能感兴趣的:(使用nginx搭载小游戏)