Distributed Architecture high availability architecture chapter _ 06_MySQL source code compilation and installation (CentOS-6.7 + MySQL-5.6)

Source: Internet
Author: User
Tags automake
Distributed Architecture high availability architecture chapter _ 06_MySQL source code compilation and installation (CentOS-67 + MySQL-56) deployment environment

Operating system: CentOS-6.6-x86_64-bin-DVD1.iso

MySQL version: mysql-5.6.22.tar.gz

Operation User: root

System IP address: 192.168.1.205

Host Name: edu-mysql-01

I. server configuration:

1. configure the network

# Vi/etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE="eth0"BOOTPROTO="static"HWADDR="00:0c:29:31:09:cf"IPV6INIT="yes"NM_CONTROLLED="yes"ONBOOT="yes"IPADDR=192.168.1.205NETMASK=255.255.255.0GATEWAY=192.168.1.1

2. set the host name

# vi /etc/sysconfig/networkNETWORKING=yesHOSTNAME=edu-mysql-01

3. set the ing between IP address and host name

# vi /etc/hosts127.0.0.1 edu-mysql-01192.168.1.205 edu-mysql-01

4. selinux of the two database servers must be disable

(Disable selinux permanently. modify/etc/selinux/config and change SELINUX to disabled)

# Vi/etc/selinux/configSELINUX = disabled

5. restart the operating system

# Reboot

II. install MySQL5.6.26 in the source code:

1. run the following command to check whether MySQL Server is installed:

# rpm -qa | grep mysqlmysql-libs-5.1.73-3.el6_5.x86_64

For CentOS7 and later versions, run the following command to view details:

# rpm -qa | grep mariadbmariadb-libs-5.5.41-2.el7_0.x86_64

(Because there is no MySQL service, there is no need to uninstall it. Mysql-libs is a required MySQL package)

