Ansible mysql在重启服务时崩溃并损坏

时间:2019-06-18 19:57:56

标签: mysql ansible

经过一整天的摸索和错误,我想出了有效的剧本,用于为Laravel应用制作简单的LEMP堆栈。

但是,一切都成功了,但是我仍然对MySQL有麻烦...

服务器安装完毕,开始使用,但是随后我添加了一个数据库和一个用户(并重新启动服务器)。

我将以下内容用作mysql默认值

mysql_packages:
  - mysql-server
  - mysql-common
  - mysql-client
  - python-mysqldb

然后我有以下任务脚本:

---

- name: install MySQL packages
  apt:
    pkg:
        "{{ mysql_packages }}"
    state: present
    update_cache: yes

- name: copy the templates to their respestive destination
  template: src={{ item.src }} dest={{ item.dest }} owner=root group=root mode={{ item.mode | default(644) }}
  with_items:
    - { src: 'my.cnf.j2', dest: '/etc/mysql/my.cnf' }
    - { src: 'root.cnf.j2', dest: '~/.my.cnf', mode: '600' }
  notify:
    - restart MySQL

- name: "Mysql Configuration - Resetting RootPassword"
  mysql_user:
    name: root
    host: "127.0.0.1"
    password: "{{ mysql_root_password }}"
    check_implicit_admin: yes
    login_user: "root"
    login_password: "toor"
    state: present

- name: Create database user with name '{{ mysql_deploy_user }}' with all database privileges
  mysql_user:
    name: "{{ mysql_deploy_user }}"
    password: "{{ mysql_user_password }}"
    priv: '*.*:ALL,GRANT'
    state: present

- name: Mysql Configuration - Creating RallyPodium & Reporting Database'
  mysql_db:
    name: "{{ mysql_database_name }}"
    state: present

但是当脚本通过时,它将引发以下内容:

fatal: [staging.rallypodium.be]: FAILED! => {"changed": false, "msg": "Unable to restart service mysql: Job for mysql.service failed because the control process exited with error code.\nSee \"systemctl status mysql.service\" and \"journalctl -xe\" for details.\n"}

当我查看服务器的状态时,我发现服务器根本没有运行,也无法停止,启动,重新启动或重新加载MySQL服务器...

journalctl -xe日志输出如下:

-- The process' exit code is 'exited' and its exit status is 1.
Jun 19 12:14:57 rpr-staging systemd[1]: mysql.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- The unit mysql.service has entered the 'failed' state with result 'exit-code'.
Jun 19 12:14:57 rpr-staging systemd[1]: Failed to start MySQL Community Server.
-- Subject: A start job for unit mysql.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- A start job for unit mysql.service has finished with a failure.
-- 
-- The job identifier is 2479 and the job result is failed.
Jun 19 12:14:57 rpr-staging systemd[1]: mysql.service: Service RestartSec=100ms expired, scheduling restart.
Jun 19 12:14:57 rpr-staging systemd[1]: mysql.service: Scheduled restart job, restart counter is at 5.
-- Subject: Automatic restarting of a unit has been scheduled
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- Automatic restarting of the unit mysql.service has been scheduled, as the result for
-- the configured Restart= setting for the unit.
Jun 19 12:14:57 rpr-staging systemd[1]: Stopped MySQL Community Server.
-- Subject: A stop job for unit mysql.service has finished
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- A stop job for unit mysql.service has finished.
-- 
-- The job identifier is 2526 and the job result is done.
Jun 19 12:14:57 rpr-staging systemd[1]: mysql.service: Start request repeated too quickly.
Jun 19 12:14:57 rpr-staging systemd[1]: mysql.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- The unit mysql.service has entered the 'failed' state with result 'exit-code'.
Jun 19 12:14:57 rpr-staging systemd[1]: Failed to start MySQL Community Server.
-- Subject: A start job for unit mysql.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- A start job for unit mysql.service has finished with a failure.
-- 
-- The job identifier is 2526 and the job result is failed.

以下是mysql日志输出的pastebin:https://pastebin.com/3EvuzdBf

关于如何解决此问题的任何想法?

如果您愿意查看所有代码,我在这里有一个gitlab仓库:https://gitlab.com/RobinRosiers/ansible-lemp

0 个答案:

没有答案