Centos6.5 installs mysql and configures the main cluster

Ready to work

Execute the following command to install dependencies:

 

 

# yum install gcc gcc-c++ ncurses-devel zip make cmake

Execute the following command (make sure there is no mysql legacy information in the system):

rm –rf /etc/my.cnf

userdel mysql

groupdel mysql

 

 

Before installing mysql, you need to query the software related to mysql contained in the system.

 

rpm -qa | grep -i mysql //grep -i is not case sensitive, if mysql is included, the following information will be displayed:

mysql-libs-5.1.71-1.el6.i686 //It is a dependency of several software. Among them, the postfix software in the mini version depends on mysql-libs. Many suggestions on the Internet are to be deleted directly.

# yum remove mysql-libs //Or execute the following command

# rpm -e --nodeps mysql-libs-5.1.71-1.el6.i686 //This is not the best way.

install mysql

 

1. Upload mysql-5.6.22.tar.gz to /opt/soft:

# rz

2. Enter /opt/soft:

# cd  /opt/soft

3. Unzip the installation package:

# tar -zxvf mysql-5.6.22.tar.gz

4. Create the directories required for installation:

# mkdir -p /opt/usr/mysql

# mkdir -p /opt/data/mysql

# mkdir -p /opt/log/mysql

 

 
5. Enter the decompressed mysql directory:

 

 

# cd /opt/soft/mysql-5.6.22

6. Execute cmake:

# cmake -DCMAKE_INSTALL_PREFIX=/opt/usr/mysql/mysql-5.6.22 \

-DMYSQL_DATADIR=/opt/data/mysql/data \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_ARCHIVE_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DWITH_FEDERATED_STORAGE_ENGINE=1 \

-DWITH_PARTITION_STORAGE_ENGINE=1 \

-DENABLED_LOCAL_INFILE=1

7. Compile and install:
 

After successful compilation and installation, execute the following command:

# make -j2 && make install -j2

8. Upload the mysql configuration file my.cnf:

# cd /opt/usr/mysql/mysql-5.6.22/etc
#rz //(Note: my.cnf refers to the appendix, there is a slight difference between master and slave)

9. Initialize the database:

    9.1. Enter the directory:
        #cd /opt/usr/mysql/mysql-5.6.22/scripts
    9.2. Execute the database initialization command:
 

        # ./mysql_install_db --basedir=/opt/usr/mysql/mysql-5.6.22 --datadir=/opt/data/mysql --user=root --        defaults-file=/opt/usr/mysql/mysql-5.6.22/etc/my.cnf

10. Copy mysql.server under support-files to the root directory

# cd /opt/usr/mysql/mysql-5.6.22/support-files

 

# cp mysql.server ../

Edit line 283 of mysql.server and add the parameter: --user="root"

You can use :set nu to view the line number

 

 
11. Master master cluster details

 

    - Delete auto.cnf in the data_dir directory

Go to the /opt/data/mysql directory and execute the following command:

rm –rf auto.cnf (prevents the same UUID)

    - Modify the serverid in the main library /opt/usr/mysql/mysql-5.6.22/etc/my.cnf file, it is recommended to use the last digit of the current server IP
    - Modify the serverid in the file /opt/usr/mysql/mysql-5.6.22/etc/my.cnf from the library, it is recommended to use the last digit of the current server IP
    - Add the following command under [mysqld] in the /opt/usr/mysql/mysql-5.6.22/etc/my.cnf file of the main library:

auto_increment_increment=2 (the step value is 2 so that two records inserted at the same time will not conflict)

auto_increment_offset=1 (offset is 1)

log_slave_updates=1

    - Add the following command under [mysqld] in the /opt/usr/mysql/mysql-5.6.22/etc/my.cnf file of the slave library:

auto_increment_increment=2

auto_increment_offset=2 (offset is 2)

log_slave_updates=1

    - Start master library and slave library

sh mysql.server start

    - Copy the authorized account on the master library (only authorized slave libraries can synchronize)

