CentOS7更换国内yum源并搭建LNMP环境

本次环境:

虚拟机软件:VMware workstation 15.5

虚拟机:CentOS7

一、更换国内yum源(浙大)

  1.什么是yum?

    简单来说yum仓库就是通常使用 yum install 命令来在线安装Linux系统软件的一个仓库,它可以自动处理依赖性关系,并且一次性安装所有依赖的软件包,但是经常会遇到下载速度过慢等问题,所以此次选择更换yum源。(之前搭建过一个本地的yum源)。yum配置文件在 /etc/yum.repos.d 目录下,一般为 CentOS-Base.repo

  2.备份原来的源

sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bk   #如果搭建过本地yum,将文件名为local的那个.repo文件备份即可

  3.下载浙大yum源(可自行挑选国内源)

$    cd /etc/yum.repos.d 
$    sudo wget -nc http://mirrors.yangxingzhen.com/help/CentOS7-Base-zju.repo 

   下面附上一些国内源

网易:

CentOS5 :http://mirrors.163.com/.help/CentOS5-Base-163.repo

CentOS6 :http://mirrors.163.com/.help/CentOS6-Base-163.repo

CentOS7 :http://mirrors.163.com/.help/CentOS7-Base-163.repo

阿里:

CentOS5 : http://mirrors.aliyun.com/repo/Centos-5.repo

CentOS6 : http://mirrors.aliyun.com/repo/Centos-6.repo

CentOS7 : http://mirrors.aliyun.com/repo/Centos-7.repo

中科大:

CentOS5 : https://lug.ustc.edu.cn/wiki/_export/code/mirrors/help/centos?codeblock=1

CentOS6 : https://lug.ustc.edu.cn/wiki/_export/code/mirrors/help/centos?codeblock=2

CentOS7 : https://lug.ustc.edu.cn/wiki/_export/code/mirrors/help/centos?codeblock=3

清华大学:

CentOS5 : https://mirrors.yangxingzhen.com/help/CentOS5-Base-tuna.repo

CentOS6 : https://mirrors.yangxingzhen.com/help/CentOS6-Base-tuna.repo

CentOS7 : https://mirrors.yangxingzhen.com/help/CentOS7-Base-tuna.repo

浙江大学:

CentOS6 : https://mirrors.yangxingzhen.com/help/CentOS6-Base-zju.repo

CentOS7 : https://mirrors.yangxingzhen.com/help/CentOS7-Base-zju.repo

中国科技大学:

CentOS5 : https://mirrors.yangxingzhen.com/help/CentOS5-Base-ustc.repo

CentOS6 : https://mirrors.yangxingzhen.com/help/CentOS6-Base-ustc.repo

CentOS7 : https://mirrors.yangxingzhen.com/help/CentOS7-Base-ustc.repo

  4.更改浙大yum源为默认源

sudo mv CentOS7-Base-zju.repo CentOS-Base.repo

  5.更新本地yum缓存

sudo yum clean all  #清除本地所有缓存
sudo yum list    #更新列表
sudo yum makecahe #(可选)缓存yum包信息到本机,提高搜索速度

二、搭建LNMP环境

  1.什么是LNMP?

  LNMP就是Linux下 Nginx+MySQL+PHP网站服务架构。Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器;Mysql是一个小型关系型数据库管理系统;PHP是一种在服务器端执行的嵌入HTML文档的脚本语言。

  2.搭建Nginx

  可以先看一下自己的yum源有没有Nginx,现在国内的源基本都有了。

sudo yum search nginx

  如果没有Nginx的话,可以官网下载相应版本的Nginx再放到相应虚拟机的目录下解压;也可像下面这样:

  在 /etc/yum.repos.d/ 目录下生成 nginx.repo 文件

vim /etc/yum.repos.d/nginx.repo 

  向nginx.repo文件内添加如下内容

[nginx] 
name = nginx repo 
baseurl = https://nginx.org/packages/mainline/centos/7/$basearch/ 
gpgcheck = 0 
enabled = 1

  利用yum安装nginx

sudo yum -y install nginx

  开启nginx服务&&设置开机自启nginx服务

$ systemctl start nginx 
$ systemctl enable nginx 

  打开浏览器输入本机IP,如果页面出现welcome nginx!即为安装成功,如果服务开启失败可以看看是否没有打开80或者443端口。(也可在图形界面中找到防火墙设置,开启端口即可)

$ systemctl start firewalld   #开启防火墙
$ firewall-cmd --zone=public --add-port=80/tcp --permanent #对外开启80端口
$ firewall-cmd --zone=public --add-port=443/tcp --permanent #对外开启443端口

  3.搭建MySQL

  3.1 下载并安装MySQL官方的 Yum Repository

wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

   安装MySQL的Yum Repository

yum -y install mysql57-community-release-el7-10.noarch.rpm

  3.2 安装MySQL服务器(自动覆盖掉原有的mariadb)

sudo yum -y install mysql-community-server

  

  3.3 配置MySQL

  先启动MySQL并设置开机自启

$ systemctl start mysqld.service  #启动MySQL
$ systemctl enable mysqld.service  #设置开机自启

  通过日志文件查看MySQL中root用户的密码

$ cat /var/log/mysqld.log | grep "password"
原文地址:https://www.cnblogs.com/Zh1z3ven/p/12741733.html