linux安装及配置_-在linux中安装+配置nginx(最详细的教程) - # 手动创建阿里云镜像配置

📅 2026-11-30 👤 拼多多助力营销技巧 📂 拼多多助力网站 👁️ 544 次阅读

大纲

一.安装nginx 1.安装依赖 yum install -y wget gcc-c++ pcre-devel zlib-devel openssl-devel 1.1.如果有这样的提示,如下:

1. 首先测试基本网络连通性

2. 检查DNS解析服务

3. 检查并修复DNS配置

4. 检查网络管理器服务

5. 临时解决方案:使用IP地址或国内镜像

6. 如果无法下载,手动创建镜像配置

7. 检查主机名解析配置

8. 测试修复结果

解压Nginx

编译和安装

防火墙设置

启动Nginx

nginx官网:https://nginx.org/

一.安装nginx 1.安装依赖 yum install -y wget gcc-c++ pcre-devel zlib-devel openssl-devel 1.1.如果有这样的提示,如下:

已加载插件:fastestmirror Loading mirror speeds from cached hostfile Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was 14: curl#6 - "Could not resolve host: mirrorlist.centos.org; 未知的错误" One of the configured repositories failed (未知), and yum doesn't have enough cached data to continue. At this point the only safe thing yum can do is fail. There are a few ways to work "fix" this: 1. Contact the upstream for the repository and get them to fix the problem. 2. Reconfigure the baseurl/etc. for the repository, to point to a working upstream. This is most often useful if you are using a newer distribution release than is supported by the repository (and the packages for the previous distribution release still work). 3. Run the command with the repository temporarily disabled yum --disablerepo=... 4. Disable the repository permanently, so yum won't use it by default. Yum will then just ignore the repository until you permanently enable it again or use --enablerepo for temporary usage: yum-config-manager --disableor subscription-manager repos --disable=5. Configure the failing repository to be skipped, if it is unavailable. Note that yum will try to contact the repo. when it runs most commands, so will have to try and fail each time (and thus. yum will be be much slower). If it is a very temporary problem though, this is often a nice compromise: yum-config-manager --save --setopt=.skip_if_unavailable=true Cannot find a valid baseurl for repo: base/7/x86_64

这个错误表明系统无法解析 mirrorlist.centos.org 域名,通常是网络配置问题。以下是几种解决方案:

1. 首先测试基本网络连通性

# 测试是否能ping通IP地址(测试网络层是否正常)

ping -c 4 8.8.8.8

ping -c 4 114.114.114.114

2. 检查DNS解析服务

# 测试DNS解析

nslookup mirrorlist.centos.org

dig mirrorlist.centos.org

# 如果命令不存在,先尝试安装

yum install -y bind-utils

3. 检查并修复DNS配置

# 查看当前DNS配置

cat /etc/resolv.conf

# 编辑DNS配置文件

vi /etc/resolv.conf

确保文件内容包含有效的DNS服务器:

# 以下是可靠的中国大陆DNS服务器

nameserver 114.114.114.114

nameserver 223.5.5.5

nameserver 8.8.8.8

nameserver 119.29.29.29

options timeout:2

options attempts:3

4. 检查网络管理器服务

# 检查NetworkManager状态

systemctl status NetworkManager

# 如果服务异常,重启网络相关服务

systemctl restart NetworkManager

systemctl restart network

5. 临时解决方案:使用IP地址或国内镜像

# 直接使用IP访问(不推荐长期使用)

# 先查找当前可用的镜像站IP

nslookup mirrors.aliyun.com

# 或者直接配置国内镜像源(推荐)

cd /etc/yum.repos.d/

mv CentOS-Base.repo CentOS-Base.repo.backup

# 下载阿里云镜像配置

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

# 如果curl也不行,用wget尝试

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

6. 如果无法下载,手动创建镜像配置

# 手动创建阿里云镜像配置

cat > /etc/yum.repos.d/CentOS-Base.repo << 'EOF'

[base]

name=CentOS-$releasever - Base - mirrors.aliyun.com

baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/

gpgcheck=1

gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

[updates]

name=CentOS-$releasever - Updates - mirrors.aliyun.com

baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/

gpgcheck=1

gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

[extras]

name=CentOS-$releasever - Extras - mirrors.aliyun.com

baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/

gpgcheck=1

gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

EOF

7. 检查主机名解析配置

# 检查/etc/hosts文件

cat /etc/hosts

# 确保有localhost解析

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4

::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

8. 测试修复结果

# 重新加载配置

systemctl restart network

# 使用getent测试DNS解析

getent hosts mirrors.aliyun.com

getent hosts mirrorlist.centos.org

# 清理yum缓存并测试

yum clean all

yum makecache

yum list available | head

如果都测试完有这样的问题:

[root@mycentos yum.repos.d]# yum list available | head 已加载插件:fastestmirror Loading mirror speeds from cached hostfile 可安装的软件包 389-ds-base.x86_64 1.3.11.1-5.el7_9 updates 389-ds-base-devel.x86_64 1.3.11.1-5.el7_9 updates 389-ds-base-libs.x86_64 1.3.11.1-5.el7_9 updates 389-ds-base-snmp.x86_64 1.3.11.1-5.el7_9 updates Cython.x86_64 0.19-5.el7 base ElectricFence.i686 2.2.2-39.el7 base ElectricFence.x86_64 2.2.2-39.el7 base 由于管道被破坏而退出

可以使用这个命令:

yum list available > /tmp/yum_list.txt

head -20 /tmp/yum_list.txt

测试完都没有问题了,就可以进行安装了

# 例如,下载Nginx 1.28.0版本

wget https://nginx.org/download/nginx-1.28.0.tar.gz

解压Nginx

解压下载的Nginx源代码包:

tar -zxvf nginx-1.24.0.tar.gz

编译和安装

进入解压后的Nginx目录并进行编译和安装:

# 切换到 Nginx 解压目录

cd nginx-1.28.0

# 编译前的配置和依赖检查

./configure

# 编译安装

make && make install

Nginx安装完成后,默认自动创建 /usr/local/nginx 目录,并创建必要的文件和目录,包括配置文件、日志文件、HTML文件等。

防火墙设置

如果您的系统启用了防火墙,需要关闭防火墙

# 查看防火墙状态

systemctl status firewalld

# 关闭防火墙

systemctl stop firewalld

# 开机禁用防火墙

systemctl disable firewalld 拼多多帮助力入口

启动Nginx

进入Nginx的安装目录:

cd /usr/local/nginx/sbin

然后,启动Nginx服务器:

./nginx

您现在可以通过浏览器访问您的服务器的IP地址或域名来验证Nginx是否正常工作。,linux安装及配置

标签: 拼多多助力网站平台 赚钱项目 拼多多助力网 首码项目 手赚APP
拼多多助力营销技巧