admin管理员组

文章数量:1531468

 前置条件:

1.centos 已安装,

Centos 7.9 安装 图解版 小白必看 最新_centos7.9 2009 系统-CSDN博客文章浏览阅读1.5k次,点赞33次,收藏24次。VMware安装win7用 12win10 用 15win11用 16.2.4别问为什么,问就是win和VMware不兼容导致虚拟机各种奇葩异常,重装集群了这已经是我当年实验了20多次得出的结果,最佳兼容性搭配。_centos7.9 2009 系统https://sanfenyunjisuan.blog.csdn/article/details/141171717

2.linux系统初始环境设置


1)配置服务器的IP地址
    查看机器的网卡名称。
         ip address show。
(2)设置服务器的主机名称
    设置主机名称
        hostnamectl set-hostname master (主机名):修改以后永久生效
        hostname master11  :临时修改主机名为master
    查看当前服务器的名称。
        hostname
(3)绑定主机名与IP地址

            查看ip  
       ip addr
    192.168.20.134
         进入编辑模式  i
    修改hosts文件
        vi /etc/hosts
    在其中增加相应内容(下面的内容表示主机名master对应的IP地址为192.168.1.1):
    192.168.20.134 master 
 
进入命令行模式shift q 

(4)防火墙
         防火墙的开启、关闭、禁用命令
    设置开机启用防火墙:systemctl enable firewalld

    设置开机禁用/永久关闭防火墙:
    systemctl disable firewalld 或 systemctl disable firewalld.service


    启动防火墙:systemctl start firewalld

    关闭防火墙:systemctl stop firewalld 或 systemctl stop firewalld.service

    检查防火墙状态 systemctl status firewalld

    我们此时永久关闭防火墙供后续使用,临时关闭后续容易无法连接外网

[root@localhost ~]# systemctl  disable  firewalld.service 
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
    
        查看防火墙的状态
        systemctl status firewalld  
    
    配置 selinux
[root@localhost ~]# getenforce 
Enforcing
[root@localhost ~]# setenforce 0

 3.centos7 配置yum源

为什么换阿里云的源,因为entos停止维护,用他的源来连接不上,而国内老用户很多企业还在用旧版本,我们为了适配企业且阿里云的源网速较快所以说配置阿里源 
2.备份原来的yum源
[root@controller ~]# mkdir /etc/yum.repos.d/repobak
[root@controller ~]# mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/repobak/


3.配置网络yum源  

centos镜像_centos下载地址_centos安装教程-阿里巴巴开源镜像站阿里巴巴开源镜像站为您提供免费的centos下载地址及centos安装教程,centos镜像简介:CentOS,是基于Red Hat Linux提供的可自由使用源代码的企业级Linux发行版本,是RHEL(Red Hat Enterprise Linux)源代码再编译的产物,是一个免费的企业级计算平台;CentOS 定期发行及更新版本,以便支持新的硬件,从而建立一个安全、低维护、稳定、高预测性、高重复性的Linux环境。阿里巴巴开源镜像站,持续同步CentOS、CentOC-altarch等最新版镜像文件,为用户提供极致的下载体验。阿里巴巴开源镜像站https://developer.aliyun/mirror/centos?spm=a2c6h.13651102.0.0.3e221b11UzjBznepel镜像_epel下载地址_epel安装教程-阿里巴巴开源镜像站阿里巴巴开源镜像站为您提供免费的epel下载地址及epel安装教程,epel镜像简介:EPEL( Extra Packages for Enterprise Linux) ,是由 Fedora 社区打造,为 RHEL 及衍生发行版如 CentOS、Scientific Linux 等提供高质量软件包的项目。EPEL 项目与 Fedora 基本一致,包含完整的构建系统、升级管理器、镜像管理器等等。阿里巴巴开源镜像站,提供最新版EPEL镜像安装源,供开发者免费下载,更快速、更稳定。阿里巴巴开源镜像站https://developer.aliyun/mirror/epel?spm=a2c6h.13651102.0.0.3e221b11UzjBzn

(1)-----这里直接使用 阿里 的 镜像
    新建文件  aliyun.repo
    vim /etc/yum.repos.d/aliyun.repo
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun/repo/Centos-7.repo

wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun/repo/epel-7.repo

    生成缓存列表:
    yum makecache
检查是否配置成功命令 
[tom@master ~]$ yum repolist 

列出软件包的依赖关系
[tom@master ~]$ yum deplist  

清理软件源
[tom@master ~]$ yum clean all
重新生成缓存列表:
[tom@master ~]$ yum makecache
检查是否配置成功命令
[tom@master ~]$ yum repolist 

安装MySQL:

1.配置安装源 :配置yum 安装MySQL指定版本所用的yum 仓库源

[root@root ~]#  cd  /etc/yum.repos.d/
 

[root@root yum.repos.d]# ls
 

CentOS-Base.repo         mysql-community-source.repo
CentOS-SCLo-scl.repo     nginx.repo
CentOS-SCLo-scl-rh.repo  Percona-xtrabackup.repo
epel.repo                repobak
mysql-community.repo     zabbix.repo

 

注意:

mysql-community.repo通常位于 /etc/yum.repos.d/ 目录下,用于配置 MySQL 社区版软件包的 YUM 仓库信息,mysql-community.repo 文件包含了 MySQL 社区版软件包的存储库配置,包括镜像源、签名密钥等信息通过配置此文件,就可以使用 YUM 命令来安装、更新和管理 MySQL 社区版软件包 。

mysql-community-source.repo:这个文件也通常位于 /etc/yum.repos.d/ 目录下,该软件包仓库包含了 MySQL 社区版软件的源代码,允许开发者自行构建、编译和定制 MySQL 服务器。通过配置此文件,可以使用 YUM 命令来安装和更新 MySQL 社区版的源码软件包

[root@root yum.repos.d]# vim mysql-community.repo       # 新建
[root@root yum.repos.d]# cat mysql-community.repo        # 粘贴复制如下内容
# Enable to use MySQL 5.5
[mysql55-community]
name=MySQL 5.5 Community Server
baseurl=http://repo.mysql/yum/mysql-5.5-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

# Enable to use MySQL 5.6
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql/yum/mysql-5.6-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

# Enable to use MySQL 5.7
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql/yum/mysql-8.0-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql/yum/mysql-connectors-community/el/7/$basearch/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://repo.mysql/yum/mysql-tools-community/el/7/$basearch/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-tools-preview]
name=MySQL Tools Preview
baseurl=http://repo.mysql/yum/mysql-tools-preview/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-cluster-7.5-community]
name=MySQL Cluster 7.5 Community
baseurl=http://repo.mysql/yum/mysql-cluster-7.5-community/el/7/$basearch/
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-cluster-7.6-community]
name=MySQL Cluster 7.6 Community
baseurl=http://repo.mysql/yum/mysql-cluster-7.6-community/el/7/$basearch/
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-cluster-8.0-community]
name=MySQL Cluster 8.0 Community
baseurl=http://repo.mysql/yum/mysql-cluster-8.0-community/el/7/$basearch/
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

mysql-community-source.repo 可选择是否添加

它是源代码安装配置仓库,允许开发者自行构建、编译和定制 MySQL 服务器编译或者开发们进行某些数据集成也许会有用到?

不过考虑某些需求,我写了如下:

       vim mysql-community-source.repo 

