系统镜像版本CentOS-7-x86_64-DVD-1804
Linux入门到放弃
- CentOS7安装
- CentOS7镜像版本选择
- CentOS7下载
- CentOS7安装
- 虚拟机安装
- Linux基础
- Linux软件安装
- Linux安装Apache
- 方法一、挂载光盘 安装Apache
- Linux安装MySQL8
- 方法一、官网RPM包安装
- 方法二、官网YUM源安装
- 方法三、清华大学源安装
CentOS7安装
CentOS7镜像版本选择
CentOS 7提供的ISO镜像文件:
版本 | 介绍 |
DVD ISO | 标准安装版,推荐使用 |
Everything ISO | 对完整版安装盘的软件进行补充,集成所有软件 |
Minimal ISO | 精简版,自带的软件最少 |
NetInstall ISO | 网络安装版,安装时下载必要文件 |
CentOS7下载
国内开源镜像站地址 推荐使用国内源进行下载速度较快
下载链接
阿里CentOS-7-x86_64-DVD-2009.iso中科大CentOS-7-x86_64-DVD-2009.iso
官方源
官方源:http://mirror.centos.org/
企业镜像
阿里云开源镜像站:https://mirrors.aliyun.com/centos/
网易开源镜像站:https://mirrors.163.com/centos/
腾讯开源镜像站:https://mirrors.cloud.tencent.com/centos/
华为开源镜像站:https://mirrors.huaweicloud.com/centos/
高校开源镜像站
中国科技大学开源镜像站:https://mirrors.ustc.edu.cn/centos/
清华大学开源软件镜像站:https://mirrors.tuna.tsinghua.edu.cn/centos/
北京外国语大学开源软件镜像站:https://mirrors.bfsu.edu.cn/centos/
上海交通大学开源镜像站:https://ftp.sjtu.edu.cn/centos/
南京大学开源镜像站:https://mirrors.nju.edu.cn/centos/
浙江大学开源镜像站:https://mirrors.zju.edu.cn/centos/
CentOS7安装
虚拟机安装
默认选择的是第二个校验镜像后安装系统,直接回车即可检查镜像是否有错误,如有错误需要重新下载,校验玩后进入安装界面
选择最小化安装,GUI界面没有什么实际用处
选择安装位置,默认即可
开启网络
设置root账户的密码
给root账户设置密码,过于简单的密码需要点两次完成
等待安装完成,点击重启
输入账户名root后回车
输入密码,密码不会显示,输完直接回车
成功登入root账户
Linux基础
Linux软件安装
Linux安装Apache
方法一、挂载光盘 安装Apache
- 在虚拟机软件里选择光盘
- 将光盘挂载到/media/cdrom目录
[root@localhost ~]# mkdir -p /media/cdrom
[root@localhost ~]# mount /dev/cdrom /media/cdrom/
mount: /dev/sr0 is write-protected, mounting read-only
- 使用vi编辑器创建Yum源配置文件
移动自带yum源
[root@localhost ~]# mv /etc/yum.repos.d/*repo /opt/
新建本地yum源
[root@localhost ~]# vi /etc/yum.repos.d/CentOS-ISO.repo
[CentOS-ISO]
name=CentOS-ISO
baseurl=file:///media/cdrom
enabled=1
gpgcheck=0
- 安装Apache服务
yum install -y httpd
- 启动Apache服务
[root@localhost ~]# systemctl start httpd.service
- 查看Apache服务运行状态
[root@localhost ~]# systemctl status httpd.service
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2022-01-10 04:43:41 EST; 1min 21s ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 42175 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup: /system.slice/httpd.service
├─42175 /usr/sbin/httpd -DFOREGROUND
├─42176 /usr/sbin/httpd -DFOREGROUND
├─42177 /usr/sbin/httpd -DFOREGROUND
├─42178 /usr/sbin/httpd -DFOREGROUND
├─42179 /usr/sbin/httpd -DFOREGROUND
└─42180 /usr/sbin/httpd -DFOREGROUND
Jan 10 04:43:41 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...
Jan 10 04:43:41 localhost.localdomain httpd[42175]: AH00558: httpd: Could not re...e
Jan 10 04:43:41 localhost.localdomain systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
- 设置Apache服务开机自启动
[root@localhost ~]# systemctl enable httpd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
- 查看ip 浏览器访问ip
[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:d5:64:7b brd ff:ff:ff:ff:ff:ff
inet 192.168.19.244/24 brd 192.168.19.255 scope global noprefixroute ens33
valid_lft forever preferred_lft forever
inet6 fe80::6f6:e65f:cf7f:802f/64 scope link noprefixroute
valid_lft forever preferred_lft forever
- Apache目录
作用 | 目录 |
服务目录 | /etc/httpd/ |
配置文件 | /etc/httpd/conf/httpd.conf |
网站数据目录 | /var/www/html |
访问日志 | /var/log/httpd/access_log |
错误日志 | /var/log/httpd/error_log |
- Apache服务配置文件
[root@localhost ~]# vi /etc/httpd/conf/httpd.conf
参数 | 作用 |
ServerRoot | 服务目录 |
ServerAdmin | 管理员邮箱 |
User | 运行服务的用户 |
Group | 运行服务的用户组 |
ServerName | 网站服务器的域名 |
DocumentRoot | 网站数据目录 |
Listen | 监听的IP地址与端口号 |
DirectoryIndex | 默认的索引页页面 |
ErrorLog | 错误日志文件 |
CustomLog | 访问日志文件 |
Timeout | 网页超时时间,默认为300秒 |
Linux安装MySQL8
方法一、官网RPM包安装
官方RPM包下载地址:https://dev.mysql.com/downloads/mysql/
方法二、官网YUM源安装
官网地址:https://dev.mysql.com/downloads/repo/yum/ 选择对应系统版本
右键No thanks, just start my download.复制链接
https://dev.mysql.com/get/mysql80-community-release-el7-4.noarch.rpm
到Linux使用wget下载rpm包
wget -i -c https://dev.mysql.com/get/mysql80-community-release-el7-4.noarch.rpm
yum安装刚刚下载的mysql80-community-release-el7-4.noarch.rpm包
yum install -y mysql80-community-release-el7-4.noarch.rpm
执行yum install -y mysql-community-server安装MySQL
yum install -y mysql-community-server
具体下载安装时间和网络有关,耐心等待即可。
安装完毕,执行systemctl start mysqld.service执行systemctl status mysqld.service查看运行状态
systemctl start mysqld.service
systemctl status mysqld.service
Active绿色标色正在运行 执行grep “password” /var/log/mysqld.log查看MySQL临时密码root@localhost:后面的即是密码
grep "password" /var/log/mysqld.log
执行mysql -u root -p进入MySQL
mysql -u root -p
在Enter password: 后输入临时密码密码,输入的密码不会显示
使用ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘这里填你要设置的密码’
提示Query OK, 0 rows affected 表示密码修改成功
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Ab123456@';
Query OK, 0 rows affected (0.05 sec)
此报错是密码太简单不符合要求,需提升密码复杂程度或者修改密码安全策略
修改密码安全策略方法
查看密码当前密码策略执行SHOW VARIABLES LIKE ‘validate_password%’;
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password.check_user_name | ON |
| validate_password.dictionary_file | |
| validate_password.length | 8 |
| validate_password.mixed_case_count | 1 |
| validate_password.number_count | 1 |
| validate_password.policy | MEDIUM |
| validate_password.special_char_count | 1 |
+--------------------------------------+--------+
关于 mysql 密码策略相关参数:
- validate_password.check_user_name 用户名检测,检测是否重名;
- validate_password.dictionary_file 指定密码验证的文件路径;
- validate_password.length 固定密码的总长度;
- validate_password.mixed.case_count 整个密码中至少要包含大/小写字母的总个数;
- validate_password.number_count 整个密码中至少要包含阿拉伯数字的个数;
- validate_password.policy 指定密码的强度验证等级,默认为 MEDIUM; 关于 validate_password.policy 的取值:0/LOW:只验证长度; 1/MEDIUM:验证长度、数字、大小写、特殊字符; 2/STRONG:验证长度、数字、大小写、特殊字符、字典文件;
- validate_password_special_char_count 整个密码中至少要包含特殊字符的个数;
修改前
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password.check_user_name | ON |
| validate_password.dictionary_file | |
| validate_password.length | 8 |
| validate_password.mixed_case_count | 1 |
| validate_password.number_count | 1 |
| validate_password.policy | MEDIUM |
| validate_password.special_char_count | 1 |
+--------------------------------------+--------+
修改命令 set global validate_password.policy=LOW;修改密码验证等级为LOW,set global validate_password.length=4;修改长度
mysql> set global validate_password.policy=LOW;
Query OK, 0 rows affected (0.03 sec)
mysql> set global validate_password.length=4;
Query OK, 0 rows affected (0.00 sec)
修改后
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------+-------+
| validate_password.check_user_name | ON |
| validate_password.dictionary_file | |
| validate_password.length | 4 |
| validate_password.mixed_case_count | 1 |
| validate_password.number_count | 1 |
| validate_password.policy | LOW |
| validate_password.special_char_count | 1 |
+--------------------------------------+-------+
再执行ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘123456’;即可把密码修改成123456
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.02 sec)
方法三、清华大学源安装
MySQL清华大学源地址:https://mirrors.tuna.tsinghua.edu.cn/help/mysql/ 新建 /etc/yum.repos.d/mysql-community.repo
vi /etc/yum.repos.d/mysql-community.repo
复制下方所有内容,粘贴到文件里
[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-connectors-community-el7-$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
[mysql-tools-community]
name=MySQL Tools Community
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-tools-community-el7-$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
[mysql-5.6-community]
name=MySQL 5.6 Community Server
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.6-community-el7-$basearch/
enabled=0
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
[mysql-5.7-community]
name=MySQL 5.7 Community Server
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
[mysql-8.0-community]
name=MySQL 8.0 Community Server
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-8.0-community-el7-$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
查看已启用的yum源
yum repolist enabled
禁用MySQL5.7yum源
yum-config-manager --disable mysql-5.7-community
yum repolist enabled
重建yum缓存
yum makecache
安装mysql-community-server
yum install -y mysql-community-server
启动MySQL服务
systemctl start mysqld.service
查看MySQL服务运行状态
systemctl status mysqld.service
查看MySQL临时密码
grep "password" /var/log/mysqld.log
登录MySQL
mysql -u root -p
修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Ab123456@';
如需修改密码为简单密码如123456 !!!!!!不建议使用简单密码 修改密码验证等级为LOW
set global validate_password.policy=LOW;
修改密码最小长度为4
set global validate_password.length=4;
修改密码为123456
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';