zoukankan      html  css  js  c++  java
  • MySQL多实例安装

    为什么要使用多实例

    1.物理机强劲,单个项目无法把资源使用完。

    2.限制单个实例数据库大小,备份好做。

    3.资源隔离,减少互相影响。

    4.分担连接数。mysql随连接数上升,性能严重下降。

    5.充分利用资源。不同业务错开高峰混跑。

    mysql启动默认使用my.cnf文件顺序

    Default options are read from the following files in the given order:
    /etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf

    /etc/my.cnf < /etc/mysql/my.cnf < /usr/local/mysql/etc/my.cnf < ~/.my.cnf

    后面覆盖前面配置。

    innodb_buffer_size 会自动调整为128的倍数

    -----------------------------------------------------------------------------------------------

    使用strace跟踪mysqld启动,能看到详细调用。

    strace -o /tmp/11.log  -ttt /usr/local/mysql/bin/mysqld

    ......

    1529632226.754417 stat("/etc/my.cnf", {st_mode=S_IFREG|0644, st_size=9697, ...}) = 0
    1529632226.754491 open("/etc/my.cnf", O_RDONLY) = 3
    1529632226.754549 fstat(3, {st_mode=S_IFREG|0644, st_size=9697, ...}) = 0
    1529632226.754593 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f249a169000
    1529632226.754637 read(3, "[client] port = 3306 "..., 4096) = 4096
    1529632226.754745 read(3, "n_load_add ="..., 4096) = 4096
    1529632226.754832 read(3, "fer_pool_dump_pct "..., 4096) = 1505
    1529632226.754895 read(3, "", 4096) = 0
    1529632226.754942 close(3) = 0
    1529632226.754982 munmap(0x7f249a169000, 4096) = 0
    1529632226.755035 stat("/etc/mysql/my.cnf", 0x7ffe5fac6710) = -1 ENOENT (No such file or directory)
    1529632226.755088 stat("/usr/local/mysql/etc/my.cnf", 0x7ffe5fac6710) = -1 ENOENT (No such file or directory)
    1529632226.755143 stat("/root/.my.cnf", 0x7ffe5fac6710) = -1 ENOENT (No such file or directory)

    ------------------------------------------------------------------------------------------------------------------------------

    多实例安装

    1.配置文件多份。

    cp /etc/my.cnf /home/mysql/mysqldata

    sed -i 's/3306/3309/g' ./my.cnf            # socket文件记得改

    2.初始化

    /usr/local/mysql/bin/mysqld --defaults-file=/home/mysql/mysqldata/my.cnf --initialize

    3.启动mysql

    /usr/local/mysql/bin/mysqld --defaults-file=/home/mysql/mysqldata/my.cnf &

    4.修改密码

    mysql -S /tmp/mysql3309.sock -p

    alter user user() identified by 'root123';

    -------------------------------------------------------------------------------------------------------------

    修改my.cnf 中,能比较好看点

    [mysql]

    prompt="\u@\h:\p [\d]>"

    Option  Description
    c  A counter that increments for each statement you issue
    D  The full current date
    d The default database
    h The server host
    l The current delimiter (new in 5.1.12)
    m  Minutes of the current time
      A newline character
    O  The current month in three-letter format (Jan, Feb, …)
    o  The current month in numeric format
    P  am/pm
    p The current TCP/IP port or socket file
    R  The current time, in 24-hour military time (0–23)
      The current time, standard 12-hour time (1–12)
    S  Semicolon
    s  Seconds of the current time
      A tab characte

    在操作系统上有些参数需要做优化的,拷贝别人的。

    网给方面的配置, 要修改/etc/sysctl.conf文件
    增加tcp支持的队列数
    net.ipv4.tcp_max_syn_backlog = 65535
    减少断开连接时 ,资源回收
    net.ipv4.tcp_max_tw_buckets = 8000
    net.ipv4.tcp_tw_reuse = 1
    net.ipv4.tcp_tw_recycle = 1
    net.ipv4.tcp_fin_timeout = 10

    打开文件的限制
    可以便用ulimit -a目录的刍各位限制,可以修改/etc/security/limits.conf文件 增加以下内容以修改打开文件数量的限制
    *soft nofile 65535
    *hard nofile 65535
    除此之外最好在MySQL服务器上关闭iptables,selinux 等防火墙软件。

  • 相关阅读:
    授权中的with admin option和with grant option
    CentOS6.2(64bit)下mysql5.6.16主从同步配置
    linux zip命令
    从模版中找到控件的方法和找到样式的方法
    WPF 在事件中绑定命令(不可以在模版中绑定命令)
    WPF: ShowDialog() 切换到其他应用窗口后,再切换回来无法让子窗口总在最上方
    TreeViewItem实现整行选中 (两种用法)
    BitmapImage 读取内存流和显示图片
    IsKeyboardFocused -- 键盘焦点
    WPF中的imagesource 和内存图片的处理
  • 原文地址:https://www.cnblogs.com/emmm233/p/9212777.html
Copyright © 2011-2022 走看看