I. minimal installation of centos II. after the virtual machine is installed, iptables is automatically enabled and chkconfig iptables is permanently disabled. set static IP address for later shell connection, mysql master server 192.168.1.41, from the server 192.168.1.42; 1.vi/etc/sysconfig/network-scripts/ifcfg-eth0 (depending on the Virtual Machine Nic, here, eth0 may also be eth1, eth2) DEVICE = eth0 BOOTPROTO = static HWADDR = 00: 26: 18: 0B: 38: c0 ONBOOT = yes IPADDR = 192.168.1.41 NETMASK = 255.255.255.0 GATEWAY = 192.168.1.1 2. IP effective:/sbin/ifdown eth0/sbin/ifup eth0 3. notify gateway to update information:/etc/init . D/network restart 4. configure DNS: vi/etc/resolv. conf nameserver 202.101.172.35 5. chattr + I/etc/resolv. change conf to read-only 6. restart system 4 use shell to log on to 192.168.1.41 (mysql master server, first set one, then copy, clone, and generate from the service area) 5 install mysql5.6.15 (download the source code package from mysql.com on the official website for installation. Http://dev.mysql.com/downloads/mysql/) 1. install the tools and libraries required to compile the source code yum install gcc-c ++ ncurses-devel perl install cmake (after mysql5.5 are installed with cmake)
Wget http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz
Tar-xzvf cmake-2.8.10.2.tar.gz
Cd cmake-2.8.10.2
./Bootstrap; make install
2. Create a mysql user and group groupadd mysql
Useradd-r-g mysql
3. Create a New mysql installation directory and Data Directory
Mkdir-p/usr/local/mysql
Mkdir-p/data/mysqldb
4. Download the mysql source code package and decompress it for installation.
Find in the official website http://dev.mysql.com/downloads/mysql/, usually the last source code about 32 m
Tar-zxv-f mysql-5.6.15.tar.gz
5. Install mysql
Cd mysql-5.6.15
Configure compilation Information
Cmake \-DCMAKE_INSTALL_PREFIX =/usr/local/mysql \-DMYSQL_UNIX_ADDR =/usr/local/mysql. sock \-DDEFAULT_CHARSET = utf8 \-DDEFAULT_COLLATION = utf8_general_ci \-rows = 1 \-rows = 1 \-rows = 1 \-DMYSQL_DATADIR =/data/mysqldb \-rows = 3306 \
-DENABLE_DOWNLOADS = 1
Make
Make install
Note: delete the cmakecache.txt file after you refresh the configuration.
################## Explanations and instructions ################### ###########################
-DCMAKE_INSTALL_PREFIX = dir_name |
Set the mysql installation directory |
-DMYSQL_UNIX_ADDR = file_name |
Set the listening socket path, which must be an absolute path name. The default value is/tmp/mysql. sock. |
-DDEFAULT_CHARSET = charset_name |
Set the character set of the server. By default, MySQL uses the latin1 (CP1252 Western Europe) Character Set. The cmake/character_sets.cmake file contains a list of allowed character set names. |
-DDEFAULT_COLLATION = collation_name |
Set the server's sorting rules. |
-DWITH_INNOBASE_STORAGE_ENGINE = 1 -DWITH_ARCHIVE_STORAGE_ENGINE = 1 -DWITH_BLACKHOLE_STORAGE_ENGINE = 1 -DWITH_PERFSCHEMA_STORAGE_ENGINE = 1 |
Storage engine options: MyISAM, MERGE, MEMORY, and CSV engines are compiled to the server by default and do not need to be explicitly installed. Use-DWITH_engine_STORAGE_ENGINE = 1 to statically compile a storage engine to the server. Available storage engine values include ARCHIVE, BLACKHOLE, EXAMPLE, FEDERATED, INNOBASE (InnoDB), PARTITION (partitioning support), and PERFSCHEMA (Performance Schema ). |
-DMYSQL_DATADIR = dir_name |
Set the mysql database file directory |
-DMYSQL_TCP_PORT = port_num |
Set the listening port of the mysql server. The default value is 3306. |
-DENABLE_DOWNLOADS = bool |
Whether to download optional files. For example, if this option is enabled (set to 1), cmake downloads the test suite used by Google to run unit tests. |
######################################## ################################
6. Modify mysql installation directory and Data Directory Permissions
Cd/usr/local/mysql
Chown-R mysql: mysql.
Cd/data/mysqldb
Chown-R mysql: mysql.
7. initialize the mysql database
Cd/usr/local/mysql
Scripts/mysql_install_db -- user = mysql -- datadir =/data/mysqldb
8. Copy the mysql service startup configuration file.
Cp/usr/local/mysql/support-files/my-default.cnf/etc/my. cnf
9. modify the configuration file
Vi/etc/my. cnf
Modify datadir =/data/mysqldb/
10. Copy the mysql Service Startup Script and add the PATH
Cp support-files/mysql. server/etc/init. d/mysqld
Vim/etc/profile
PATH =/usr/local/mysql/bin:/usr/local/mysql/lib: $ PATH
Export PATH
Source/etc/profile
11. Start the mysql service and add the service to start automatically
Service mysqld start
Chkconfig -- level 35 mysqld on
12. Check whether the mysql service is started.
Netstat-tulnp | grep 3306
Mysql-u root-p
The password is blank. If you can log on to the land, the installation is successful.
13. Modify the root password of a MySQL user
Mysqladmin-u root password '123'
6. Copy the VM and prepare for mysql master-slave replication.
1. You can clone the VM or directly press ctrl + c ctrl + v to copy the VM.
2. log on to the VM you just copied. Because the VM is copied, it needs to be modified in some places.
Hostname mysql42
/Etc/sysconfig/network-scripts/ifcfg-eth0 modify static IP to 192.168.1.42
Rm/etc/udev/rules. d/70-persistent-net.rules Delete this file
Reboot restart
3. After restarting the slave server, you can use shell to access the server. You need to modify the auto. cnf file (both copy the VM and cause the fault)
Cd/data/mysqldb/
Vi auto. cnf
Modify one or more numbers in hexadecimal notation for this long string. For example, you can change 0 to 1 and 2 to a. You can change it as needed to ensure that it is different from the 41 server.
7. mysql Master/Slave Configuration
1. Set server_id and log-bin.
192.168.1.41 master server
Vi/etc/my. cnf;
Modify server_id = 1;
Modify log-bin = mysqlbin-log;
Service mysqld restart mysql service
192.168.1.42 slave server
Vi/etc/my. cnf;
Modify server_id = 42; (whatever it is, this corresponds to the ip address)
Modify log-bin = mysqlbin-log; (the slave server can be left unspecified)
Service mysqld restart mysql service
2. master server: create an account with master-slave Permissions
Go to mysql-uroot-p123456
Grant replication slave on *. * to 'atfire' @ '%' identified by 'atfire123 ';
Atfire is the account, atfire.cn is the password
Flush privileges; refresh the permission to make the permission take effect. This statement must be executed, otherwise it will be invalid.
Show master status; view the current time of the master server bin-log, which is assumed to be mysql-bin.000001 120;
3. Set the slave server
Go to mysql-uroot-p123456
(You can enter the help change master to command to view related configurations)
CHANGE MASTER
MASTER_HOST = '1970. 168.1.41 ',
MASTER_USER = 'atfire ',
MASTER_PASSWORD = 'atfire123 ',
MASTER_PORT = 3306,
MASTER_LOG_FILE = 'mysqlbin-log.000001 ',
MASTER_LOG_POS = 120
These parameters are the master server address, user name, password, port number, bin-log file, and current bin-log address (identified in step 2)
4. start slave; enable the slave server thread
5. show slave status \ G; view slave server information
If
Slave_IO_Running = yes
Slave_ SQL _Running = yes
It indicates that the operation is successful. At this time, you can add, delete, and modify data on the master server, and the slave server will generate the same data.
If either Slave_IO_Running or Slave_ SQL _Running is yes, an error occurs.
Both no and connecting are incorrect. If both are yes, success is indicated.
According to the author's operations, it is theoretically successful (because I am operating and recording, and succeeded ,)
However, there are many possible failures.
There are many causes of errors. You can search for answers online.