CentOS7yum安装Mysql多实例,并搭建Mycat

2018/07 作者:ihunter 0 0

  1. 安装mysql:
    wget http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
    rpm -ivh mysql57-community-release-el7-9.noarch.rpm
    yum clean all
    yum makecache
    yum -y install mysql-community-client.x86_64 mysql-community-common.x86_64 mysql-community-devel.x86_64 mysql-community-libs.x86_64 mysql-community-server.x86_64
    or rpm install mysql-server
    
    启动MySQL:
    systemctl start mysqld  #启动MySQLDB
    systemctl stop mysqld  #停止MySQLDB
    systemctl restart mysqld  #重启MySQLDB
    systemctl enable mysqld  #设置开机启动`
    
    查看初始密码: grep 'temporary password' /var/log/mysqld.log
    使用初始密码登录: mysql -u root -p****  # 更改初始密码
  2. 配置多实例

    • 初始化实例目录

      /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/home/data/mysql_3306
      /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/home/data/mysql_3307
      /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/home/data/mysql_3308
      /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/home/data/mysql_3309
    • 修改配置: vi /etc/my.cnf

      [client]
      default-character-set = utf8
      
      [mysqld_multi]
      mysqld = /usr/local/mysql/bin/mysqld_safe
      mysqladmin =/usr/local/mysql/bin/mysqladmin
      log =/home/data/logs/mysqld_multi.log
      
      [mysqld6]
      basedir=/usr/local/mysql
      datadir=/home/data/mysql_3306
      port=3306
      server_id=6
      socket=/home/data/mysql_3306/mysql.sock
      symbolic-links=0
      character_set_server=utf8
      pid-file=/home/data/mysql_3306/mysql.pid
      wait_timeout=1814400
      max_connections = 1500
      [mysqld7]
      basedir=/usr/local/mysql
      datadir=/home/data/mysql_3307
      port=3307
      server_id=7
      socket=/home/data/mysql_3307/mysql.sock
      symbolic-links=0
      character_set_server=utf8
      pid-file=/home/data/mysql_3307/mysql.pid
      wait_timeout=1814400
      max_connections = 1500
      [mysqld8]
      basedir=/usr/local/mysql
      datadir=/home/data/mysql_3308
      port=3308
      server_id=8
      socket=/home/data/mysql_3308/mysql.sock
      symbolic-links=0
      character_set_server=utf8
      pid-file=/home/data/mysql_3308/mysql.pid
      wait_timeout=1814400
      max_connections = 1500
      [mysqld9]
      basedir=/usr/local/mysql
      datadir=/home/data/mysql_3309
      port=3309
      server_id=9
      socket=/home/data/mysql_3309/mysql.sock
      symbolic-links=0
      character_set_server=utf8
      pid-file=/home/data/mysql_3309/mysql.pid
      wait_timeout=1814400
      max_connections = 1500
      
      启动多实例:
      /etc/init.d/mysqld_multi start 6,7,8,9
      mysql --socket=/home/data/mysql_3306/mysql.sock
      mysql --socket=/home/data/mysql_3307/mysql.sock
      mysql --socket=/home/data/mysql_3308/mysql.sock
      mysql --socket=/home/data/mysql_3309/mysql.sock
      
      --
      set password =password('bnh1923');
      grant all on *.* to 'root'@'%' IDENTIFIED BY 'bnh1923' with grant option;
      flush privileges;
      
      --
      mysqladmin -uroot -pbnh1923 --socket=/home/data/mysql_3314/mysql.sock shutdown
      mysqld_multi --defaults-extra-file=/etc/my.cnf report
  3. 开放端口

    firewall-cmd --zone=public --add-port=3306/tcp --permanent
    firewall-cmd --zone=public --add-port=3307/tcp --permanent
    firewall-cmd --reload
  4. 连接主库

    grant replication slave on *.* to 'reply'@'localhost' identified by 'reply';
    FLUSH PRIVILEGES;
  5. 连接从库

    change master to master_host='localhost',master_user='repl',master_password='repl',master_port=3306;
    start slave;
    show slave status;## Slave_IO_Running:Yes, Slave_SQL_Running:Yes
  6. 测试

    • 主库

      create database test; -- 主库建库
    • 从库

      show databases; -- 从库查看

安装JDK

  1. 下载JDK

    http://download.oracle.com/otn-pub/java/jdk/8u65-b17/jdk-8u65-linux-x64.tar.gz?AuthParam=1446824947_759e61ddd65fdc24639703e1929d6e21
  2. 解压JDK

    ```
    tar xzvf jdk-8u65-linux-x64.tar.gz
    mv jdk1.8.0_65 /usr/local/
    ```
  3. 配置环境变量

    vi /etc/profile
    export JAVA_HOME=/usr/local/jdk1.8.0_65
    export PATH=$PATH:$JAVA_HOME/bin
    
    . /etc/profile

安装Mycat

  1. 下载Mycat

    cd /opt
    wget https://github.com/MyCATApache/Mycat-download/raw/master/1.4.1-DEV/Mycat-server-1.4.1-dev-20151104100146-linux.tar.gz
  2. 解压Mycat

    tar xzvf Mycat-server-1.4.1-dev-20151104100146-linux.tar.gz
  3. 配置

    
    
    
        
            
        
        
        
        
        
        
            select user()
            
            
                
            
            
            
        
    
  4. 启动

    cd /opt/
    ./bin/mycat start && tail -200f logs/mycat.log

安装Mycat-Web

  1. 下载

    cd /opt
    wget http://nexus.mycat.io/content/groups/public/io/mycat/mycat/Mycat-web/1.0-SNAPSHOT/Mycat-web-1.0-20151020.024535-7-20151020104455-linux.tar.gz
  2. 解压

    tar xzvf Mycat-web-1.0-20151020.024535-7-20151020104455-linux.tar.gz
  3. 启动

    cd mycat-web
    ./start.sh
  4. 访问

    点击访问 IP根据实际情况


赞(0) 更多分享

上篇: 通过MYSQL的二进制日志找回误删记录
下篇: mysql多实例安装