(If some words can be uninstalled using the following command, rpm-e mysql // normal deletion mode or yum remove mysql -*)

2. modify the firewall settings and open port 3306:

# vi /etc/sysconfig/iptables

Add the following lines:

## MySQL-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT

Restart firewall:

# Service iptables restart

3. added the mysql User group:

# Groupadd mysql

4. add a mysql User and add it to the mysql User group:

# Useradd-r-g mysql

5. create the MySQL execution file directory (the compiled mysql program will be installed in this directory later ):

# Mkdir-p/usr/local/mysql

(The-p parameter is used to create a parent directory if the parent directory of the final directory does not exist)

6. create a MySQL database data file directory:

#mkdir -p /home/mysql/data#mkdir -p /home/mysql/logs#mkdir -p /home/mysql/temp

(Note: The preceding logs and temp directories are used to separate MySQL data files from execution program files. if you want to set different paths, modify the corresponding execution commands and database initialization scripts. In the official production environment, we recommend that you use separate partitions to mount the data directory and log Directory. different partitions belong to different disks or disk groups .)

7. add the PATH environment variable search PATH:

# Vi/etc/profile

# Add two lines at the end of the profile file

# Mysql env param

PATH =/usr/local/mysql/bin:/usr/local/mysql/lib: $ PATH

Export PATH

Make the PATH search PATH take effect immediately:

# Source/etc/profile

8. install the dependency packages required for MySQL compilation:

(Mysql 5.5 and later versions do not use./configure compilation, but use the cmake compiler. for specific cmake compilation parameters, refer to the mysql official website documentation.

Cmake, automake, autoconf, and other packages that require minimal installation for MySQL 5.5.x include: bison, gcc, gcc-c ++, and ncurses-devel ):

#yum install make cmake gcc gcc-c++ bison bison-devel ncurses ncurses-develautoconf automake

9. go to the/usr/local/src directory and upload the source code mysql-5.6.22.tar.gz to the/usr/local/src Directory:

# Cd/usr/local/src

10, start to compile and install mysql-5.2.22:

Decompress the source package:

#tar -zxvf mysql-5.6.22.tar.gz

Go to the decompressed Source Code Directory:

Use the cmake source code to install mysql. (if you want to install mysql in different paths, modify the/usr/local/mysql and/home/mysql/data paths in the following statement !)

# Cd mysql-5.6.22

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/home/mysql/data -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 -DENABLE_DOWNLOADS=1

Configuration explanation:

-DCMAKE_INSTALL_PREFIX =/usr/local/mysql installation directory-DMYSQL_DATADIR =/home/mysql/data set database storage directory-DMYSQL_UNIX_ADDR =/usr/local/mysql. sock sets UNIX socket Directory-DMYSQL_USER = mysql sets run user-DDEFAULT_CHARSET = utf8 sets default character set, default latin1-DEFAULT_COLLATION = utf8_general_ci sets default proofread rules, default latin1_general_ci-DWITH_INNOBASE_STORAGE_ENGINE = 1 add InnoDB engine support-DENABLE_DOWNLOADS = 1 automatically download optional files, such as automatically download Google's test package-DMYSQL_TCP_PORT = 3306 set the server listening port, the default value is 3306-DSYSCONFDIR =/etc. cnf directory, which is the installation directory by default)

During execution, the following error occurs:

CMake Error: Problem with tar_extract_all(): Invalid argumentCMake Error: Problem extracting tar: /usr/local/src/mysql-5.6.26/source_downloads/gmoc k-1.6.0.zip

Solution: (I didn't add-DMYSQL_UNIX_ADDR =/usr/local/mysql. sock here)

There will be a source_downloads directory under the cd mysql directory, you need to extract the unzip gmock-1.6.0.zip, and then re-execute the above configuration process. Of course, you can also remove the-DENABLE_DOWNLOADS = 1 option. there is no problem if you do not compile Google's test package, but some earlier versions may not be compiled.

11. compile the source code after cmake is complete. this step takes a long time. please wait patiently:

# Make

12. install the compiled program:

# Make install

(Note: If you need to reinstall mysql, in the/usr/local/src/mysql-5.6.22 in the execution of make install can be done, no need to cmake and make)

13. clear the installation temporary files:

# Make clean

14. modify the mysql Directory owner as a mysql User:

# Chown-Rf mysql: mysql/usr/local/mysql

# Chown-Rf mysql: mysql/home/mysql

15. enter the installation path of the mysql execution program:

# Cd/usr/local/mysql

16. execute the initialization configuration script to create the database and table that comes with the system (note: The path/home/mysql/data must be replaced with your custom database storage path ):

[root@edu-mysql-01 mysql-5.6.22]# cd /usr/local/mysql[root@edu-mysql-01 mysql]# pwd/usr/local/mysql

# Scripts/mysql_install_db -- user = mysql -- basedir =/usr/local/mysql -- datadir =/home/mysql/data

17. the configuration file my. cnf is generated under/usr/local/mysql. you need to change the owner of the configuration file:

# Ls-lah

18. note:
(1) Tips: when starting the Mysql service, I will search for my. cnf in a certain order, first in the/etc directory ., If no value is found, the system will search for my. cnf in the mysql program directory.

(2) note that after the minimal installation of CentOS 6 operating system is complete, even if mysql is not installed, there will be a my in the/etc/directory. cnf file. we recommend that you rename this file to another name. Otherwise, this file will interfere with the correct configuration of MySQL installed in the source code, resulting in a failure to start. modify/etc/my. the cnf operation is as follows:

Mv/etc/my/cnf/etc/my. cnf. bak

You can also: delete the/etc/my. cnf File: rm-rf/etc/my. cnf

If you need to use it in the production environment, you do not need to rush to start the following mysql. we recommend that you initialize/usr/local/mysql/my generated by mysql in the previous step. delete cnf, and then put your optimized mysql configuration file my. put cnf under/etc/(this is the experience of mysql replication and mysql optimization)

I am using/etc/my. cnf

19. edit/etc/my. cnf

# Vi/etc/my. cnf

[client]port=3306#socket=/usr/local/mysql/mysql.socksocket=/tmp/mysql.sock[mysqld]character-set-server=utf8collation-server=utf8_general_ciskip-external-lockingskip-name-resolveuser=mysqlport=3306basedir=/usr/local/mysqldatadir=/home/mysql/data#server_id=...#socket=/usr/local/mysql/mysql.socksocket=/tmp/mysql.socklog-error=/home/mysql/logs/mysql_error.logpid-file=/home/mysql/mysql.pidopen_files_limit=10240back_log=600max_connections=500max_connect_errors=6000wait_timeout=605800#open_tables=6000#table_cache=650#opened_talbes=630max_allowed_packet=32Msort_buffer_size=4Mjoin_buffer_size=4Mthread_cache_size=300query_cache_type=1query_cache_size=256query_cache_limit=2Mquery_cache_min_res_unit=16Ktmp_table_size=256Mmax_heap_table_size=256Mkey_buffer_size=256Mread_buffer_size=1Mread_rnd_buffer_size=16Mbulk_insert_buffer_size=64Mlower_case_table_names=1default-storage-engine=INNODBinnodb_buffer_pool_size=512innodb_log_buffer_size=32Minnodb_log_file_size=128Minnodb_flush_method=O_DIRECT##########################thread_concurrency=32long_query_time=2slow-query-log=onslow-query-log-file=/home/mysql/logs/mysql-slow.log[mysqldump]quickmax_allowed_packet=32M[mysql_safe]log-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pid

The size of innodb_buffer_pool_size is 1/3 to 1/2 of the allocated memory.

20. copy the service startup script:

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

21. start the mysql service

Service mysql start

# service mysql startStarting MySQL. SUCCESS!

22. set MySQL to automatically start the service at startup:

# Chkconfig mysql on

Set the mysql database root user's local logon password (the initial user has no password ):

# Mysqladmin-u root password 'root'

23. log on to and modify the MySQL User root password

# mysql -u root -pEnter password:mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || test |+--------------------+4 rows in set (0.00 sec)mysql> use mysql;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedmysql> update user set password=password('root') where user='root';Query OK, 4 rows affected (0.06 sec)Rows matched: 5 Changed: 4 Warnings: 0mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)

Allow root remote logon. set the remote logon password to 123456.

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;Query OK, 0 rows affected (0.00 sec)

Mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

Note: In a real production environment, do not use the root user for application operations.

24. run the security settings script. it is strongly recommended to use the production server (optional)

[Root @ edu-mysql-01 ~] #/Usr/local/mysql/bin/mysql_secure_installation

The above is the content of MySQL, distributed, and CentOS. For more information, see the Chinese PHP website (www.php1.cn )!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.