Linux——安装软件(mysql)

随笔2个月前发布 沉梦听雨
37 0 0

一、应用部署:

安装软件 运行某个程序或者服务
安装软件包
dnf/yum 包安装工具官方网站提供的集成软件包源码编译安装      // 源码编译的步骤 只应用于编译型语言 对于解释性语言编写的程序 采用不用的方式打包

编译型语言编写的程序: nginx解释性语言编写的程序:ansible   dnf配置程序编译的参数编译 根据第一步配置完成源码到二进制程序的编译  make安装   make install安装后配置步骤容器化应用   镜像修改配置测试功能

例、mysql

mysql官方源码编译安装的步骤:

https://dev.mysql.com/doc/refman/8.4/en/source-installation.html

mysql源码编译的前置条件:

cmake  一个全平台通用的编译框架,很多软件都是用cmake 完成编译环境配置make   编译工具   在很多平台上都可以直接安装make工具,mysql 安装时推荐使用GNU make  在有些平台上make命令是gmake 命令的别名    make 程序的版本最好在3.7.5以上mysql 8.4 使用了部分C++17的特性,最好升级c++17以体验更佳完成功能
linux 操作系统   gcc10mysql 在编译时 还需要使用c++ 或者 c99 编译器mysql 8.0 开始所有的链接默认开启加密,所以编译时需要获取ssl 函数库的支持   openssl 以及 openssl-devel还需要一个boost c++ 库,但是从mysql 8.3 开始源码包自带boost 代码ncurses 函数库 ncurses ncurses-devel保证有充足的内存空间测试脚本需要使用perl语言源码包的解压工具bison > 2.1m4  




[root@bogon packages]# dnf -y install gcc gcc-c++ make 


[root@bogon bison-3.6.2]# pwd 


/usr/src/bison-3.6.2


[root@bogon bison-3.6.2]# dnf -y install m4     //bison 软件依赖


[root@bogon bison-3.6.2]# ./configure   // 观察输出是否提示缺少依赖库

Linux——安装软件(mysql)

在源码编译时,缺少依赖如何解决?

yum provides */提示缺少的文件名上网百度




进行bison的编译安装


[root@bogon bison-3.6.2]# make -j 2 && make install


[root@bogon bison-3.6.2]# bison --version 


bison (GNU Bison) 3.6.2


Written by Robert Corbett and Richard Stallman.


 


Copyright (C) 2020 Free Software Foundation, Inc.


This is free software; see the source for copying conditions.  There is NO


warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


 


#### bison依赖安装完毕 ######


 


#### 安装cmake 编译框架 #####


[root@bogon bison-3.6.2]# cd /root/packages/


[root@bogon packages]# ls 


bison-3.6.2.tar.gz  cmake-3.30.2.tar.gz  mysql-8.4.2.tar.gz


[root@bogon packages]# tar -zxf cmake-3.30.2.tar.gz -C /usr/src/


[root@bogon packages]# cd /usr/src/cmake-3.30.2/


[root@bogon cmake-3.30.2]# ./bootstrap 

Linux——安装软件(mysql)




[root@bogon cmake-3.30.2]# dnf -y install openssl openssl-devel 


[root@bogon cmake-3.30.2]# ./bootstrap 


[root@bogon cmake-3.30.2]# make -j 2 && make install 

提示 这一步有进度条

Linux——安装软件(mysql)

Linux——安装软件(mysql)




#### cmake 安装完毕 ####


 


### 开始进行mysql 源码编译安装 ####


[root@bogon ~]# dnf -y install ncurses ncurses-devel 


[root@bogon ~]# 


[root@bogon ~]# cd packages/


[root@bogon packages]# tar -xzf mysql-8.4.2.tar.gz -C /usr/src/


[root@bogon packages]# cd /usr/src/mysql-8.4.2/


[root@bogon mysql-8.4.2]# ls 


client           Doxyfile-ignored   libchangestreams  MYSQL_VERSION      scripts        testclients


cmake            Doxyfile.in        libmysql          mysys              share          unittest


CMakeLists.txt   doxygen_resources  libs              packaging          sql            utilities


components       extra              libservices       plugin             sql-common     vio


config.h.cmake   include            LICENSE           README             storage


configure.cmake  INSTALL            man               router             strings


Docs             libbinlogevents    mysql-test        run_doxygen.cmake  support-files


[root@bogon mysql-8.4.2]# mkdir build


[root@bogon mysql-8.4.2]# cd build/


# gcc 编译工具支持


[root@bogon build]# yum install gcc-toolset-12-gcc gcc-toolset-12-gcc-c++ gcc-toolset-12-binutils gcc-toolset-12-annobin-annocheck gcc-toolset-12-annobin-plugin-gcc


# 依赖缺少


[root@bogon build]# dnf -y install libtirpc-devel


## 问题1: 这里的软件包安装不了


## 解决方案如下:


[root@bogon mysql]# dnf -y install epel-release 


Last metadata expiration check: 0:51:46 ago on Thu 29 Aug 2024 08:31:37 AM CST.


Package epel-release-9-7.el9.noarch is already installed.


