• ADADADADAD

    怎么使用Systemd管理下的MySQL Server[ mysql数据库 ]

    mysql数据库 时间:2024-11-26 22:12:48

    作者:文/会员上传

    简介:

    mysql 5.7 官网的rpm包,编译时指定了-DWITH_SYSTEMD=bool 参数,启用systemd管理,并且不会安装mysqld_safe和System V 初始化的脚本-DWITH_SYSTEMD=1如果还想使用mysqld_safe两

    以下为本文的正文内容,内容仅供参考!本站为公益性网站,复制本文以及下载DOC文档全部免费。

    mysql 5.7 官网的rpm包,编译时指定了-DWITH_SYSTEMD=bool 参数,启用systemd管理,并且不会安装mysqld_safe和System V 初始化的脚本

    -DWITH_SYSTEMD=1

    如果还想使用mysqld_safe两种方法:

    1.下载源码包编译;

    select version : 5.7.23

    select operating system: Source Code

    select OS Version: Gerneric Linux (Architecture Independent)

    mysql-boost-5.7.23.tar.gz

    2.下载tar文件或压缩后的tar文件(安装后的文件,解压后可直接启动)

    select version : 5.7.23

    select operating system: Red Hat Enterprise Linux / Oracle Linux

    select OS Version: Red Hat Enterprise Linux 7/ Oracle Linux 7(x86,64-bit)

    mysql-5.7.23-el7-x86_64.tar.gz / mysql-5.7.23-el7-x86_64.tar

    概览systemd:

    systemctl {start|stop|restart|status} mysqld

    兼容的System V的指令如下

    service mysqld {start|stop|restart|status}

    #设置mysql开机自启动

    systemctl enable mysqld

    配置systemd for mysql

    增加或改变systemd for mysqld的选项,方法如下:

      使用局部(localized)的systemd配置文件

      为MySQL server 进程,设定systemd 环境变量

      设定MYSQLD_OPTS systemd变量

      1)使用局部systemd配置文件

      建立目录:/etc/systemd/system/mysqld.service.d

      在目录里建立一个包含[Service]的文件,如override.conf

      [Service]
      LimitNOFILE=max_open_files
      PIDFile=/path/to/pid/file
      Nice=nice_level
      LimitCore=core_file_limit
      Environment="LD_PRELOAD=/path/to/malloc/library"
      Environment="TZ=time_zone_setting"

      新版本的systemd支持如下命令编辑

      systemctl edit mysqld

      编辑完后,别忘重新加载systemd配置,并重启mysqld服务

      systemctl daemon-reload

      systemctl restart mysqld

      在systemd中,必须使用 override.conf 配置文件来获取参数,而不是以前mysql option file(/etc/my.cnf)中[mysqld]和[mysqld_safe]选项。它不会去读这两个选项

      For additional information about using systemd rather thanmysqld_safe, seeMigrating from mysqld_safe to systemd.

      可以通过 override.conf可以设定如下参数:

      1.PIDFILE 指定pid文件

      2.LimitNOFILE, 设定mysql server文件描述符的有效数量,而不是mysqld_safe 的 --open-files-limit

      3. LimitCore, 设定最大内核文件大小, 而不是mysqld_safe 的 --core-file-size

      4.Nice, 设定mysql server排程的优先级,而不是 --niceoption formysqld_safE

      5.LD_PRELOAD, 指定mysql server 内存分配库 ,Environment="LD_PRELOAD=/path/to/malloc/library"

      6.TZ ,设定缺省的时区 Environment="TZ=time_zone_setting"

      多种方法指定mysql server 的环境变量,在systemd管理下。

      1.在override.conf 配置文件,使用 Environment 行指定,如:Environment="TZ=xx"

      2. /etc/sysconfig/mysql 中指定变量值

      LD_PRELOAD=/path/to/malloc/library

      TZ=time_zone_setting

      修改过后记得重启mysql

      systemctl restart mysqld

      3.set / unset systemd变量: MYSQLD_OPTS

      systemctl set-environment MYSQLD_OPTS="--general_log=1"

      systemctl unset-environment MYSQLD_OPTS

      MYSQLD_OPTS也可以被设定在 /etc/sysconfig/mysql文件中

      修改过后记得重启mysql

      systemctl restart mysqld

      注意:在systemd的平台上,空的数据目录,将在mysql server启动时,自动初始化数据。

      NO_INIT=true

      在/etc/sysconfig/mysql中指定 NO_INIT=true 来控制不要自动初始化数据库。

      在systemd环境下配置多实例MySQL

      rpm平台:/etc/my.cnf

      如两个实例:replica01andreplica02,配置文件如下:

      [mysqld@replica01]

      datadir=/var/lib/mysql-replica01

      socket=/var/lib/mysql-replica01/mysql.sock

      port=3307

      log-error=/var/log/mysqld-replica01.log

      [mysqld@replica02]

      datadir=/var/lib/mysql-replica02

      socket=/var/lib/mysql-replica02/mysql.sock

      port=3308

      log-error=/var/log/mysqld-replica02.log

      管理方法如下:

      systemctl start mysqld@replica01

      systemctl start mysqld@replica02

      设置开机启动

      systemctl enable mysqld@replica01

      systemctl enable mysqld@replica02

      支持通配符

      systemctl status 'mysqld@replica*'

      systemd的单元文件 unit file也是不同的

      mysqld@.servicerather thanmysqld.service

      如果想在/etc/my.cnf.d中分别配置每个实例,需要在/etc/my.cnf中增加

      !includedir /etc/my.cnf.d 把my.cnf.d的文件引入。

    怎么使用Systemd管理下的MySQL Server.docx

    将本文的Word文档下载到电脑

    推荐度:

    下载
    热门标签: mysqlserversystemd