CentOS 7安装Mysql+Mycat

发布时间:2024年01月25日
  1. 安装MySQL yum源

    yum localinstall  http://repo.mysql.com//mysql57-community-release-el7-7.noarch.rpm
    
  2. 修改源

    vi /etc/yum.repos.d/mysql-community.repo
    [mysql-connectors-community]
    name=MySQL Connectors Community
    baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/
    enabled=0
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
    
    [mysql-tools-community]
    name=MySQL Tools Community
    baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch/
    enabled=0
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
    
    # Enable to use MySQL 5.5
    [mysql55-community]
    name=MySQL 5.5 Community Server
    baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/7/$basearch/
    enabled=0
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
    
    # Enable to use MySQL 5.6
    [mysql56-community]
    name=MySQL 5.6 Community Server
    baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/
    enabled=1 # 启用5.6
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
    
    [mysql57-community]
    name=MySQL 5.7 Community Server
    baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
    enabled=0 # 禁用5.7
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
    
  3. 刷新源

    yum repolist enabled | grep mysql
    
  4. 安装MySQL

    yum install mysql-community-server
    
  5. 启动MySQL

    systemctl start mysqld  #启动MySQLDB
    systemctl stop mysqld  #停止MySQLDB
    systemctl restart mysqld  #重启MySQLDB
    systemctl enable mysqld  #设置开机启动`
    
  6. 配置多实例

    • 初始化实例目录

      mysql_install_db --datadir=/var/lib/mysql/3306 --user=mysql
      mysql_install_db --datadir=/var/lib/mysql/3307 --user=mysql
      
    • 修改配置

      vi /etc/my.cnf
      [client]
      default-character-set = utf8
      
      [mysqld_multi]
      mysqld     = /usr/bin/mysqld_safe
      mysqladmin = /usr/bin/mysqladmin
      user       = root
      log        = /var/log/mysqld.multi.log
      
      [mysqld1]
      user=mysql
      port=3306
      datadir=/var/lib/mysql/3306
      socket=/var/lib/mysql/3306.sock
      pid-file=/tmp/mysql3306.pid
      log-error=/var/log/3306-error.log
      max_allowed_packet=1M
      table_open_cache=4
      thread_stack=128k
      character_set_server=utf8
      lower_case_table_names=1
      server-id=1
      log-bin = master3306-bin  #必须开启
      log-bin-index = master3306-bin.index  #必须开启
      
      [mysqld2]
      user=mysql
      port=3307
      datadir=/var/lib/mysql/3307
      socket=/var/lib/mysql/3307.sock
      pid-file=/tmp/mysql3307.pid
      log-error=/var/log/3307-error.log
      max_allowed_packet=1M
      table_open_cache=4
      thread_stack=128k
      character_set_server=utf8
      lower_case_table_names=1
      server-id=2
      log-bin=mysql3307-bin
      relay-log = relay-log
      relay-log-index = relay-log-index
      read-only = on
      

  7. 启动多实例

    mysqld_multi start
    
  8. 开放端口

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

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

    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
    
  11. 测试

    • 主库

      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. 配置

    <?xml version="1.0"?>
    <!DOCTYPE mycat:schema SYSTEM "schema.dtd">
    <mycat:schema xmlns:mycat="http://org.opencloudb/">
        <schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100">
            <table name="t_user" dataNode="dn1,dn2,dn3" rule="auto-sharding-long" />
        </schema>
        <!-- <dataNode name="dn1$0-743" dataHost="localhost1" database="db$0-743" 
            /> -->
        <dataNode name="dn1" dataHost="localhost1" database="db1" />
        <dataNode name="dn2" dataHost="localhost1" database="db2" />
        <dataNode name="dn3" dataHost="localhost1" database="db3" />
        <dataHost name="localhost1" maxCon="1000" minCon="10" balance="0"
            writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
            <heartbeat>select user()</heartbeat>
            <!-- can have multi write hosts -->
            <writeHost host="hostM1" url="localhost:3306" user="root"
                password="123456">
                <!-- can have multi read hosts -->
            </writeHost>
            <writeHost host="hostS1" url="localhost:3307" user="root"
                password="123456" />
            <!-- <writeHost host="hostM2" url="localhost:3316" user="root" password="123456"/> -->
        </dataHost>
    </mycat:schema>
    
  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根据实际情况

文章来源:https://blog.csdn.net/caryxp/article/details/135831696
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。