双机热备(实验环境)

主服务器:ip地址192.168.100.244,mysql版本5.5.30,源码安装
从服务器:ip地址192.168.100.245

一、源码安装mysql5.5

启动目录:/usr/local/mysql
数据文件目录:/data/mysql
二进制日志目录:/data/mysql/binlog
1.添加mysql 用户(不添加用户目录)
shell> groupadd mysql
shell> useradd -r -g mysql mysql
-g, --gid GROUP
The group name or number of the user’s initial login group. The group name must exist. A group number must refer to an already existing group.  /etc/default/useradd.

-r  This flag is used to create a system account. That is, a user with a UID lower than the value of UID_MIN defined in /etc/login.defs and whose password does not expire. Note that useradd will not create a home directory for such an user, regardless of the default setting in /etc/login.defs. You have to specify -m option if you want a home directory for a system account to be created. This is an option added by Red Hat
ps:
# yum install gcc-c++
# yum install cmake`
# yum install -y ncurses-devel

2.编译和安装
shell> cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \-DDEFAULT_CHARSET=latin1 \-DDEFAULT_COLLATION=latin1_swedish_ci\-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_COMMENT="jss edition" \-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \-DSYSCONFDIR=/data/mysql/
shell> make
shell> make test
shell> make install 

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql    指定启动目录存放路径

-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock     指定sock存放路径
-DSYSCONFDIR=/data/mysql/    指定数据库文件存放位置

3.部分机器需要安装cmake[cmake-2.8.12.2.tar.gz]
shell> yum install ncurses-devel
shell> yum install bison
shell > yum install gcc*
shell>  ./bootstrap --prefix=/usr/local/cmake
shell> make
shell> make install

4.修改数据目录权限

shell> chown -R mysql:mysql mysql/
5.导入数据库文件
cd /usr/local/mysql/
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/
6.添加mysql服务
cd /usr/local/mysql/support-files/
cp -rp mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 345 mysqld on
7.修改配置文件
[client]
port            = 3306
socket          = /data/mysql/mysql.sock
default_character-set=utf8[mysqld]
port            = 3306
socket          = /data/mysql/mysql.sock
character_set_server=utf8
log-error=/data/mysql/log/error.log
datadir=/data/mysql/data/
max_connections = 16384
table_cache = 64slow_query_log_file=/data/mysql/mysql-slow.log
long_query_time=3symbolic-links=0skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
expire_logs_days = 1
log-bin=/data/mysql/binlog/mysql-bin
binlog_format=STATEMENT
server-id       = 2
innodb_buffer_pool_size = 16M
innodb_additional_mem_pool_size = 2M
innodb_log_file_size = 5M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_file_per_table=1
innodb_flush_method = O_DIRECT
innodb_file_io_threads = 4innodb_data_home_dir=/data/mysql/data
innodb_data_file_path=ibdata1:1G:autoextend

8.启动mysqld服务

/etc/init.d/mysqld start
9.添加/usr/local/mysql/bin 到PATH
在/etc/profile最后一行添加:export $PATH="$PATH:/usr/local/mysql/bin"
保存退出,执行shell> source /etc/profile
10.设置mysql密码
mysqladmin -u root password "newpassword"

二、主从配置

1.主服务器bin-log配置
log-bin=/data/mysql/binlog/mysql-bin
expire_logs_days=1
可选配置:
binlog-do-db=fire
binlog-ignore-db=mysql #这个最好不要添加,因为存储过程都是存在msyql库的proc表里

2.主库新建从库账户

grant replication slave on *.* to 'slave-user1'@'192.168.1.72' identified by 'redhat';
flush privileges;
3.关闭主服务器mysql表写入,dump数据库
3.1先查询当前正在执行的操作是否结束:show processlist;
3.2 在所有操作执行完后,
flush tables with read lock;
读master进程状态:mysql > show master status \G
此时,lock表的终端不要关闭,因为关闭会导致数据库解锁。
开启另外一个终端,dump数据库:# mysqldump -uroot -p --opt -R -B -F --databases fire | gzip > db.tar.gz
--opt --add-drop-table + --add-locks + --create-options + --disables-keys + --extended-insert + --lock-tables + --quick + --set+charset
-R 在转储的数据库中转储存储程序(函数和程序)。使用---routines产生的输出包含CREATE PROCEDURE和CREATE FUNCTION语句以重新创建子程序。但是,这些语句不包括属性,例如子程序定义者或创建和修改时间戳。这说明当重载子程序时,对它们进行创建时定义者应设置为重载用户,时间戳等于重载时间。

