使用Ansible在CentOS 7上部署GROWI

环境- Environment

Ansible 2.9.3
目标节点:CentOS Linux 7.7.1908 (核心)

“Growi是什么意思?”

Markdown 可以用来编写维基,听起来是一个很强大的功能,所以个人使用也是不错的选择。
https://docs.growi.org/ja/guide/

目录结构

|-- docker_playbook.yml
|-- files
|   `-- docker-compose.yml
`-- hosts

docker_playbook.yml的中文直译为“docker批处理文件.yml”。

---
- hosts: growi
  tasks:
    - name: upgrade all packages
      yum:
       name: '*'
       state: latest

    - name: yum install for docokertools
      yum:
       name: device-mapper-persistent-data,lvm2,yum-utils,git
       state: latest
       update_cache: yes

    - name: add docker repo
      tags: dockerinst
      shell: "yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo"
      args:
        chdir: "/etc/yum.repos.d"
        creates: docker-ce.repo

    - name: yum install docker ce
      tags: dockerinst
      yum:
       name: docker-ce,docker-ce-cli,containerd.io
       state: latest
       update_cache: yes

    - name: Make sure a service is running
      tags: dockerinst
      systemd:
       state: started
       enabled: yes
       name: docker

    - name: mkdir /growi/
      tags: docker_settings
      file: 
       path: /growi/ 
       state: directory 
       owner: root 
       group: root 
       mode: 0755

    - name: git clone groei-docker-compose.git
      git: 
       repo: https://github.com/weseek/growi-docker-compose.git 
       dest: /growi/
       force: yes

    - name: copy docker-comopose.yml
      tags: files_copy
      copy:
       src:  ./files/docker-compose.yml
       dest: /growi/

    - name: docker-comopose install
      tags: docker_settings
      shell: "curl -L https://github.com/docker/compose/releases/download/1.25.4/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose"

    - name: docker-comopose chmod
      tags: docker_settings
      shell: "chmod +x /usr/local/bin/docker-compose"

docker-compose.yml 的中文释义是:docker-compose 配置文件。

为了允许从另一个服务器访问,根据官方文档的说明,我们将编辑初始设置中的端口部分。

version: '3'

services:
  app:
    build:
      context: .
      dockerfile: ./Dockerfile
    ports:
      - 3000:3000    # localhost only by default
    links:
      - mongo:mongo
      - elasticsearch:elasticsearch
    depends_on:
      - mongo
      - elasticsearch
    environment:
      - MONGO_URI=mongodb://mongo:27017/growi
      - ELASTICSEARCH_URI=http://elasticsearch:9200/growi
      - PASSWORD_SEED=changeme
      # - FILE_UPLOAD=mongodb   # activate this line if you use MongoDB GridFS rather than AWS
      # - FILE_UPLOAD=local     # activate this line if you use local storage of server rather than AWS
      # - MATHJAX=1             # activate this line if you want to use MathJax
      # - PLANTUML_URI=http://  # activate this line and specify if you use your own PlantUML server rather than public plantuml.com
      # - HACKMD_URI=http://    # activate this line and specify HackMD server URI which can be accessed from GROWI client browsers
      # - HACKMD_URI_FOR_SERVER=http://hackmd:3000  # activate this line and specify HackMD server URI which can be accessed from this server container
      # - FORCE_WIKI_MODE='public'    # activate this line to force wiki public mode
      # - FORCE_WIKI_MODE='private'   # activate this line to force wiki private mode

    command: "dockerize
              -wait tcp://mongo:27017
              -wait tcp://elasticsearch:9200
              -timeout 60s
              npm run server:prod"
    restart: unless-stopped
    volumes:
      - growi_data:/data

  mongo:
    image: mongo:3.6
    restart: unless-stopped
    volumes:
      - mongo_configdb:/data/configdb
      - mongo_db:/data/db

  elasticsearch:
    build:
      context: ./elasticsearch
      dockerfile: ./Dockerfile
    environment:
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms256m -Xmx256m"  # increase amount if you have enough memory
    ulimits:
      memlock:
        soft: -1
        hard: -1
    restart: unless-stopped
    volumes:
      - es_data:/usr/share/elasticsearch/data
      - ./elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml

volumes:
  growi_data:
  mongo_configdb:
  mongo_db:
  es_data:

主持人

请根据需要修改ansible的清单。

[growi]
192.168.1.107 ansible_user=root ansible_password=password

执行

# ansible-playbook -i hosts docker_playbook.yml

执行之后 (shí zhī

连接到目标服务器后,执行ssh命令并运行docker-compose up -d。

# cd /growi/
# docker-compose up -d
image.png
image.png
bannerAds