配置阿里云yum源centos7配置国内yum源 - 腾讯云开发者社区-腾讯云 (tencent.com)

1
2
3
4
5
6
7
8
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

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

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo
yum clean all # 清除系统所有的yum缓存
yum makecache # 生成yum缓存

安装 epel
yum install -y epel-release

配置阿里镜像提供的epel源
wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo

CentOS7官方源默认已经包含bash-completion,直接安装

1
yum -y install bash-completion

清华

# 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 baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 #released updates [updates] name=CentOS-$releasever - Updates baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful [extras] name=CentOS-$releasever - Extras baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-$releasever - Plus baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus gpgcheck=1 enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

设置网络相关

changeYumrepo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash

# 定义颜色
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m' # 无颜色

# 定义YUM源选项
echo -e "${BLUE}请选择要更换的YUM源(默认使用阿里源):${NC}"
echo -e "${BLUE}1) 阿里YUM源: http://mirrors.aliyun.com/repo/${NC}"
echo -e "${BLUE}2) 163(网易)YUM源: http://mirrors.163.com/.help/${NC}"
echo -e "${BLUE}3) 中科大Linux安装镜像源: http://centos.ustc.edu.cn/${NC}"
echo -e "${BLUE}4) 搜狐的Linux安装镜像源: http://mirrors.sohu.com/${NC}"
echo -e "${BLUE}5) 北京首都在线科技: http://mirrors.yun-idc.com/${NC}"
read -p "请输入选项 [1-5] (默认1): " choice

# 根据选择设置URL
case $choice in
2)
repo_url="http://mirrors.163.com/.help/CentOS7-Base-163.repo"
;;
3)
repo_url="http://centos.ustc.edu.cn/CentOS-Base.repo"
;;
4)
repo_url="http://mirrors.sohu.com/help/CentOS-Base-sohu.repo"
;;
5)
repo_url="http://mirrors.yun-idc.com/CentOS-Base.repo"
;;
*)
repo_url="http://mirrors.aliyun.com/repo/Centos-7.repo"
;;
esac

# 备份当前的YUM源配置文件
if [ -f /etc/yum.repos.d/CentOS-Base.repo ]; then
sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
echo -e "${GREEN}已备份当前的YUM源配置文件到 /etc/yum.repos.d/CentOS-Base.repo.bak${NC}"
else
echo -e "${RED}未找到 /etc/yum.repos.d/CentOS-Base.repo 文件,跳过备份步骤${NC}"
fi

# 下载选定的YUM源配置文件
sudo wget -O /etc/yum.repos.d/CentOS-Base.repo $repo_url
if [ $? -eq 0 ]; then
echo -e "${GREEN}成功下载选定的YUM源配置文件${NC}"
else
echo -e "${RED}下载选定的YUM源配置文件失败,请检查网络连接${NC}"
exit 1
fi

# 清除YUM缓存并生成新的缓存
sudo yum clean all
sudo yum makecache

# 验证新的YUM源配置是否成功
sudo yum repolist -y
if [ $? -eq 0 ]; then
echo -e "${GREEN}新的YUM源配置成功${NC}"
else
echo -e "${RED}新的YUM源配置失败,请检查YUM源配置文件${NC}"
exit 1
fi

# 下载并配置EPEL源
sudo wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
if [ $? -eq 0 ]; then
echo -e "${GREEN}成功下载并配置EPEL源${NC}"
else
echo -e "${RED}下载EPEL源失败,请检查网络连接${NC}"
exit 1
fi

echo -e "${GREEN}YUM源更换并配置EPEL源成功${NC}"

# 提示用户是否需要进行系统更新
read -p "是否需要进行系统更新(默认不更新)?[y/N]: " update_choice
if [[ "$update_choice" =~ ^[Yy]$ ]]; then
sudo yum upgrade -y
if [ $? -eq 0 ]; then
echo -e "${GREEN}依赖包更新成功${NC}"
else
echo -e "${RED}依赖包更新失败${NC}"
fi
else
echo -e "${GREEN}跳过系统更新${NC}"
fi
1
2
cd /etc/sysconfig/network-scripts/
vim ifcfg-ens160

改名:

hostnamectl set-hostname centos-backup

跑分

wget -qO- –no-check-certificate https://raw.githubusercontent.com/oooldking/script/master/superbench.sh | bash

V2ray 一键脚本:

bash <(curl -s -L https://git.io/v2ray.sh)

调试shell脚本

{ set -x
set +x; } 2>/tmp/desktop.log

shell终端显示全路径

1
echo "export PS1='[\u@\h $PWD]$'" >> ~/.bash_profile

使用ll显示更友好

最新修改的文件排在最下面

1
alias ll='ls -lhtr --time-style=long-iso'

比 ctrl+r 更准确、有效的在历史命令纪录中查找自己想要的命令:

  1. 首先在该用户家目录下新建一个 .inputrc 文件,并在其中写入以下配置,如下:
1
2
3
4
5
6
7
cat > ~/.inputrc << eof
"\e[A": history-search-backward
"\e[B": history-search-forward
set show-all-if-ambiguous on
set completion-ignore-case on

eof

error while loading shared libraries: LibXm.so.4: cannot open shared object file: No such file or directory

在Linux应用软件安装的过程中,比较头疼的是库的问题,比如安装完成程序后,碰到这样的信息:xxxxx: error while loading shared libraries: LibXm.so.4: cannot open shared object file: No such file or directory

这时候对Linux系统不熟悉的用户往往一头雾水:难道应用软件不是说可以在这个Linux的Distribution上安装的么?
早期的Redhat的一些Linux版本有一个万能的办法:就是在安装Linux的过程中选择“完全安装”,虽然安装的系统很是占
硬盘,但是不需要操心库的事情了。现在就复杂得多:什么Server安装、Develop安装、Desktop安装,等等。在安装应用
软件的时候,用户就要操心库的事情了。但是有一点是好的:就是应用软件如果说在那个Linux版本上是支持的,比如Suse 11,
那么,至少你不需要到处去找库的安装包 - Linux安装光盘或者ISO包中一定有。

以libXm.so.4为例,这时说,应用软件需要motif或者openmotif的支持。这时候用户只需要将Linux的光盘
放到驱动器或者挂载Linux系统的ISO文件,进入相应的目录,比如:
/media/RHEL5u5/Server(这个目录下是安装所需要的rpm文件)
列举一下Openmotif相关的rpm文件,选择x86-64或者i386包,使用:
#rpm -ivh openmotif-xxx.rpm
就可以完成libXm.so.4的安装。

您的VPN账号已创建:
用户名:lfdou
密码:Letmin07183