From 2664d075ddf4e7d093f24abbb11edae36aefce81 Mon Sep 17 00:00:00 2001 From: Zhang Peng Date: Fri, 22 Feb 2019 18:02:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../linux/ops/service/maven/install-maven3.sh | 3 - .../ops/service/nodejs/install-nodejs.sh | 2 +- .../yum/{CentOS-Base.repo => Centos-5.repo} | 0 codes/linux/sys/yum/Centos-6.repo | 62 +++++++++++++++++++ codes/linux/sys/yum/Centos-7.repo | 62 +++++++++++++++++++ codes/linux/sys/yum/README.md | 12 ++++ codes/linux/sys/yum/change-yum-repo.sh | 16 ++--- 7 files changed, 146 insertions(+), 11 deletions(-) rename codes/linux/sys/yum/{CentOS-Base.repo => Centos-5.repo} (100%) create mode 100644 codes/linux/sys/yum/Centos-6.repo create mode 100644 codes/linux/sys/yum/Centos-7.repo create mode 100644 codes/linux/sys/yum/README.md diff --git a/codes/linux/ops/service/maven/install-maven3.sh b/codes/linux/ops/service/maven/install-maven3.sh index b38f7ce..0a25282 100644 --- a/codes/linux/ops/service/maven/install-maven3.sh +++ b/codes/linux/ops/service/maven/install-maven3.sh @@ -28,6 +28,3 @@ source /etc/profile echo -e "\n>>>>>>>>> replace /opt/maven/apache-maven-${version}/conf/settings.xml" cp /opt/maven/apache-maven-${version}/conf/settings.xml /opt/maven/apache-maven-${version}/conf/settings.xml.bak wget -N https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/service/maven/settings-aliyun.xml -O /opt/maven/apache-maven-${version}/conf/settings.xml - -# 回到初始目录 -cd - diff --git a/codes/linux/ops/service/nodejs/install-nodejs.sh b/codes/linux/ops/service/nodejs/install-nodejs.sh index 9f1f012..7408e54 100644 --- a/codes/linux/ops/service/nodejs/install-nodejs.sh +++ b/codes/linux/ops/service/nodejs/install-nodejs.sh @@ -11,7 +11,7 @@ echo -e "\n>>>>>>>>> install node.js" . ~/.nvm/nvm.sh nvm --version execode=$? -if [ ${execode} != 0 ]; then +if [[ ${execode} != 0 ]]; then echo -e "\n未找到 nvm ,开始安装" echo -e "\n>>>>>>>>> install nvm" rm -rf ~/.nvm diff --git a/codes/linux/sys/yum/CentOS-Base.repo b/codes/linux/sys/yum/Centos-5.repo similarity index 100% rename from codes/linux/sys/yum/CentOS-Base.repo rename to codes/linux/sys/yum/Centos-5.repo diff --git a/codes/linux/sys/yum/Centos-6.repo b/codes/linux/sys/yum/Centos-6.repo new file mode 100644 index 0000000..811f914 --- /dev/null +++ b/codes/linux/sys/yum/Centos-6.repo @@ -0,0 +1,62 @@ +# CentOS-Base.repo +# +# The mirror system uses the connecting IP address of the client and the +# update status of each mirror to pick mirrors that are updated to and +# geographically close to the client. You should use this for CentOS updates +# unless you are manually picking other mirrors. +# +# If the mirrorlist= does not work for you, as a fall back you can try the +# remarked out baseurl= line instead. +# +# + +[base] +name=CentOS-$releasever - Base - mirrors.aliyun.com +failovermethod=priority +baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/ + http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/ + http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/ +gpgcheck=1 +gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6 + +#released updates +[updates] +name=CentOS-$releasever - Updates - mirrors.aliyun.com +failovermethod=priority +baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/ + http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/ + http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/ +gpgcheck=1 +gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6 + +#additional packages that may be useful +[extras] +name=CentOS-$releasever - Extras - mirrors.aliyun.com +failovermethod=priority +baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/ + http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/ + http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/ +gpgcheck=1 +gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6 + +#additional packages that extend functionality of existing packages +[centosplus] +name=CentOS-$releasever - Plus - mirrors.aliyun.com +failovermethod=priority +baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/ + http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/ + http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/ +gpgcheck=1 +enabled=0 +gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6 + +#contrib - packages by Centos Users +[contrib] +name=CentOS-$releasever - Contrib - mirrors.aliyun.com +failovermethod=priority +baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/ + http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/ + http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/ +gpgcheck=1 +enabled=0 +gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6 diff --git a/codes/linux/sys/yum/Centos-7.repo b/codes/linux/sys/yum/Centos-7.repo new file mode 100644 index 0000000..df18245 --- /dev/null +++ b/codes/linux/sys/yum/Centos-7.repo @@ -0,0 +1,62 @@ +# CentOS-Base.repo +# +# The mirror system uses the connecting IP address of the client and the +# update status of each mirror to pick mirrors that are updated to and +# geographically close to the client. You should use this for CentOS updates +# unless you are manually picking other mirrors. +# +# If the mirrorlist= does not work for you, as a fall back you can try the +# remarked out baseurl= line instead. +# +# + +[base] +name=CentOS-$releasever - Base - mirrors.aliyun.com +failovermethod=priority +baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/ + http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/ + http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/ +gpgcheck=1 +gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 + +#released updates +[updates] +name=CentOS-$releasever - Updates - mirrors.aliyun.com +failovermethod=priority +baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/ + http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/ + http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/ +gpgcheck=1 +gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 + +#additional packages that may be useful +[extras] +name=CentOS-$releasever - Extras - mirrors.aliyun.com +failovermethod=priority +baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/ + http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/ + http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/ +gpgcheck=1 +gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 + +#additional packages that extend functionality of existing packages +[centosplus] +name=CentOS-$releasever - Plus - mirrors.aliyun.com +failovermethod=priority +baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/ + http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/ + http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/ +gpgcheck=1 +enabled=0 +gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 + +#contrib - packages by Centos Users +[contrib] +name=CentOS-$releasever - Contrib - mirrors.aliyun.com +failovermethod=priority +baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/ + http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/ + http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/ +gpgcheck=1 +enabled=0 +gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 diff --git a/codes/linux/sys/yum/README.md b/codes/linux/sys/yum/README.md new file mode 100644 index 0000000..f476653 --- /dev/null +++ b/codes/linux/sys/yum/README.md @@ -0,0 +1,12 @@ +# 脚本使用说明 + +## 替换 yum repo 源 + +由于 CentOS 默认 yum 源,访问速度很慢,所以推荐使用国内镜像。 + +使用方法:执行以下任意命令即可执行脚本。 + +```sh +curl -o- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/sys/yum/change-yum-repo.sh | bash +wget -qO- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/sys/yum/change-yum-repo.sh | bash +``` diff --git a/codes/linux/sys/yum/change-yum-repo.sh b/codes/linux/sys/yum/change-yum-repo.sh index 2a01d27..398e60b 100644 --- a/codes/linux/sys/yum/change-yum-repo.sh +++ b/codes/linux/sys/yum/change-yum-repo.sh @@ -15,10 +15,12 @@ cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak # version=`lsb_release -r | awk '{print substr($2,1,1)}'` # 很多机器没有 lsb_release 命令 version=`cat /etc/redhat-release | awk '{print substr($4,1,1)}'` +cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak + # 根据发型版本选择相应 yum 镜像 -if [ ${version} == 5 ]; then +if [[ ${version} == 5 ]]; then # Cento5 已废弃,只能使用 http://vault.CentOS.org/ 替换,但由于是国外镜像,速度较慢 - wget --no-cookie --no-check-certificate -O /etc/yum.repos.d/CentOS-Base.repo https://github.com/dunwu/os-tutorial/master/codes/deploy/sys/yum/CentOS-Base.repo + wget -N https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/sys/yum/Centos-5.repo -O /etc/yum.repos.d/CentOS-Base.repo # 根据实际发型版本情况替换 detailVersion=`lsb_release -r | awk '{print substr($2,1,3)}'` @@ -26,12 +28,12 @@ if [ ${version} == 5 ]; then # 不替换下面的开关,可能会出现错误:Could not open/read repomd.xml sed -i 's/enabled=1/enabled=0/g' /etc/yum.repos.d/CentOS-Media.repo +elif [[ ${version} == 6 ]]; then + wget -N https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/sys/yum/Centos-6.repo -O /etc/yum.repos.d/CentOS-Base.repo +elif [[ ${version} == 7 ]]; then + wget -N https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/sys/yum/Centos-7.repo -O /etc/yum.repos.d/CentOS-Base.repo else - # 国内 aliyun 镜像 - wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/CentOS-${version}.repo - - # 国内 163 镜像(备选) - #wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS${version}-Base-163.repo + echo -e "版本不支持,替换 yum repo 失败" fi # 更新缓存