Mysql 集群技术

server/2024/10/18 23:29:08/

一、Mysql 在服务器中的部署方法

  • 在企业中90%的服务器操作系统均为Linux
  • 在企业中对于Mysql的安装通常用源码编译的方式来进行
  • 官网:http://www.mysql.com

1.1 在Linux下部署mysql

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ #指定安装路径
-DMYSQL_DATADIR=/data/mysql \ #指定数据目录
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \ #指定套接字文件
-DWITH_INNOBASE_STORAGE_ENGINE=1 \ #指定启用INNODB存储引擎,默认用myisam
-DWITH_EXTRA_CHARSETS=all \ #扩展字符集
-DDEFAULT_CHARSET=utf8mb4 \ #指定默认字符集
-DDEFAULT_COLLATION=utf8mb4_unicode_ci \ #指定默认校验字符集
-DWITH_BOOST=/root/mysql-5.7.44/boost/boost_1_59_0/ #指定c++库依赖make -j2 #-j2 表示有几个核心就跑几个进程

1.1.1 安装依赖性

#下载源码安装需要用到的软件[root@mysql-node1 ~]# yum  install cmake gcc-c++ openssl-devel -y
[root@mysql-node1 ~]# yum install ncurses-devel.x86_64   rpcgen.x86_64  -y#导入libtirpc-devel-0.2.4-0.16.el7.x86_64.rpm
[root@mysql-node1 ~]# yum install libtirpc-devel-0.2.4-0.16.el7.x86_64.rpm -y

1.1.2 下载并解压源码包

#导入mysql-boost-5.7.44.tar.gz
[root@mysql-node1 ~]# tar zxf mysql-boost-5.7.44.tar.gz 

 1.1.3 源码编译安装mysql

[root@mysql-node1 ~]# cd mysql-5.7.44/[root@mysql-node1 mysql-5.7.44]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_EXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_unicode_ci -DWITH_BOOST=/root/mysql-5.7.44/boost/boost_1_59_0/ [root@mysql-node1 mysql-5.7.44]# make -j2 [root@mysql-node10 mysql-5.7.44# make install

注意!!!(当cmake出错后如果想重新检测,删除 mysql-5.7.44 中 CMakeCache.txt即可 )

1.2 部署mysql

#生成启动脚本
[root@node10 ~]# dnf install initscripts-10.11.6-1.el9.x86_64 -y
[root@node10 ~]# cd /usr/local/mysql/support-files/
[root@node10 support-files]# cp mysql.server /etc/init.d/mysqld
#修改环境变量
[root@node10 ~]# vim ~/.bash_profile
export PATH=$PATH:/usr/local/mysql/bin
[root@node10 ~]# source ~/.bash_profile
#生成配置文件
[root@node10 support-files]# yum install mariadb-connector-c-config-3.2.6-
1.el9_0.noarch -y
[root@node10 my.cnf.d]# vim /etc/my.cnf
[mysqld]
datadir=/data/mysql #指定数据目录
socket=/data/mysql/mysql.sock #指定套接字
symbolic-links=0 #数据只能存放到数据目录中,禁止链接到数据目录
#数据库初始化建立mysql基本数据
[root@node10 ~]# mysqld --initialize --user=mysql
[root@node10 ~]# /etc/init.d/mysqld start
[root@node10 ~]# chkconfig mysqld on

1.2.1 生成启动脚本

[root@mysql-node1 ~]# cd /usr/local/mysql/
[root@mysql-node1 mysql]# ls
bin  docs  include  lib  LICENSE  man  mysql-test  README  README-test  share  support-files
[root@mysql-node1 mysql]# useradd -s /sbin/nologin -M mysql
[root@mysql-node1 mysql]# mkdir /data/mysql -p
[root@mysql-node1 mysql]# chown mysql.mysql -R /data/mysql
[root@mysql-node1 mysql]# pwd
/usr/local/mysql
[root@mysql-node1 mysql]# ls
bin  docs  include  lib  LICENSE  man  mysql-test  README  README-test  share  support-files
[root@mysql-node1 mysql]# cd /usr/local/mysql/support-files/
[root@mysql-node1 support-files]# ls
magic  mysqld_multi.server  mysql-log-rotate  mysql.server
[root@mysql-node1 support-files]# cp mysql.server /etc/init.d/mysqld

1.2.2 修改环境变量

[root@mysql-node1 support-files]# vim ~/.bash_profile 
[root@mysql-node1 support-files]# cat ~/.bash_profile 
# .bash_profile# Get the aliases and functions
if [ -f ~/.bashrc ]; then. ~/.bashrc
fi# User specific environment and startup programsPATH=$PATH:$HOME/bin:/usr/local/mysql/binexport PATH
[root@mysql-node1 support-files]# source ~/.bash_profile

 

