在安装在/var/lib/mysql上的lv上安装mysql server 5.7

hvvq6cgz  于 2021-06-19  发布在  Mysql
关注(0)|答案(1)|浏览(349)

从两个星期开始,我就在用ansible进行mysql部署。我必须在lv上安装mysql。
在部署mysql之前,ansible脚本创建 /var/lib/mysql ,lv并安装在 /var/lib/mysql . 然后,创建mysql用户和mysql组,将0700设置在mysql目录上。完成后,ansible将部署MySQL5.7。
我的ansible代码的一部分:

- name: "Group : mysql"
  group:
    name: "mysql"
    state: "present"
  tags:
    - User mysql

- name: "user : mysql"
  user:
    name: "mysql"
    shell: "mysql"
    group: "mysql"
    createhome: "no"
    append: "True"
    state: "present"
  tags:
    - User

- name: "Set rights on mysql dir "
  file:
    path: "/var/lib/mysql"
    owner: "mysql"
    group: "mysql"
    mode: 0700
  tags:
    - mysql dir rights

- name: "mysql root password"
  debconf:
    name: "mysql-server"
    question: "mysql-server/root_password"
    value: "{{ password_root_mysql }}"
    vtype: "password"
  when: password_root_mysql is defined
  tags:
    - Install  

- name: "mysql root password confirmation"
  debconf:
    name: "mysql-server"
    question: "mysql-server/root_password_again"
    value: "{{ password_root_mysql }}"
    vtype: "password"
  when: password_root_mysql is defined
  tags:
    - Install mysql

- name: "Install : MySQL Server"
  apt:
    update_cache: "True"
    name: "mysql-server"
    install_recommends: "True"
  tags:
    - Install mysql
  notify:
    - stop mysql   

- name: "Copie du template root.cnf.j2 vers root/.my.cnf "
  template:
    src: "{{ mysql_template_rootcnf }}"
    dest: "~/.my.cnf"
    owner: "root"
    mode: "0600"
  tags:
    - Install mysql

所以当我尝试安装 mysql-server 没有任何lv和目录设置,它可以工作。但是当我准备好mysql目录时,不管是手动还是自动部署,安装都不起作用。
有什么想法吗?
ubuntu 16.04和MySQL5.7。ansible v2.7版

8wigbo56

8wigbo561#

好的,我发现了这个问题,/var/lib/mysql中的lost+found目录(lv挂载在上面)被认为是一个数据库,mysql不喜欢它。在我的代码中,我刚刚添加了:

- name: "Remove lost+found from {{ mysql_dir }}"
  file: 
    path: "{{ mysql_dir }}/lost+found"  
    state: absent

相关问题