Home Database Mysql Tutorial MySQL 服务器主从同步架构安装配置学习记录

MySQL 服务器主从同步架构安装配置学习记录

Jun 07, 2016 pm 05:41 PM

论坛的mysql数据库备份一直以来采取冷备模式,每天一次,网站必须中断访问一段时间,前期还好,数据库小,分把钟就解决问题,随着数据库越来越大,每次备份所需

论坛的mysql数据库备份一直以来采取冷备模式,每天一次,网站必须中断访问一段时间,前期还好,数据库小,分把钟就解决问题,随着数据库越来越大,每次备份所需的时间也越来越长,这种方式显然已不合适了。

网上搜索解决方案,下面这种方案感觉应该可以满足论坛现阶段的要求。

ESXI5.0 上创建两台虚拟机作为mysql服务器,一主一从,主服务器提供论坛msyql访问,从服务器用来定时备份,备份时并不影响网站正常访问,并将数据打包上传到Windows 2000的FTP服务器,Windows 服务器再同步到盛大网盘,同时达到异地和网络备份的目的,保障数据安全。

 

下面是通过学习整理的相关操作步骤:

 

一、创建两台虚拟机

 

创建两块虚拟磁盘,一块10GB,一块50GB。10GB磁盘安装系统,打算配置优化完成之后采用ESXI 磁盘的非持久模式,这样一旦系统出问题,香港虚拟主机,关机即可还原系统。50GB磁盘使用持久模式,用来存放mysql数据

两台服务器IP分别是

 

10.0.0.81

10.0.0.82

 

二、安装centos6.0并作简要初始配置

 

 

图文界面安装,按提示一步步来就可以了,只有以下几点注意事项:

1.检测光盘文件的时候选择skip跳过;

2.系统安装在10G磁盘上;

3.安装选择迷你版系统,尝试学习命令行模式的服务器操作;

4.网络配置、时区配置。

 

 

分区并格式化50G硬盘,然后挂载硬盘

 

fdisk -l

显示/dev/sdb 未分区

分区

fdisk /dev/sdb

输入m回车启动分区菜单

输入n回车创建一个新分区

输入p回车回车新建主分区

输入1回车

然后连续两次回车选择默认,将磁盘所有空间都分配给这个分区

输入P回车查看分区是否成功

输入W保存分区

格式化分区

mkfs -t ext4 /dev/sdb1

创建挂载目录并挂载硬盘

mkdir /mysql

mount /dev/sdb1 /mysql

vi /etc/fstab

添加

/dev/sdb1               /mysql                  ext4    defaults        0 0

ESC 按:wq保存退出

 

第一次给Linux硬盘分区格式时不熟悉,只给sdb1分了几MB大小,后来复制个几MB文件就满了,下面这个命令不错,可以检查下磁盘空间的使用状况,免得犯类似错误,分区空间大小一目了然

df -hl

 

 

配置防火墙

开放mysql端口 

vi /etc/sysconfig/iptables

添加

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

:wq保存

重启防火墙应用设置

service iptables restart 

 

 

安装FTP客户端,否则不能用终端使用FTP命令
rpm -Uvh 

 

时区配置很重要

 

安装vmtools

 

 

 

 

三、安装mysql5.5.28

 

 

 

yum -y install gcc gcc-c++ ncurses-devel make wget

 

 

检查了下,只需要升级以上就可以成功安装mysql 5.5.28,就不多装其他的了,不知道有没问题

yum 安装的时候会报错:Loaded plugins: fastestmirror

vi /etc/yum/pluginconf.d/fastestmirror.conf

把enabled =1改为enabled =0 就好了

 

2.创建源码包存放目录并下载相关软件

mkdir /mysql/tmp

安装完了就可以删,随便搞个目录

/mysql                #msyql安装路径。先前挂载硬盘时已创建

/mysql/tmp            #安装包路径

 

cd /mysql/tmp

 