1.2.3 生成配置文件

[root@mysql-node1 support-files]# vim /etc/my.cnf
[root@mysql-node1 support-files]# cat /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
symbolic-links=0

1.2.4  数据库初始化建立mysql基本数据

[root@mysql-node1 ~]# mysqld --user mysql --initialize
[root@mysql-node1 ~]# /etc/init.d/mysqld start

1.2.5 查询所有服务状态以及设置MySQL服务启动

[root@mysql-node1 ~]# yum install chkconfig -y
[root@mysql-node1 ~]# chkconfig --list[root@mysql-node1 ~]# chkconfig  mysqld on
[root@mysql-node1 ~]# chkconfig --list

1.2.6 数据库安全初始化

[root@mysql-node1 ~]# mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root: #输入当前密码
The existing password for the user account root has expired. Please set a new password.
New password: #输入新密码
Re-enter new password: #重复密码
VALIDATE PASSWORD PLUGIN can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD plugin?
Press y|Y for Yes, any other key for No: no #是否启用密码插件
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) : no
#是否要重置密码
... skipping.
By default, a MySQL installation has an anonymous user,allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.
Normally, root should only be allowed to connect from'localhost'. This ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No): y
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

 1.2.7 测试

[root@mysql-node1 ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.44 Source distributionCopyright (c) 2000, 2023, Oracle and/or its affiliates.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 |
| sys                |
+--------------------+
4 rows in set (0.01 sec)

二、mysql的主从复制 

[root@mysql-node1 ~]# vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
symbolic-links=0
log-bin=mysql-bin
server-id=1
[root@mysql-node1 ~]# /etc/init.d/mysqld restart

 


http://www.ppmy.cn/server/104391.html

相关文章

H7-TOOL脱机烧录的UID加密操作方法,支持一键生成目标板C代码,方便大家轻松操作(2024-08-20,已发布)

UID加密使用比较方便,对应的C代码模板已经做好,使用TOOL上位机生成后,直接复制粘贴到自己的工程即可使用。返回1表示解密成功,返回0表示失败。 【UID加密原理】 1、烧录器在烧录芯片时,按照指定的算法将UID码编码为…

电路笔记(PCB):JLC PCB布局和走线基础教程笔记

对立创EDA 四层板PCB设计保姆级教程的笔记看完才发现是个虚假的教程,除了没教四层板咋画其它教了(中间的两层全是GND的作用) 文章目录 PCB布局转换原理图布局传递 板框布局确定锁定功能布局调整工具 调整器件位置**altB**放置到底层网络中隐藏…

校园志愿者服务管理系统-计算机毕设Java|springboot实战项目

🎓 作者:计算机毕设小月哥 | 软件开发专家 🖥️ 简介:8年计算机软件程序开发经验。精通Java、Python、微信小程序、安卓、大数据、PHP、.NET|C#、Golang等技术栈。 🛠️ 专业服务 🛠️ 需求定制化开发源码提…

【计算机网络】网络基础

👦个人主页:Weraphael ✍🏻作者简介:目前正在学习c和算法 ✈️专栏:Linux 🐋 希望大家多多支持,咱一起进步!😁 如果文章有啥瑕疵,希望大佬指点一二 如果文章对…

使用JMeter进行接口测试教程

安装 使用JMeter的前提需要安装JDK,需要JDK1.7以上版本目前在用的是JMeter5.2版本,大家可自行下载解压使用 运行 进入解压路径如E: \apache-jmeter-5.2\bin,双击jmeter.bat启动运行 启动后默认为英文版本,可通过Options – Cho…

2 nestjs 设计模式

回顾 MVC MVC(Model-View-Controller)设计模式是一种常用于软件开发的架构模式,旨在分离应用程序的不同部分,使得它们可以独立地开发、测试和维护。它将应用程序分为三个主要组件: Model(模型)…

UE4编安卓时Core模块为何只include Android文件夹?

Core模块 Core模块是整个引擎中最核心的模块。几乎UE4中的每个其他模块都导入Core。Engine\Source\Runtime\Core\Private下有很多文件夹&#xff0c;下面罗列一部分&#xff1a; G:\St\EngineSource\Engine\Source\Runtime\Core\Private 的目录 2024/07/18 12:02 <DIR…

2018年高教社杯全国大学生数学建模竞赛(ABCD题)题目及附件

数学建模练习&#xff0c;老师发了一个2018年的C题论文&#xff0c;让我们复现&#xff0c;结果找题目附件找好长时间&#xff0c;都是泪……好在最后找到了&#xff0c;给大家分享一下。 2018年的数学建模C题不知道官网的链接打不开了已经&#xff0c;找附件找了好长时间………