• 注意要先开通外网!C:\Users\15638>ping www.baidu.com
  • 首先:CentOS7 配置阿里云yum源
(1)进入yum的文件夹 命令:cd /etc/yum.repos.d/
(2)查看当前yum文件夹所有yum源:[root@localhost yum.repos.d]# ls
CentOS-Base.repo  CentOS-CR.repo  CentOS-Debuginfo.repo  CentOS-fasttrack.repo  CentOS-Media.repo  CentOS-Sources.repo  CentOS-Vault.repo
(3)备份
[root@bogon ~]# cd /etc/yum.repos.d/
[root@bogon yum.repos.d]# mkdir repo_bak
[root@bogon yum.repos.d]# mv *.repo repo_bak/
[root@bogon yum.repos.d]# ls
repo_bak
(4)利用wget下载阿里云repo文件,下载新的CentOS-Base.repo 到/etc/yum.repos.d/
[root@bogon yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@bogon yum.repos.d]# ls
CentOS-Base.repo  repo_bak
(5)运行yum clean all清除之前的yum缓存,运行yum makecache生成新的缓存。注意:依次执行
清理yum源之前的缓存命令:[root@localhost yum.repos.d]# yum clean all
生成新的缓存 命令:[root@localhost yum.repos.d]# yum makecache
1.1 JDK 1.8安装
(1)查看云端目前支持安装的jdk版本
[root@localhost ~]# yum search java|grep jdk
(2)选择版本后,安装(执行以下命令会自动安装jdk相关依赖)
[root@localhost ~]#  yum install -y java-1.8.0-openjdk
(3)安装完成,验证是否安装成功
[root@localhost ~]# java -version
(4)通过搜索java文件,查找jdk默认安装目录
[root@localhost ~]# find / -name 'java'
1.2 MySQL 5.6.44安装
  • 在根目录上传mysql-5.6.44-linux-glibc2.12-x86_64.tar.gz
[root@localhost ~]# ls
anaconda-ks.cfg  mysql-5.6.44-linux-glibc2.12-x86_64.tar.gz
  • 解压mysql压缩包
[root@localhost ~]# tar -zxf mysql-5.6.44-linux-glibc2.12-x86_64.tar.gz
  • 移动mysql文件夹到到/usr/local/目录下并更名为mysql
[root@localhost ~]# mv mysql-5.6.44-linux-glibc2.12-x86_64 /usr/local/mysql
  • 创建一个mysql用户并更改/usr/local/mysql目录的权限(用户和组)
[root@localhost ~]# useradd -r -s /sbin/nologin mysql
[root@localhost ~]# id mysql
uid=996(mysql) gid=994(mysql) groups=994(mysql)
[root@localhost ~]# chown -R mysql.mysql /usr/local/mysql
[root@localhost ~]# ll /usr/local/mysql
[root@localhost ~]# ll /usr/local/mysql/data/
total 0
drwxr-xr-x 2 mysql mysql 20 Apr 12 13:47 test
  • 卸载移除mariadb-libs软件包库文件。若出现提示的话,一路 Y 到底
[root@localhost ~]# cd /usr/local/mysql/
[root@localhost mysql]# yum remove mariadb-libs
  • 移除mariadb-libs库文件之后,初始化数据库脚本
[root@localhost mysql]# /usr/local/mysql/scripts/mysql_install_db --user=mysql
这一步若需要则安装autoconf库:[root@localhost mysql]# yum install autoconf -y
[root@localhost mysql]# ll data
total 110600
-rw-rw---- 1 mysql mysql 12582912 Apr 12 14:03 ibdata1
-rw-rw---- 1 mysql mysql 50331648 Apr 12 14:03 ib_logfile0
-rw-rw---- 1 mysql mysql 50331648 Apr 12 14:03 ib_logfile1
drwx------ 2 mysql mysql     4096 Apr 12 14:03 mysql
drwx------ 2 mysql mysql     4096 Apr 12 14:03 performance_schema
drwxr-xr-x 2 mysql mysql       20 Apr 12 13:47 test
移动support-files目录下的mysql.server脚本到/etc/init.d目录一份,通过service管理mysql数据库软件
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysql
启动mysql脚本,显示 SUCCESS 表示启动mysql成功!
[root@localhost mysql]# service mysql start
Starting MySQL.Logging to '/usr/local/mysql/data/localhost.localdomain.err'.
 SUCCESS!
