Centos初始化

  1. 1. 换源
    1. 1.1. 备份
    2. 1.2. 写入国内源(centos 7)
    3. 1.3. 更新
  2. 2. 设置代理
  3. 3. 基础建设
    1. 3.1. git && gcc
    2. 3.2. pip
  4. 4. ZSH
    1. 4.1. 安装 & 激活

换源

备份

1
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

写入国内源(centos 7)

ustc: https://lug.ustc.edu.cn/wiki/mirrors/help/centos

163:

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

更新

1
2
yum clean all
yum makecache

设置代理

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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#! /bin/bash
# Author: Kevin Tan
# Update-Date: 2017-1-14
URL=$1
ACTION=('\nSet' '\nDel')
mode=1
if [ -z $URL ]; then
echo '[Warning]: URL parameter is empty, default action change to remove'
mode=2
fi
set_proxy(){
file=$1;prefix=$2;value="$2=$3";
echo "Set \"$value\" to \"$file\""
if [ -e "$file" ]; then
if grep -q "^\s*$prefix" "$file"; then
sed -i "s#^\s*$prefix=.*#$value#g" $file
else
echo $value >> $file
fi
fi
}
del_proxy(){
file=$1;prefix=$2
echo "Del \"$prefix\" from \"$file\""
if [ -e "$file" ]; then
sed -i "/^\s*$prefix=.*/d" $file
fi
eval $prefix=""
}
SHELL_NAME=`ps -p $$ | awk 'NR==2 {print $4}'`
echo 'Current shell is '$SHELL_NAME
source_file(){
## bash
if [ "$SHELL_NAME" = "bash" ]; then
source $HOME'/.bashrc'
fi
## zsh
if [ "$SHELL_NAME" = "zsh" ]; then
source $HOME'/.zshrc'
fi
}
# yum
echo -n ${ACTION[$mode]}' the yum? (y/n/r) ';read F
if [ $F = 'y' ] && [ $mode -eq 1 ]; then
set_proxy '/etc/yum.conf' 'proxy' $URL
elif [ $F = 'r' ] || ([ $F = 'y' ] && [ $mode -eq 2 ]); then
del_proxy '/etc/yum.conf' 'proxy'
fi
# environment
echo -n ${ACTION[$mode]}' the environment var?(y/n/r) ';read F
shell_names=(zsh bash)
if [ $F = 'y' ] && [ $mode -eq 1 ]; then
for name in ${shell_names[@]}; do
set_proxy "$HOME/.${name}rc" "export http_proxy" $URL
set_proxy "$HOME/.${name}rc" "export https_proxy" $URL
done
source_file
elif [ $F = 'r' ] || ([ $F = 'y' ] && [ $mode -eq 2 ]); then
for name in ${shell_names[@]}; do
del_proxy "$HOME/.${name}rc" "export http_proxy"
del_proxy "$HOME/.${name}rc" "export https_proxy"
done
fi
#curl
echo -n ${ACTION[$mode]}' the curl proxy alias?(y/n/r) ';read F
shell_names=(zsh bash)
if [ $F = 'y' ] && [ $mode -eq 1 ]; then
for name in ${shell_names[@]}; do
set_proxy "$HOME/.${name}rc" "alias curl" "\"curl -x $URL\""
done
source_file
elif [ $F = 'r' ] || ([ $F = 'y' ] && [ $mode -eq 2 ]); then
for name in ${shell_names[@]}; do
del_proxy "$HOME/.${name}rc" "alias curl"
unalias curl
done
fi
# kubernetes
echo -n ${ACTION[$mode]}' kube environment var?(y/n/r) ';read F
if [ $F = 'y' ] && [ $mode -eq 1 ]; then
for name in ${shell_names[@]}; do
set_proxy "$HOME/.${name}rc" "export KUBERNETES_HTTP_PROXY" $URL
set_proxy "$HOME/.${name}rc" "export KUBERNETES_HTTPS_PROXY" $URL
set_proxy "$HOME/.${name}rc" "export KUBE_BUILD_HTTPS_PROXY" $URL
set_proxy "$HOME/.${name}rc" "export KUBE_BUILD_HTTP_PROXY" $URL
done
source_file
elif [ $F = 'r' ] || ([ $F = 'y' ] && [ $mode -eq 2 ]); then
for name in ${shell_names[@]}; do
del_proxy "$HOME/.${name}rc" "export KUBERNETES_HTTP_PROXY"
del_proxy "$HOME/.${name}rc" "export KUBERNETES_HTTPS_PROXY"
del_proxy "$HOME/.${name}rc" "export KUBE_BUILD_HTTPS_PROXY"
del_proxy "$HOME/.${name}rc" "export KUBE_BUILD_HTTP_PROXY"
done
fi
# docker
echo -n ${ACTION[$mode]}' the docker?(y/n/r) ';read F
if type "docker" &>/dev/null && ([ $F = 'y' ] || [ $F = 'r' ]); then
DOCKER_CONF_DIR='/etc/systemd/system/docker.service.d'
DOCKER_CONF=$DOCKER_CONF_DIR'/http-proxy.conf'
REGISTRY="87129800.m.daodocker.io"
sudo mkdir -p "$DOCKER_CONF_DIR"
sudo rm -rf $DOCKER_CONF
if [ $F = 'y' ] && [ $mode -eq 1 ]; then
printf "[Service]\nEnvironment=" | sudo tee $DOCKER_CONF > /dev/null
printf "\"HTTP_PROXY=%s\" " $URL | sudo tee -a $DOCKER_CONF > /dev/null
printf "\"HTTPS_PROXY=%s\" " $URL | sudo tee -a $DOCKER_CONF > /dev/null
printf "\"NO_PROXY=localhost,%s\"" $REGISTRY | sudo tee -a $DOCKER_CONF > /dev/null
fi
sudo systemctl daemon-reload
sudo systemctl restart docker
echo "Daemon reloaded"
systemctl show --property=Environment docker
fi

将上面脚本保持为setproxy,然后执行,注意,如果当前环境下已经有了http_proxy等变量。则需要我们手动reset

1
2
chmod u+x setproxy
source setproxy http://10.100.100.136:4411

基础建设

git && gcc

1
yum install git gcc

pip

1
curl "https://bootstrap.pypa.io/get-pip.py" | python

EPEL

1
rpm -ivh http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

ZSH

安装 & 激活

1
2
yum install zsh
chsh -s /bin/zsh