Mysql 集群技术

devtools/2024/9/25 8:26:52/

一、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/devtools/99124.html

相关文章

制作语音数据集: 爬取B站音视频+基于whisper语音识别标注

本文以制作小学课堂音频数据集为例子 1. 搜索关键字获取音视频链接 if __name__ "__main__":with sync_playwright() as playwright:searcher BLVideoSearch(playwright, headlessTrue)url searcher.make_url(keyword["小学公开课"])searcher.run(url, …

七天.NET 8操作SQLite入门到实战详细教程(选型、开发、发布、部署)

教程简介 EasySQLite是一个七天.NET 8操作SQLite入门到实战详细教程,主要是对学校班级,学生信息进行管理维护(包含选型、开发、发布、部署)! 什么是SQLite? SQLite 是一个软件库,实现了自给自…

粘包现象 | wireshark抓包的使用

在TCP协议的通信过程中,由于其面向流的特性,数据在传输过程中可能会发生粘包现象,即多个发送的数据包被接收方一次性接收,导致应用层无法正确解析数据。 1.粘包现象概述 TCP协议为了保证传输效率,可能会将多次send调…

[数据集][目标检测]电力场景输电线异物检测数据集VOC+YOLO格式2060张1类别

数据集格式:Pascal VOC格式YOLO格式(不包含分割路径的txt文件,仅仅包含jpg图片以及对应的VOC格式xml文件和yolo格式txt文件) 图片数量(jpg文件个数):2060 标注数量(xml文件个数):2060 标注数量(txt文件个数):2060 标注…

Flink常见数据源(source)使用教程(DataStream API)

前言 一个 Flink 程序,其实就是对 DataStream 的各种转换。具体来说,代码基本上都由以下几部分构成,如下图所示: 获取执行环境(execution environment)读取数据源(source)定义基于数据的转换操作(transformations)定义计算结果的输出位置(sink)触发程序执行(exec…

nginxlvshaproxy负载均衡的区别

lvs 优势:抗负载能力很强、工作稳定、不占什么流量、pv 超过 1000 万可用 1s nginx:nginx工作第7层,支持 btkp 应用本身分流&#xff0c;s,没有这个功能 nginz 对网络依赖很小&#xff0c;nginx 安装简单也稳定,流量日p<1000 万 nginx 足以能撑住, 一般不是特别大的公司都达…

Milvus在数派数据大模型业务中的实践

01. 写在前面 云南数派数据科技有限公司是一家总部位于美丽春城昆明的大模型创新企业&#xff0c;在深圳和昆明双城并立&#xff0c;设立了两个研发中心。我们的旗舰产品——SUPIEDT大模型开发平台&#xff0c;作为一款全生命周期的异构算力大模型开发平台&#xff0c;集一站式…

85.游戏改造-修改UI分辨率,面向对象方式

免责声明&#xff1a;内容仅供学习参考&#xff0c;请合法利用知识&#xff0c;禁止进行违法犯罪活动&#xff01; 内容参考于&#xff1a;易道云信息技术研究院 上一个内容&#xff1a;84.游戏改造-窗口化下的分辨率 首先剑侠情缘这个游戏它按f9是可以隐藏ui界面的&#xf…