[root@localhost mysql]# service mysql status
 SUCCESS! MySQL running (102405)
  • 设置密码:mysql5.6安装完成后,它的 root 用户的密码默认是空的,我们要及时用 mysql 的 root 用户登录(第一次直接回车,不用输密码),并修改密码
[root@localhost mysql]# mysql -u root
-bash: mysql: command not found
[root@localhost mysql]# cd ~
[root@localhost ~]# alias mysql=/usr/local/mysql/bin/mysql
[root@localhost ~]# cd /usr/local/mysql
[root@localhost mysql]# mysql -V
/usr/local/mysql/bin/mysql  Ver 14.14 Distrib 5.6.44, for linux-glibc2.12 (x86_64) using  EditLine wrapper
[root@localhost mysql]# mysql -u root
mysql> use mysql;
mysql> update user set password=PASSWORD("123456") where User='root';
mysql> flush privileges;
设置远程主机登录
mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "123456";   这里的123456为你给新增权限用户设置的密码,%代表所有主机,也可以具体到你的主机ip地址
mysql> flush privileges;  这一步一定要做,不然无法成功!这句表示从mysql数据库的grant表中重新加载权限数据
执行完这两步,再次查询用户表命令:mysql> select  User,authentication_string,Host from user;
防火墙开放mysql数据库3306端口
[root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[root@localhost ~]# firewall-cmd --reload    重启防火墙
success
[root@localhost ~]# firewall-cmd --list-ports    查看已经开发的端口
3306/tcp
  • 其他
[root@localhost mysql]# service mysql stop
Shutting down MySQL.. SUCCESS! 
[root@localhost mysql]# service mysql status
 ERROR! MySQL is not running
[root@localhost mysql]# service mysql restart
 ERROR! MySQL server PID file could not be found!
Starting MySQL. SUCCESS! 
[root@localhost mysql]# service mysql status
SUCCESS! MySQL running (104693)
  • Centos 7下查看mysql的版本
[root@localhost ~]# whereis mysql
mysql: /usr/lib64/mysql /usr/local/mysql
[root@localhost ~]# cd /usr/local/mysql
[root@localhost mysql]# mysql -V
-bash: mysql: command not found
[root@localhost mysql]# cd ~
[root@localhost ~]# alias mysql=/usr/local/mysql/bin/mysql
[root@localhost ~]# cd /usr/local/mysql
[root@localhost mysql]# mysql -V
/usr/local/mysql/bin/mysql  Ver 14.14 Distrib 5.6.44, for linux-glibc2.12 (x86_64) using  EditLine wrapper
1.3 Nginx安装

Nginx:前台访问后台的反向代理

CentOS7中使用yum安装Nginx

  • (1)执行命令添加Nginx的源
[root@localhost ~]# sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
  • (2)通过yum search nginx看看是否已经添加源成功
[root@localhost ~]# yum search nginx
  • (3)成功添加源则执行命令安装Nginx
[root@localhost ~]# sudo yum install -y nginx
  • (4)启动Nginx并设置开机自动运行
[root@localhost ~]# sudo systemctl start nginx.service
[root@localhost ~]# sudo systemctl enable nginx.service
[root@localhost ~]# firewall-cmd  --list-all
  ports: 3306/tcp 80/tcp 443/tcp
  • 修改/增加开放的端口命令:[root@localhost ~]# sudo firewall-cmd --add-port=80/tcp --permanent
  • 要重启防火墙:[root@localhost ~]# firewall-cmd --reload
  • (7)其他常用命令
查看nginx版本的命令
[root@localhost ~]# cd /usr/sbin
[root@localhost sbin]# ./nginx -v
nginx version: nginx/1.20.2
查看nginx状态的命令
[root@localhost sbin]# ps -ef | grep nginx
root     106082      1  0 15:19 ?        00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx    106083 106082  0 15:19 ?        00:00:00 nginx: worker process
nginx    106084 106082  0 15:19 ?        00:00:00 nginx: worker process
root     122012 120245  0 20:23 pts/0    00:00:00 grep --color=auto nginx
关闭nginx的命令
[root@localhost sbin]# ./nginx -s stop
启动nginx的命令
[root@localhost sbin]# ./nginx
  • 注意:因jar包已集成tomcat无需再安装,spring boot使用tomcat作为默认嵌入式容器。