@yanglt7
2018-10-21T15:56:37.000000Z
字数 7077
阅读 826
Web集群实战
可参考文章【Web 集群实战】12_MySQL 的安装与配置
[root@ylt001 ~]# mkdir -p /data/{3306,3307}/data[root@ylt001 ~]# tree /data//data|-- 3306| `-- data`-- 3307`-- data4 directories, 0 files
[root@ylt001 3306]# cat my.cnf[client]port = 3306socket = /data/3306/mysql.sock[mysqld]port = 3306socket = /data/3306/mysql.sockbasedir = /application/mysqldatadir = /data/3306/datapid-file = /data/3306/mysql.pidrelay-log = /data/3306/relay-binrelay-log-info-file = /data/3306/relay-log.infoskip-external-lockingkey_buffer_size = 16Kmax_allowed_packet = 1Mtable_open_cache = 4sort_buffer_size = 64Kread_buffer_size = 256Kread_rnd_buffer_size = 256Knet_buffer_length = 2Kthread_stack = 128Kserver-id = 1[mysqldump]quickmax_allowed_packet = 16M[mysql]no-auto-rehash# Remove the next comment character if you are not familiar with SQL#safe-updates[myisamchk]key_buffer_size = 8Msort_buffer_size = 8M[mysqlhotcopy]interactive-timeout[mysqld_safe]log-error=/data/3306/mysql_ylt3306.errpid-file=/data/3306/mysqld.pid
[root@ylt001 3306]# cp /data/3306/my.cnf /data/3307/[root@ylt001 3306]# sed -i 's/3306/3307/g' /data/3307/my.cnf[root@ylt001 3306]# sed -i 's/server-id = 1/sever-id = 3/g' /data/3307/my.cnf[root@ylt001 3306]# touch /data/{3306/mysql_ylt3306.err,3307/mysql_ylt3307.err}[root@ylt001 3306]# tree /data/data|-- 3306| |-- data| |-- my.cnf| `-- mysql_ylt3306.err`-- 3307|-- data|-- my.cnf`-- mysql_ylt3307.err4 directories, 4 files
[root@ylt001 3306]# cat mysql#!/bin/sh#############this scripts is created by ylt at 2018-09-30#initport=3306mysql_user="root"mysql_pwd="password"CmdPath="/application/mysql/bin"mysql_sock="/data/${port}/mysql.sock"#startup functionfunction_start_mysql(){if [ ! -e "$mysql_sock" ];thenprintf "Starting MySQL...\n"/bin/sh ${CmdPath}/mysqld_safe --defaults-file=/data/${port}/my.cnf 2>&1 > /dev/null &elseprintf "MySQL is running...\n"exitfi}#stop functionfunction_stop_mysql(){if [ ! -e "$mysql_sock" ];thenprintf "MySQL is stopped...\n"exitelseprintf "Stopping MySQL...\n"${CmdPath}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql.sock shutdownfi}#restart functionfunction_restart_mysql(){printf "Restarting MySQL...\n"function_stop_mysqlsleep 2function_start_mysql}case $1 instart)function_start_mysql;;stop)function_stop_mysql;;restart)function_restart_mysql;;*)printf "Usage: /data/${port}/mysql{start|stop|restart}\n"esac
[root@ylt001 3306]# cp /data/3306/mysql /data/3307/[root@ylt001 3306]# sed -i 's/3306/3307/g' /data/3307/mysql[root@ylt001 3306]# tree /data/data|-- 3306| |-- data| |-- my.cnf| |-- mysql_ylt3306.err| `-- mysql`-- 3307|-- data|-- my.cnf|-- mysql_ylt3307.err`-- mysql4 directories, 6 files
[root@ylt001 3306]# chown -R mysql:mysql /data[root@ylt001 3306]# find /data -name mysql|xargs ls -l-rw-r--r-- 1 mysql mysql 1012 Sep 30 13:38 /data/3306/mysql-rw-r--r-- 1 mysql mysql 1012 Sep 30 13:38 /data/3307/mysql
[root@ylt001 3306]# find /data -name mysql|xargs chmod 700
[root@ylt001 3306]# find /data -name mysql -exec ls -l {} \;-rwx------ 1 mysql mysql 1012 Sep 30 13:38 /data/3307/mysql-rwx------ 1 mysql mysql 1012 Sep 30 13:38 /data/3306/mysql
[root@ylt001 3306]# ls /application/mysql/bin/mysql/application/mysql/bin/mysql
[root@ylt001 3306]# echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile[root@ylt001 3306]# tail -1 /etc/profileexport PATH=/application/mysql/bin:$PATH[root@ylt001 3306]# source /etc/profile[root@ylt001 3306]# echo $PATH/application/mysql/bin:/application/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[root@ylt001 3306]# ln -s /application/mysql/bin/* /usr/local/sbin/
[root@ylt001 3306]# cd /application/mysql/scripts/[root@ylt001 scripts]# ./mysql_install_db --basedir=/application/mysql --datadir=/data/3306/data --user=mysqlInstalling MySQL system tables...180930 13:46:31 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.180930 13:46:31 [Note] /application/mysql/bin/mysqld (mysqld 5.5.61) starting as process 102410 ...OKFilling help tables...180930 13:46:31 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.180930 13:46:31 [Note] /application/mysql/bin/mysqld (mysqld 5.5.61) starting as process 102417 ...OK...[root@ylt001 scripts]# ./mysql_install_db --basedir=/application/mysql --datadir=/data/3307/data --user=mysqlInstalling MySQL system tables...180930 13:47:48 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.180930 13:47:48 [Note] /application/mysql/bin/mysqld (mysqld 5.5.61) starting as process 102521 ...OKFilling help tables...180930 13:47:48 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.180930 13:47:48 [Note] /application/mysql/bin/mysqld (mysqld 5.5.61) starting as process 102528 ...OK...
[root@ylt001 scripts]# tree /data/data|-- 3306| |-- data| | |-- mysql| | | |-- columns_priv.MYD| | | |-- columns_priv.MYI| | | |-- columns_priv.frm| | | |-- db.MYD| | | |-- db.MYI| | | |-- db.frm...
[root@ylt001 3306]# /data/3306/mysql startStarting MySQL...[root@ylt001 3306]# /data/3307/mysql startStarting MySQL...[root@ylt001 3306]# netstat -lntup|grep 330tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN 106726/mysqldtcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 107676/mysqld
[root@ylt001 3306]# /data/3306/mysql stopStopping MySQL...
[root@ylt001 ~]# /data/3306/mysql restartRestarting MySQL...Stopping MySQL...Starting MySQL...
[root@ylt001 3306]# echo "#mysql multi instances" >> /etc/rc.local[root@ylt001 3306]# echo "/data/3306/mysql start" >> /etc/rc.local[root@ylt001 3306]# echo "/data/3307/mysql start" >> /etc/rc.local[root@ylt001 3306]# tail -3 /etc/rc.local#mysql multi instances/data/3306/mysql start/data/3307/mysql start
[root@ylt001 ~]# mysql -S /data/3306/mysql.sockWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.5.61 MySQL Community Server (GPL)Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || test |+--------------------+4 rows in set (0.00 sec)mysql> select user();+----------------+| user() |+----------------+| root@localhost |+----------------+1 row in set (0.00 sec)mysql>
[root@ylt001 ~]# mysqladmin -u root -S /data/3306/mysql.sock password 'password'# 为 mysql 设置密码[root@ylt001 ~]# mysql -uroot -p -S /data/3306/mysql.sockEnter password:Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.5.61 MySQL Community Server (GPL)...mysql>
[root@ylt001 3306]# find /data -type f -name "mysql" -exec chmod 700 {} \;[root@ylt001 3306]# find /data -type f -name "mysql" -exec chown root.root {} \;[root@ylt001 3306]# find /data -type f -name "mysql" -exec ls -l {} \;-rwx------ 1 root root 1003 Sep 30 14:20 /data/3307/mysql-rwx------ 1 root root 1003 Sep 30 14:21 /data/3306/mysql