Dependencies resolved.


Nothing to do.


Complete!


[root@bogon mysql]# crb enable 


Enabling CRB repo


CRB repo is enabled and named: crb


 


 


[root@bogon build]# yum -y install rpcgen


 


清理cmake缓存


[root@bogon build]# rm -f CMakeCache.txt


cmake  .. 				// 指明软件代码路径


-DCMAKE_INSTALL_PREFIX=/usr/local/mysql 		// mysql 安装路径


-DMYSQL_DATADIR=/usr/local/mysql/data 			// mysql 数据库目录


-DWITH_SSL=system 							// ssl 函数库位置 system使用系统默认


//此处值为路径时,指定ssl的安装路径


-DWITH_ZLIB=bundled 							// zlib 库的位置 使用源码库自带


// 值为路径时,指定zlib库的位置


-DWITH_INNOBASE_STORAGE_ENGINE=1 			// 安装时默认启动哪些存储引擎


// 启动innodb 存储引擎


-DWITH_ARCHIVE_STORAGE_ENGINE=1 			


-DWITH_MYISAM_STORAGE_ENGINE=1 			


-DWITH_BLACKHOLE_STORAGE_ENGINE=1 


-DENABLED_LOCAL_INFILE=1 					// 启用infile支持


-DWITH_DEBUG=0 								// 使用启用debug 功能的


-DMYSQL_TCP_PORT=3306 						// mysql tcp端口号


-DMYSQL_UNIX_ADDR=/usr/local/mysq/l/run/mysqld.sock // mysql 套接字


-DDEFAULT_CHARSET=utf8mb4 					// 默认字符集


-DDEFAULT_COLLATION=utf8mb4_0900_ai_ci 		// 扩展字符集


-DWITH_SYSTEMD=1							// 启用systemd 支持 


[root@bogon build]# cmake  .. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DWITH_SSL=system -DWITH_ZLIB=bundled -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DWITH_DEBUG=1 -DMYSQL_TCP_PORT=3306 -DMYSQL_UNIX_ADDR=/usr/local/mysq/l/run/mysqld.sock -DDEFAULT_CHARSET=utf8mb4  -DDEFAULT_COLLATION=utf8mb4_0900_ai_ci -DWITH_SYSTEMD=1 

Linux——安装软件(mysql)




[root@bogon build]# make -j 2 


 

# make 编译过程中 因为意外或者任何原因中断编译,可以在编译目录下,重新运行make

#指令,继续在上一次中断的地方继续编译

# make 执行过程中 也会因为缺少依赖等报错

# 内存不足   通过free 查看内存使用情况  可用该内存大小不低于50M 则与内存无关

# 调用的逻辑核心数过多,为了加快编译速度而同时避免因为争抢CPU 资源出现问题,建

# 议调用核心数,相对于逻辑核心数减少1-2 (lscpu 查看CPU 基本信息)

# 清理编译缓存  make clean

Linux——安装软件(mysql)

[root@bogon build]# make install

// 检查安装指令执行结果

[root@bogon build]# echo $?

 二、安装后部署




1、创建程序用户账号(这一步可以在编译前完成)


[root@bogon build]#  groupadd mysql


[root@bogon build]# useradd -r -g mysql -s /bin/false mysql


2、确保mysql 相关目录的正确权限


[root@bogon build]# cd /usr/local/mysql/


[root@bogon mysql]# chown -R mysql.mysql /usr/local/mysql/


[root@bogon mysql]# mkdir mysql-files 


[root@bogon mysql]# chown mysql.mysql mysql-files/


[root@bogon mysql]# chmod 750 mysql-files/


 


3、初始化mysql 数据


[root@bogon mysql]# vim /etc/profile 


// 打开文件后,按下大写的GG 直接锁定文本最后一行,按下o开启新一行输出


PATH=$PATH:/usr/local/mysql/bin


// 然后保存退出,注意此文件修改错误,可能导致大量命令失效,谨慎修改


[root@bogon mysql]# source  /etc/profile   


[root@bogon mysql]# echo $PATH


/root/.local/bin:/root/bin:/usr/share/Modules/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/usr/local/mysql/bin


[root@bogon mysql]# 


[root@bogon mysql]# mysqld --initialize --user=mysql 


2024-08-29T01:02:54.106027Z 0 [System] [MY-015017] [Server] MySQL Server Initialization - start.


2024-08-29T01:02:54.116997Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.4.2-debug) initializing of server in progress as process 14917


2024-08-29T01:02:54.188591Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.


2024-08-29T01:02:55.289367Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.