GRANT REPLICATION SLAVE ON *.* to 'repl'@'192.168.1.%' identified by 'repl'; (pay attention to the network segment where you are, replace it with % at the end)

    - Copy the authorized account from the library (only authorized slaves can synchronize)

GRANT REPLICATION SLAVE ON *.* to 'repl'@'192.168.1.%' identified by 'repl';

    - View the offset of the main library

show master status

Record file and position variables

Generate the following command and execute the following command on the slave library:

change master to

master_host='192.168.56.101', #represents the IP of the main library

master_user='repl',

master_password='repl',

master_log_file='mysql-bin.000004',#file

master_log_pos=334;#position

Execute the name on the slave library

    - View the offset from the library

show master status

Record file and position variables

Generate the following commands and execute them on the main library:

change master to

master_host='192.168.56.102', #represents the IP of the main library

master_user='repl',

master_password='repl',

master_log_file='mysql-bin.000004', #file

master_log_pos=120; #position

    - Execute the startup command on the main library

start slave;

    - Execute commands from the library

start slave;

    - Verify master master configuration status

show slave status \G;



 

 

 

 

11.1. Create the database:
Enter mysql execution

    create database jiajiaozaixian; (if the master is successful, after the master database is created, the slave database will be automatically copied)

11.2. Create user jiajiaozaixian and password jiajiaozaixian_123 and empower

    grant all privileges on jiajiaozaixian.* to  jiajiaozaixian@'%'  identified by ' jiajiaozaixian_123'; 

 
11.3.  常见问题排查

先检查change master to 命令所指定的ip、用户等信息是否正确;然后确认防火墙已关闭(Service iptables stop);然后检查mysql.enf中增加的配置是否有误。

 

 

 

 

12. 设置mysql开机启动:

 将mysql.server这个文件copy到/etc/init.d/目录下,改名成mysql

#  cp support-files/mysql.server /etc/init.d/mysql

#  chmod 755 /etc/init.d/mysql //给mysql这个文件赋予“执行”权限

#  chkconfig --add mysql //加入到开机自动运行

#  service mysql restart //重新启动MySQL

#  chkconfig --list  mysql //查看mysql是否开机启动

 

 

 

 

附录: 主机my.cnf
[client]
port = 3306
socket = /var/lib/mysql/mysql.sock
[mysql]
no-auto-rehash
[mysqld]
user = root
port = 3306
socket = /var/lib/mysql/mysql.sock
basedir = /opt/usr/mysql/mysql-5.6.22
datadir = /opt/data/mysql
pid-file = /opt/log/mysql/mysql.pid
open_files_limit = 10240
lower_case_table_names=1
user = root
server-id = 33
log-bin=mysql-bin
binlog-do-db=jiajiaozaixian
binlog-ignore-db=mysql
slow_query_log = 1
long_query_time = 1
log_error = /opt/log/mysql/mysql-error.log
slow_query_log_file = /opt/log/mysql/mysql-slow.logi
 
auto_increment_increment=2
auto_increment_offset=1
log_slave_updates=1
 
从机my.cnf
[client]
port = 3306
socket = /opt/data/mysql/mysql.sock
[mysql]
no-auto-rehash
[mysqld]
user = root
port = 3306
socket = /opt/data/mysql/mysql.sock
basedir = /opt/usr/mysql/mysql-5.6.22
datadir = /opt/data/mysql
pid-file = /opt/log/mysql/mysql.pid
open_files_limit = 10240
lower_case_table_names=1
user = root
server-id = 36
log-bin=mysql-bin
binlog-do-db=jiajiaozaixian
binlog-ignore-db=mysql
slow_query_log = 1
long_query_time = 1
log_error = /opt/log/mysql/mysql-error.log
slow_query_log_file = /opt/log/mysql/mysql-slow.logi
auto_increment_increment=2
auto_increment_offset=2
log_slave_updates=1
 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327105715&siteId=291194637