[root@root yum.repos.d]# cat mysql-community-source.repo 
[mysql55-community-source]
name=MySQL 5.5 Community Server - Source
baseurl=http://repo.mysql/yum/mysql-5.5-community/el/7/SRPMS
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql56-community-source]
name=MySQL 5.6 Community Server - Source
baseurl=http://repo.mysql/yum/mysql-5.6-community/el/7/SRPMS
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql57-community-source]
name=MySQL 5.7 Community Server - Source
baseurl=http://repo.mysql/yum/mysql-5.7-community/el/7/SRPMS
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql80-community-source]
name=MySQL 8.0 Community Server - Source
baseurl=http://repo.mysql/yum/mysql-8.0-community/el/7/SRPMS
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-connectors-community-source]
name=MySQL Connectors Community - Source
baseurl=http://repo.mysql/yum/mysql-connectors-community/el/7/SRPMS
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-tools-community-source]
name=MySQL Tools Community - Source
baseurl=http://repo.mysql/yum/mysql-tools-community/el/7/SRPMS
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-tools-preview-source]
name=MySQL Tools Preview - Source
baseurl=http://repo.mysql/yum/mysql-tools-preview/el/7/SRPMS
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-cluster-7.5-community-source]
name=MySQL Cluster 7.5 Community - Source
baseurl=http://repo.mysql/yum/mysql-cluster-7.5-community/el/7/SRPMS
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-cluster-7.6-community-source]
name=MySQL Cluster 7.6 Community - Source
baseurl=http://repo.mysql/yum/mysql-cluster-7.6-community/el/7/SRPMS
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-cluster-8.0-community-source]
name=MySQL Cluster 8.0 Community - Source
baseurl=http://repo.mysql/yum/mysql-cluster-8.0-community/el/7/SRPMS
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg

yum 安装MySQL指定版本 用的yum 源是上面第一个 

# enabled=1 gpgcheck=0  1表示开启,0表示关闭,此处是开启版本,关闭密钥验证 

# 配置好前置配置yum 安装MySQL指定版本 用的yum 源 在执行以下安装命令

2.执行安装命令

yum install  mysql  -y

  • yum install mysql-server安装特定的mysql-server包,适用于需要安装旧版本MySQL的情况。
  • yum install mysql -y安装名为mysql的包,可能会安装MariaDB而不是MySQL,具体取决于操作系统的默认配置 我们的话卸载默认MariaDB 手动配置 mysql-community.repo  这样的话安装的就是指定的MySQL版本了

3. 启动 MySQL 服务

安装完成后,启动 MySQL 服务并使其在系统启动时自动启动:

Copysudo systemctl start mysqld
sudo systemctl enable mysqld

4. 检查 MySQL 服务状态

确保 MySQL 服务已成功启动:

Copysudo systemctl status mysqld

5. 获取临时 root 密码

在 MySQL 安装过程中,会为 root 用户创建一个临时密码。你可以通过查看 MySQL 错误日志找到这个密码。通常,错误日志位于 /var/log/mysqld.log

Copysudo grep 'temporary password' /var/log/mysqld.log

你会看到类似这样的输出:

Copy[Note] A temporary password is generated for root@localhost: Abcdefghijklmn

记录下这个临时密码。

6. 运行 MySQL 安装安全脚本

MySQL 提供了一个安全脚本来帮助你对安装进行一些基础的安全配置。

Copysudo mysql_secure_installation

在脚本运行时,你会被要求输入刚刚获取的临时密码,然后,

你可以设置一个新的 root 密码,记得大小写 ,密码举例:Password123$  并根据提示进行其他安全设置,如删除匿名用户、禁止远程 root 登录、删除测试数据库和重载权限表。

7. 登录 MySQL

配置完成后,你可以使用新设置的 root 密码登录 MySQL:

Copymysql -uroot -p

8. 配置 MySQL(可选)

如果需要进一步的配置,可以编辑 MySQL 配置文件,通常位于 /etc/myf 或 /etc/mysql/myf。完成更改后,

重新启动 MySQL 服务以应用配置,如下

Copysudo systemctl restart mysqld

9. 防火墙没关闭 开放防火墙端口(如果需要远程访问) ,

注意:

公司里面 ,防火墙一定会开,但是 sellinux (内核防火墙)一般可以关,当然一些公司可能直接上云服务,直接云防火墙一体化,那么firewalld 可能会关。

但是,目前如果你在学习配置或处于实验环境,可以关掉防火墙,不然天天配置出站入站规则,监听端口,处理端口占用,端口是否开启,检测是否设置防火墙中有关该服务的规则,挺麻烦的

如果需要远程访问 MySQL,需要在防火墙中开放 MySQL 默认端口 3306:

Copysudo firewall-cmd --permanent --zone=public --add-port=3306/tcp
sudo firewall-cmd --reload

经过这些步骤,在 CentOS 或其他基于 RHEL 的 Linux 发行版上成功安装并配置 MySQL

本文标签: 防火墙内核静态主机名新手入门