2024-08-29T01:03:02.452228Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Kd:(#fUsS6H(   // 临时密码,每个人不一样


 


2024-08-29T01:03:16.607332Z 0 [System] [MY-015018] [Server] MySQL Server Initialization - end.


[root@bogon mysql]# 


[root@bogon mysql]# echo 'Kd:(#fUsS6H(' >> /root/root_temp


初始化后,出现data 目录

Linux——安装软件(mysql)




4、尝试启动mysql 进程


[root@bogon mysql]# mysqld_safe --user mysql &


[1] 15004


[root@bogon mysql]# Logging to '/usr/local/mysql/data/bogon.err'.


2024-08-29T01:06:06.747831Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data


 


[root@bogon mysql]# ps -elf | grep mysql 


4 S root       15004    2171  0  80   0 - 55697 do_wai 09:06 pts/0    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --user mysql


4 S mysql      15108   15004 15  80   0 - 483905 do_pol 09:06 pts/0   00:00:04 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --user mysql --log-error=bogon.err --pid-file=bogon.pid


0 S root       15155    2171  0  80   0 - 55417 pipe_r 09:06 pts/0    00:00:00 grep --color=auto mysql


[root@bogon mysql]# mysql -u root -p$(cat /root/root_temp)


mysql: [Warning] Using a password on the command line interface can be insecure.


Welcome to the MySQL monitor.  Commands end with ; or g.


Your MySQL connection id is 9


Server version: 8.4.2-debug


 


Copyright (c) 2000, 2024, 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> alter user root@localhost identified by 'redhat1~';   // 修改密码


Query OK, 0 rows affected (0.02 sec)


 


mysql> show databases;


+--------------------+


| Database           |


+--------------------+


| information_schema |


| mysql              |


| performance_schema |


| sys                |


+--------------------+


4 rows in set (0.03 sec)


 


mysql> create database webapp;


Query OK, 1 row affected (0.01 sec)


 


mysql> show databases;


+--------------------+


| Database           |


+--------------------+


| information_schema |


| mysql              |


| performance_schema |


| sys                |


| webapp             |


+--------------------+


5 rows in set (0.01 sec)


 


mysql> exit


Bye


 


5、使用systemctl 控制服务启动


[root@bogon mysql]# ls usr/lib/systemd/system/


mysqld.service  mysqld@.service  mysqlrouter.service


[root@bogon mysql]# cp  /usr/local/mysql/usr/lib/systemd/system/* /usr/lib/systemd/system/


[root@bogon mysql]# systemctl daemon-reload 


[root@bogon mysql]# killall mysqld


[root@bogon mysql]# killall mysqld


[root@bogon mysql]# 2024-08-29T01:13:04.137062Z mysqld_safe mysqld from pid file /usr/local/mysql/data/bogon.pid ended


 


[1]+  Done                    mysqld_safe --user mysql


[root@bogon mysql]# 


[root@bogon mysql]# pwd 


/usr/local/mysql


[root@bogon mysql]# ls run/


[root@bogon mysql]# ls data/*.pid


ls: cannot access 'data/*.pid': No such file or directory


[root@bogon mysql]# systemctl start mysqld.service


[root@bogon mysql]# systemctl status mysqld


● mysqld.service - MySQL Server


     Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; preset: disabled)


     Active: active (running) since Thu 2024-08-29 09:14:19 CST; 5s ago


       Docs: man:mysqld(8)


             http://dev.mysql.com/doc/refman/en/using-systemd.html


    Process: 15382 ExecStartPre=/usr/local/mysql/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)


   Main PID: 15448 (mysqld)


     Status: "Server is operational"


      Tasks: 35 (limit: 24434)


     Memory: 454.5M


        CPU: 12.488s


     CGroup: /system.slice/mysqld.service


             └─15448 /usr/local/mysql/bin/mysqld


 


Aug 29 09:14:16 bogon mysqld_pre_systemd[15411]: 2024-08-29T01:14:16.449419Z 0 [System] [MY-015018] [Server] MySQL Server Initialization - end.


Aug 29 09:14:16 bogon mysqld[15448]: 2024-08-29T01:14:16.501034Z 0 [System] [MY-015015] [Server] MySQL Server - start.


Aug 29 09:14:16 bogon mysqld[15448]: 2024-08-29T01:14:16.760249Z 0 [System] [MY-010116] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.4.2-debug) starting as>


Aug 29 09:14:16 bogon mysqld[15448]: 2024-08-29T01:14:16.782453Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.


Aug 29 09:14:17 bogon mysqld[15448]: 2024-08-29T01:14:17.536247Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.


Aug 29 09:14:19 bogon mysqld[15448]: 2024-08-29T01:14:19.481641Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.


Aug 29 09:14:19 bogon mysqld[15448]: 2024-08-29T01:14:19.481734Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted conn>


Aug 29 09:14:19 bogon mysqld[15448]: 2024-08-29T01:14:19.751956Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 330>


Aug 29 09:14:19 bogon mysqld[15448]: 2024-08-29T01:14:19.753196Z 0 [System] [MY-010931] [Server] /usr/local/mysql/bin/mysqld: ready for connections. Version:>


Aug 29 09:14:19 bogon systemd[1]: Started MySQL Server.


[root@bogon mysql]# mysql -u root -p'redhat1~'


mysql: [Warning] Using a password on the command line interface can be insecure.


Welcome to the MySQL monitor.  Commands end with ; or g.


Your MySQL connection id is 8


Server version: 8.4.2-debug Source distribution

© 版权声明

相关文章

暂无评论

您必须登录才能参与评论!
立即登录
暂无评论...