如果你需要创建的子程序使用原来的定义者和时间戳属性,不使用--routines。相反,使用一个具有mysql数据库相应权限的MySQL账户直接转储和重载mysql.proc表的内容。

该选项在MySQL 5.1.2中添加进来。在此之前,存储程序不转储。

-B 转储几个数据库。通常情况,mysqldump将命令行中的第1个名字参量看作数据库名,后面的名看作表名。使用该选项,它将所有名字参量看作数据库名。CREATE DATABASE IF NOT EXISTS db_name和USE db_name语句包含在每个新数据库前的输出中。
-F 开始转储前刷新MySQL服务器日志文件。该选项要求RELOAD权限。请注意如果结合--all--database(或-A)选项使用该选项,根据每个转储的数据库刷新日志。例外情况是当使用--lock-all-tables或--master-data的时候:在这种情况下,日志只刷新一次,在所有 表被锁定后刷新。如果你想要同时转储和刷新日志,应使用--flush-logs连同--lock-all-tables或--master-data。
对主库解锁:unlock tables;
打包 # tar -zcf fire.tar.gz ./fire.sql
复制到从服务器
4.配置从服务器master、开启slave进程
mysql> change master to  master_host='192.168.100.252', master_user='slave-user1', master_password='1234',                                       
master_log_file='mysql-bin.000001', master_log_pos=479;

解压主服务器的fire库 # tar -xvf fire.tar.gz 
在主服务器添加fire数据库 mysql > create database fire ;
附加数据到fire库 # mysql -uroot -p fire < fire.sql
开slave进程 mysql > start slave ;
mysql > show slave status ;
5.开启主服务器mysql表写入,查看从服务器的slave进程状态
mysql > show master status ;

三、后期维护

1.二进制日志过多的时候,用sql语句删除过多的日志
mysql> purge binary logs to 'mysql-bin.000128';
Query OK, 0 rows affected (2.92 sec)

将二进制日志删除到000128
直接进数据库查看purge_binary_logs的属性值,通过set purge_binary_logs=2来设置
2.主从服务器服务重启顺序
3.mysqldump对数据库版本的要求
一鈡情况会出现mysqldump 数据报错
mysqldump: Couldn't execute 'SET OPTION SQL_QUOTE_SHOW_CREATE=1': You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'OPTION SQL_QUOTE_SHOW_CREATE=1' at line 1 (1064)
参考网上较多的解决方案:
1)使用与mysql server相同版本的mysqldump的绝对路径进行dump,如:/usr/bin/mysqldump -uroot -p databasename > sql.sql 
2)核对数据库版本(server版本和client版本),低client版本不能导出高server版本的数据库(如5.5的mysqldump不能导出5.6的server的数据)
4. 从库配置好master后,启动slave,报错:
Slave_IO_Running: Yes
Slave_SQL_Running: No

Last_Error: Error 'Duplicate entry '11531105-356' for key 1' on query. Default database: 'db_bayu_5'. Query: 'INSERT INTO `t_quest`SET`rid`=11531105,`quest_id`=356,`type`=0,`status`=1,`target_idx`=0,`quest_loop`=0,`progress`='',`entrust`=2,`star`=0,`money_type`=0,`left_count`=1,`last_round_date`=1405642337'
分析:配置的从库和mysqldump的时间不协调,出现了很多redo错误
5. error.log
140827 10:04:41  InnoDB: ERROR: the age of the last checkpoint is 9433834,
InnoDB: which exceeds the log group capacity 9433498.
InnoDB: If you are using big BLOB or TEXT rows, you must set the
InnoDB: combined size of log files at least 10 times bigger than the
InnoDB: largest such row.

At first glance, I would say that your innodb_log_file_size is way too small. It should be bigger to do two things:

  • Accommodate any big BLOB or TEXT fields
  • Holding bigger transactions

Here is what you should do for now to see if it helps:

STEP 01) Change the following in /etc/my.cnf

[mysqld]innodb_log_buffer_size          = 32M

innodb_buffer_pool_size               = 3G

innodb_log_file_size           = 768M

STEP 02) service mysql stop

STEP 03) rm -f /var/lib/mysql/ib_logfile*

STEP 04) service mysql start

This will rebuild the following files

  • /var/lib/mysql/ib_logfile0
  • /var/lib/mysql/ib_logfile1

Give it a Try !!!

