CentOS 7 中设置系统级代理

在 CentOS 7 中设置系统级代理需要几个步骤。以下是设置系统级代理的方法:

  1. 设置环境变量:

编辑 /etc/environment 文件:

bash 复制代码
sudo nano /etc/environment

添加以下行(替换 proxy_server 和 port 为您的实际代理服务器地址和端口):

http_proxy="http://proxy_server:port"
https_proxy="http://proxy_server:port"
ftp_proxy="http://proxy_server:port"
no_proxy="localhost,127.0.0.1,::1"
HTTP_PROXY="http://proxy_server:port"
HTTPS_PROXY="http://proxy_server:port"
FTP_PROXY="http://proxy_server:port"
NO_PROXY="localhost,127.0.0.1,::1"
  1. 为 Yum 包管理器设置代理:

编辑 /etc/yum.conf 文件:

bash 复制代码
sudo nano /etc/yum.conf

在文件末尾添加:

proxy=http://proxy_server:port
  1. 为 Wget 设置代理:

编辑 /etc/wgetrc 文件:

bash 复制代码
sudo nano /etc/wgetrc

取消注释并修改以下行:

http_proxy = http://proxy_server:port
https_proxy = http://proxy_server:port
ftp_proxy = http://proxy_server:port
  1. 为 Shell 设置代理:

编辑 /etc/profile.d/proxy.sh 文件:

bash 复制代码
sudo nano /etc/profile.d/proxy.sh

添加以下内容:

bash 复制代码
export http_proxy="http://proxy_server:port"
export https_proxy="http://proxy_server:port"
export ftp_proxy="http://proxy_server:port"
export no_proxy="localhost,127.0.0.1,::1"
  1. 应用更改:

重新加载环境变量:

bash 复制代码
source /etc/environment
source /etc/profile.d/proxy.sh
  1. 验证设置:
bash 复制代码
echo $http_proxy
echo $https_proxy
  1. 如果使用 systemd 服务,可能需要为它们单独设置代理。编辑服务文件并添加环境变量。

注意事项:

  • 确保替换 proxy_serverport 为您实际的代理服务器地址和端口。
  • 如果代理需要认证,使用格式:http://username:password@proxy_server:port
  • 某些应用可能需要单独的代理配置。
  • 更改系统级代理可能会影响系统的各个方面,请谨慎操作。
  • 重启系统可能是必要的,以确保所有更改生效。
相关推荐
阳爱铭30 分钟前
机器内存使用率突然激增的原因是什么?
linux·windows·分布式·后端·程序人生·中间件·架构
wangsir.34 分钟前
进程间通信-进程池
linux·开发语言·算法
天马行空工作坊43 分钟前
Autosar学习----AUTOSAR_SWS_BSWGeneral(二)
运维·服务器·学习·架构·汽车·汽车电子
summer@彤妈1 小时前
遇到僵尸进程,怎么处理---学习笔记
linux·性能优化
DYS_000011 小时前
哨兵机制Sentinel
linux·运维·前端·redis·缓存
Evenurs1 小时前
【linux】一种基于虚拟串口的方式使两个应用通讯
linux·运维·服务器
加油,旭杏1 小时前
【Linux】网络层协议——IP
linux·服务器·tcp/ip·ip·网络层·网段划分·私有ip和公网ip
一心只为学1 小时前
Linux中vim常用命令大全
linux·运维·vim
海鸥812 小时前
在linux下,找到指定命令对应的路径信息
linux·运维·服务器
shyuu_2 小时前
Linux 三种方式查看和设置主机名
linux·运维·服务器·正则表达式·云计算·运维开发