Linux CentOS 7环境配置
程序员文章站
2024-03-11 09:57:07
...
CentOS7环境配置
文章目录
一、配置
1.修改主机名
- 想要永久生效,可以修改/etc/sysconfig/network文件
vim /etc/hostname
2.替换Yum源为阿里源
- 首先备份/etc/yum.repos.d/CentOS-Base.repo
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
- 下载对应版本 repo 文件, 放入 /etc/yum.repos.d/ (操作前请做好相应备份)
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
- 运行以下命令生成缓存
yum clean all
yum makecache
二、必备软件安装
1.安装Java8
(1) 下载jdk
wget https://download.oracle.com/otn/java/jdk/8u251-b08/3d5a2bb8f8d4428bbe94aed7ec7ae784/jdk-8u251-linux-x64.tar.gz?AuthParam=1594047023_9e2977d15a4af117f2bee890ed0eed0f
mv jdk-8u251-linux-x64.tar.gz\?AuthParam\=1594047023_9e2977d15a4af117f2bee890ed0eed0f jdk-8u251-linux-x64.tar.gz
(2) 解压安装
tar -zxvf jdk-8u251-linux-x64.tar.gz -C /usr/local/java/
(3) 修改java.security
vim /usr/local/java/jdk1.8.0_251/jre/lib/security/java.security
# securerandom.source=file:/dev/random 改为 securerandom.source=file:/dev/./urandom
(4) 配置java
vim /etc/profile
# set java environment
JAVA_HOME=/usr/local/java/jdk1.8.0_251
CLASSPATH=.:$JAVA_HOME/lib.tools.jar
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH PATH
source /etc/profile
(5) 检测是否安装成功
[[email protected] ~]# java -version
java version "1.8.0_251"
Java(TM) SE Runtime Environment (build 1.8.0_251-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.251-b08, mixed mode)
[[email protected] ~]#
2.安装MySQL5.7
(1) 检查是否已安装SQL
[[email protected] ~]# rpm -qa | grep mysql
[[email protected] ~]# rpm -qa | grep -i mariadb
mariadb-libs-5.5.52-1.el7.x86_64
[[email protected] ~]#
(2) 卸载已安装的数据库
rpm -qa | grep mariadb | xargs rpm -e --nodeps
(3) 下载安装包文件
http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
[[email protected] ~]# wget https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
--2020-07-06 23:20:14-- https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 23.36.53.20
Connecting to repo.mysql.com (repo.mysql.com)|23.36.53.20|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 26024 (25K) [application/x-redhat-package-manager]
Saving to: ‘mysql80-community-release-el7-3.noarch.rpm’
100%[===============================================================================================================>] 26,024 139KB/s in 0.2s
2020-07-06 23:20:16 (139 KB/s) - ‘mysql80-community-release-el7-3.noarch.rpm’ saved [26024/26024]
[[email protected] ~]#
(4) 安装MySQL的yum源
[[email protected] ~]# rpm -ivh mysql80-community-release-el7-3.noarch.rpm
warning: mysql80-community-release-el7-3.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql80-community-release-el7-3 ################################# [100%]
[[email protected] ~]#
(5) 查看可用的mysql安装文件
[[email protected] ~]# ls /etc/yum.repos.d/ -l
total 20
-rw-r--r-- 1 root root 2523 Jun 16 2018 CentOS-Base.repo
-rw-r--r-- 1 root root 675 Jul 6 22:01 CentOS-Base.repo.backup
-rw-r--r-- 1 root root 230 Jul 6 22:01 epel.repo
-rw-r--r-- 1 root root 2076 Apr 25 2019 mysql-community.repo
-rw-r--r-- 1 root root 2108 Apr 25 2019 mysql-community-source.repo
[[email protected] ~]#
[[email protected] ~]# yum repolist all | grep mysql
mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community disabled
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - disabled
mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community disabled
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - disabled
mysql-cluster-8.0-community/x86_64 MySQL Cluster 8.0 Community disabled
mysql-cluster-8.0-community-source MySQL Cluster 8.0 Community - disabled
mysql-connectors-community/x86_64 MySQL Connectors Community enabled: 153
mysql-connectors-community-source MySQL Connectors Community - disabled
mysql-tools-community/x86_64 MySQL Tools Community enabled: 110
mysql-tools-community-source MySQL Tools Community - Sourc disabled
mysql-tools-preview/x86_64 MySQL Tools Preview disabled
mysql-tools-preview-source MySQL Tools Preview - Source disabled
mysql55-community/x86_64 MySQL 5.5 Community Server disabled
mysql55-community-source MySQL 5.5 Community Server - disabled
mysql56-community/x86_64 MySQL 5.6 Community Server disabled
mysql56-community-source MySQL 5.6 Community Server - disabled
mysql57-community/x86_64 MySQL 5.7 Community Server disabled
mysql57-community-source MySQL 5.7 Community Server - disabled
mysql80-community/x86_64 MySQL 8.0 Community Server enabled: 177
mysql80-community-source MySQL 8.0 Community Server - disabled
[[email protected] ~]#
(6) 安装yum-utils源
yum install yum-utils -y
(7) 启用MySQL5.7的源
yum-config-manager --disable mysql80-community
yum-config-manager --enable mysql57-community
[[email protected] ~]# yum repolist enabled | grep mysql
mysql-connectors-community/x86_64 MySQL Connectors Community 153
mysql-tools-community/x86_64 MySQL Tools Community 110
mysql57-community/x86_64 MySQL 5.7 Community Server 424
[[email protected] ~]#
(8) 安装mysql
yum install mysql-server
[[email protected] ~]# rpm -qa | grep mysql
mysql-community-common-5.7.30-1.el7.x86_64
mysql-community-client-5.7.30-1.el7.x86_64
mysql-community-server-5.7.30-1.el7.x86_64
mysql80-community-release-el7-3.noarch
mysql-community-libs-5.7.30-1.el7.x86_64
[[email protected] ~]#
(9) 启动mysql服务
systemctl start mysqld.service
systemctl restart mysqld.service
systemctl stop mysqld.service
(10) 设置密码
cat /var/log/mysqld.log
# 查看这句话中的密码[Note] A temporary password is generated for [email protected]: ****
[[email protected] ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.30
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
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>
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=3;
Query OK, 0 rows affected (0.00 sec)
mysql> SET PASSWORD = PASSWORD('root');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql>
(11) 设置远程主机登录
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=3;
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on *.* to 'root'@'%' identified by 'root';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>
(12) 设置编码
mysql> show variables like 'character_set_%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
mysql>
vim /etc/my.cnf
# 在[mysqld]结束位置添加:character_set_server=utf8
# 保存并重启MySQL服务
systemctl restart mysqld.service
[[email protected] ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.30 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
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 variables like 'character_set_%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.01 sec)
mysql>
(13) MySQL自启动
systemctl enable mysqld.service
推荐阅读