【问题标题】:CentOS with Systemd on DockerCentOS 与 Docker 上的 Systemd
【发布时间】:2017-07-05 22:12:19
【问题描述】:

我实际上正在使用 Gitlab-CI 对我的剧本进行自动化测试,Ubuntu 运行良好,没有遇到任何问题。

实际上我遇到的问题是 CentOS 和 Systemd,首先是 Playbook(在 CentOS7 中安装 Postgres 9.5):

- name: Ensure PostgreSQL is running
  service:
    name: postgresql-9.5
    state: restarted
  ignore_errors: true   
  when:
    - ansible_os_family == 'RedHat'

所以,如果我想在容器内启动 postgres,这就是我得到的:

Failed to get D-Bus connection: Operation not permitted\nFailed to get D-Bus connection: Operation not permitted\nFailed to get D-Bus connection: Operation not permitted\nFailed to get D-Bus connection: Operation not permitted\nFailed to get D-Bus connection: Operation not permitted\n

我已经必须在特权模式下运行容器,使用 c-groups 和其他任何东西。已经尝试过不同的 Docker 容器,但没有任何效果。

【问题讨论】:

    标签: postgresql docker centos continuous-integration ansible


    【解决方案1】:

    使用 docker 时,我认为最好使用 postgres 来启动服务器。

    之类的命令
    postgres -D /opt/postgresql/data/ > /var/log/postgresql/pg_server.log 2>&1 &
    

    【讨论】:

      【解决方案2】:

      当你使用 docker 时,你没有一个功能齐全的 systemd。

      您可以使用@KJocker 建议的解决方案来制作postgresql 功能容器。或者,您可以将 systemd 配置为在容器内工作,这是一个文档 check

      【讨论】:

      • 在我启动了我的 docker-systemctl-replacement 脚本之后,我很幸运,我不必再经历启动 systemd 守护进程的麻烦了;)
      【解决方案3】:

      在 Docker 容器上使用 Ansible 时,我也遇到了同样的问题。我为此编写了 docker-systemctl-replacement。它适用于 PostgreSQL - 无需更改 Ansible 脚本,它可以在真机上进行部署。

      【讨论】:

        【解决方案4】:

        编辑你的 gitlab runner 实例的 conf /etc/gitlab-runner/config.toml

        发件人:

        [runners.docker]
            privileged = false
            volumes = ["/cache"]
        

        收件人:

        [runners.docker]
            privileged = true
            volumes = ["/sys/fs/cgroup:/sys/fs/cgroup:ro", "/cache"]
        

        添加:

        [runners.docker.tmpfs]
            "/run" = "rw"
            "/tmp" = "rw"
        [runners.docker.services_tmpfs]
            "/run" = "rw"
            "/tmp" = "rw"
        

        重启 gitlab-runner。

        在您的 docker 镜像上,编辑 getty tty1 服务以允许在 systemd 启动后自动登录用户 root

        sed -e 's|/sbin/agetty |/sbin/agetty -a root |g' -i /etc/systemd/system/getty.target.wants/getty\@tty1.service 
        

        .gitlab-ci.yml 的镜像名称部分使用该 docker 镜像并添加以下内容以启动 systemd。不要编辑入口点

          script: 
            - /lib/systemd/systemd --system --log-target=kmsg &
            - sleep 5
            - systemctl start postgresql-9.5
        

        【讨论】:

          猜你喜欢
          • 2019-01-01
          • 2017-08-29
          • 1970-01-01
          • 2017-08-31
          • 2018-02-22
          • 2016-05-22
          • 1970-01-01
          • 1970-01-01
          • 2015-06-05
          相关资源
          最近更新 更多