转载于:https://www.cnblogs.com/forilen/p/4271778.html

mysql5.5.30源码安装及主从搭建相关推荐

  1. mysql5.6.30源码安装_Centos7.1 for MySQL5.6.30源码安装及多实例配置

    预备工作: OS:Centos7.1 DATABASE: mysql-5.6.30.tar.gz wget http://ftp.ntu.edu.tw/MySQL/Downloads/MySQL-5. ...

  2. 源码安装mysql主从_mysql源码安装和主从同步配置

    mysql源码安装和主从同步配置 mysql介绍: MySQL 是一种关联数据库管理系统,关联数据库将数据保存在不同的表中,而不是将所有数据放在一个大仓库内,这样就增加了速度并提高了灵活性.MySQL ...

  3. mysql 5.7.17源码包_centos7 mysql5.7.17源码安装

    centos7 mysql5.7.17源码安装 **安装前准备 操作系统环境:Centos 7.2 1.解决依赖包并下载源码包至/home/soft/目录下 [root@node03 ~]# yum  ...

  4. mysql5.6.8源码安装

    mysql5.6.8源码安装 内核: [root@opop ~]# cat /etc/centos-release CentOS release 6.8 (Final) [root@opop ~]# ...

  5. mysql 5.7.18源码包下载_MYSQL数据库CentOS6.9+Mysql5.7.18源码安装详细教程

    <MYSQL数据库CentOS6.9+Mysql5.7.18源码安装详细教程>要点: 本文介绍了MYSQL数据库CentOS6.9+Mysql5.7.18源码安装详细教程,希望对您有用.如 ...

  6. centos 7 mysql 源码安装_centos7 mysql5.7.17源码安装

    centos7 mysql5.7.17源码安装 **安装前准备 操作系统环境:Centos 7.2 1.解决依赖包并下载源码包至/home/soft/目录下[root@node03 ~]# yum - ...

  7. ubuntu17.04下mysql5.7.18源码安装

    1.下载mysql5.7.18源码(带有boost) 下载 地址为https://dev.mysql.com/downloads/mysql/ 2.添加mysql组及用户 groupadd mysql ...

  8. nginx mysql5.7_Centos7+Php7+Mysql5.7+Nginx源码安装实战部署手册

    本文以Centos 7.1+Php 7.1.3+Mysql5.7.17为例,介绍Centos7+Php7+Mysql5.7+Nginx 1.10.3源码安装实战部署的过程. 一.准备工作 软件获取 二 ...

  9. mysql5.6.36源码安装_CentOS 7下rpm安装MySQL 5.6.36

    CentOS 7下本地安装了MySQL 5.7, 但和springboot整合jpa时会出现 hibernateException, 不知道为什么, 换个MySQL5.6版本的MySQL,  源码安装 ...

最新文章

  1. Python基础入门:endswith() 函数
  2. ssm 框架配置详解
  3. 学习了MPLS ×××
  4. 工作309:uni-获取vuex里面的值
  5. Vue工程模板文件 webpack打包
  6. Centos7 安装 Rabbitmq、Erlang
  7. rhel6.4部署tomcat
  8. 微软收购yahoo,不知道是好事还是坏事!?
  9. aspose转pdf乱码问题
  10. 前端开发工程师学习路线图(收藏版)
  11. pip安装scikit-learn
  12. JavaWeb — 系统结构分析
  13. SiamFC++笔记
  14. UliPad常用技巧小贴士
  15. 云栖小镇通勤车_云栖小镇在全省试点“5G车联网” 或将改变你我出行
  16. Python | 如何运行.ipynb文件?如何安装Jupyter notebook?
  17. 英语Aeroides海蓝宝石aeroides单词
  18. c语言中char97,C语言数据类型char
  19. 支持动图、一键生成,基于 React 的开源像素绘画应用 —— Pixel Art to CSS
  20. STM32的7位数据位支持

热门文章

  1. HTML5 Web Worker
  2. 电子商务实战课程-张晨光-专题视频课程
  3. Android中的动画
  4. mysql安装8.013_Mysql 8.0.13 安装
  5. OAuth 2.0攻击方法及案例总结
  6. SpringCloud学习笔记(1)- Spring Cloud Alibaba
  7. 基础练习 十进制转十六进制 C语言
  8. SQL语句、PL/SQL语句、SQL*PLUS语句结束符号
  9. kafka读写速度快的原因
  10. js验证input输入框(字母,数字,符号,中文)