CentOS下yum使用代理的設定
問題描述:
CentOSyum時出現“Could not retrieve mirrorlisthttp://mirrorlist.centos.org/?release=5&arch=i386&repo=addonserror”錯誤:
[plain]view plaincopyprint?
- [root@servermysql-5.0.56]#yuminstallgcc
- Loadedplugins:fastestmirror
- Loadingmirrorspeedsfromcachedhostfile
- Couldnotretrievemirrorlisthttp://mirrorlist.centos.org/?release=5&arch=i386&repo=addonserrorwas
- [Errno4]IOError:<urlopenerror(-3,'\xe5\x9f\x9f\xe5\x90\x8d\xe8\xa7\xa3\xe6\x9e\x90\xe6\x9a\x82\xe6\x97\xb6\xe5\xa4\xb1\xe8\xb4\xa5')>
- Error:Cannotfindavalidbaseurlforrepo:addons
發現原來是沒有配置resolv.conf,於是到/etc目錄下配置resolv.conf加入nameserver IP:[plain]view plaincopyprint?
- [root@servermysql-5.0.56]#vi/etc/resolv.conf
- nameserver218.85.157.99
- searchlocaldomain
儲存resolv.conf,再次運行上面命令就可以。
因為最近在研究LInux系統,公司環境有限,公司統一通過代理上網,我在自己電腦的虛擬機器上安裝了Linux伺服器,因此在虛擬機器裡面設代理,電腦ip為xxx.xxx.xxx.xx,其中http連接埠808.
經過在網路上的搜尋終於發現了最終的解決方案,現在貼出來和大家做個分享!
如果只是暫時使用代理,在命令列輸入下面一條命令:
export http_proxy="http://210.45.72.XX:808"
對於長久使用代理的情況:
yum裡面可以單獨設定代理
就是yum源的參數加proxy=“http://ip:PORT”
即在/etc/yum.conf中加入下面幾句.
proxy=http://210.45.72.XX:808
proxy_username=username
proxy_password=password
另外:
/root/.bashrc中加入:
export http_proxy="http://username:password@210.45.72.XX:808"
如果是通過ip或電腦的網卡地址認證,可忽略所有username 和 password .
注:停止使用代理的時候,要把改過的檔案改成原樣.尤其是如果使用了export http_proxy="http://210.45.72.XX:808"命令,
要在命令列輸入: unset http_proxy ,去除環境變數.
因為export http_proxy="http://210.45.72.XX:808"這條命令的實質是把export後面的設定寫進環境設定檔案中.
輸入env 可以看所有的環境變數設定.
env >env.txt 可以把環境變數輸出到env.txt中,然後開啟看也可以.
unset 變數 可以取消曾經設過的環境變數.
轉載請註明出處:http://blog.csdn.net/fwj380891124