wget ftp://mirror.switch.ch/mirror/mysql/Downloads/MySQL-5.5/mysql-5.5.28.tar.gz

wget

 

3.安装bison和cmake   


提示:MySQL 5.5 版本的安装需要这两个软件,bison用yum安装,cmake则用编译安装的办法。

yum -y install bison

tar zxvf cmake-2.8.4.tar.gz

cd cmake-2.8.4/

./configure

gmake

gmake install

cd ..

 

4.安装mysql 5.5.28

 # 创建mysql运行用户和组

groupadd mysql

useradd -g mysql -s /sbin/nologin mysql

 

tar zxvf mysql-5.5.28.tar.gz

cd mysql-5.5.28

cmake -DCMAKE_INSTALL_PREFIX=/mysql -DMYSQL_DATADIR=/mysql/data -DSYSCONFDIR=/mysql 

gmake

gmake install

cd /mysql
chmod +w /mysql
chown -R mysql:mysql /mysql
cp ./support-files/my-huge.cnf /etc/my.cnf

编辑my.cnf

vi /etc/my.cnf


[mysqld]段增加
datadir = /mysql/data
wait-timeout = 30
max_connections = 512
max_connect_errors = 10000000
#日志文件保留天数
expire-logs-days  = 7
安装数据
./scripts/mysql_install_db --user=mysql

添加系统启动
cp ./support-files/mysql.server /etc/rc.d/init.d/mysql
chmod 755 /etc/rc.d/init.d/mysql
chkconfig --add mysql
chkconfig --level 3 mysql on

 

四、mysql 初始安装配置

service mysql start

启动初始配置向导
./bin/mysql_secure_installation

参考:

 

五、创建数据库

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Reduce the use of MySQL memory in Docker Reduce the use of MySQL memory in Docker Mar 04, 2025 pm 03:52 PM

This article explores optimizing MySQL memory usage in Docker. It discusses monitoring techniques (Docker stats, Performance Schema, external tools) and configuration strategies. These include Docker memory limits, swapping, and cgroups, alongside

How to solve the problem of mysql cannot open shared library How to solve the problem of mysql cannot open shared library Mar 04, 2025 pm 04:01 PM

This article addresses MySQL's "unable to open shared library" error. The issue stems from MySQL's inability to locate necessary shared libraries (.so/.dll files). Solutions involve verifying library installation via the system's package m

How do you alter a table in MySQL using the ALTER TABLE statement? How do you alter a table in MySQL using the ALTER TABLE statement? Mar 19, 2025 pm 03:51 PM

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

Run MySQl in Linux (with/without podman container with phpmyadmin) Run MySQl in Linux (with/without podman container with phpmyadmin) Mar 04, 2025 pm 03:54 PM

This article compares installing MySQL on Linux directly versus using Podman containers, with/without phpMyAdmin. It details installation steps for each method, emphasizing Podman's advantages in isolation, portability, and reproducibility, but also

What is SQLite? Comprehensive overview What is SQLite? Comprehensive overview Mar 04, 2025 pm 03:55 PM

This article provides a comprehensive overview of SQLite, a self-contained, serverless relational database. It details SQLite's advantages (simplicity, portability, ease of use) and disadvantages (concurrency limitations, scalability challenges). C

Running multiple MySQL versions on MacOS: A step-by-step guide Running multiple MySQL versions on MacOS: A step-by-step guide Mar 04, 2025 pm 03:49 PM

This guide demonstrates installing and managing multiple MySQL versions on macOS using Homebrew. It emphasizes using Homebrew to isolate installations, preventing conflicts. The article details installation, starting/stopping services, and best pra

How do I configure SSL/TLS encryption for MySQL connections? How do I configure SSL/TLS encryption for MySQL connections? Mar 18, 2025 pm 12:01 PM

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)? What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)? Mar 21, 2025 pm 06:28 PM

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

See all articles