整理自「开发 Tips」系列,汇总 CentOS 服务器运维中的常见问题与解决方法。
1. 升级 Docker 版本
- 卸载旧版本的 Docker
1
2
3
4
5
6
| $yum remove docker \
docker-common \
container-selinux \
docker-selinux \
docker-engine \
docker-engine-selinux
|
保存在 /var/lib/docker/ 的镜像、容器、数据、网络都会被保留。
- 安装依赖
1
| yum install -y yum-utils device-mapper-persistent-data lvm2
|
- 安装 Docker
1
2
3
| yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
|
2. 新增交换分区文件
查看当前分区情况:
增加 swap 大小,2G 左右:
1
| dd if=/dev/zero of=/var/swap bs=1024 count=2048000
|
设置交换文件:
立即激活启用交换分区:
添加系统引导时自启动运行,编辑 /etc/fstab,添加一行:
1
| /var/swap swap swap defaults 0 0
|
收回 swap 空间:
1
2
| swapoff /var/swap
rm /var/swap
|
3. 安装 minikube
新增安装源:
1
2
3
4
5
6
7
8
9
| cat <<'EOF' > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-$basearch
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF
|
开始安装:
1
2
3
4
| yum -y install kubectl
wget https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 -O minikube
chmod +x minikube
mv minikube /usr/local/bin/
|
Linux 下 minikube 支持两种虚拟机 VirtualBox 和 KVM。但如果使用的是云服务器,无法开启 CPU 的虚拟化功能,可以使用宿主机的 Docker 环境:
1
| minikube start --vm-driver=none
|
参考文章。
4. 安装指定版本的 Docker
新增 Aliyun 的 docker-ce 源:
1
2
| yum install -y yum-utils
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
|
查看可选的 docker-ce 版本:
1
2
3
4
5
6
| yum list docker-ce --showduplicates
docker-ce.x86_64 17.03.3.ce-1.el7 docker-ce-stable
docker-ce.x86_64 18.06.3.ce-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.9-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.8-3.el7 docker-ce-stable
|
安装指定版本的 docker-ce:
1
| yum install -y docker-ce-19.03.8-3.el7
|
启动:
1
2
| systemctl start docker
systemctl enable docker
|
5. 编译安装 Python 3.7
安装依赖:
1
| yum install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils libffi-devel
|
下载源码包:
1
2
| cd /usr/src
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
|
开始安装:
1
2
3
4
| tar xzf Python-3.7.0.tgz
cd Python-3.7.0
./configure --enable-optimizations
make altinstall
|
查看版本信息:
安装 pip:
1
2
| wget https://bootstrap.pypa.io/get-pip.py -O - | python3.7
pip3 -V
|
6. 升级安装 Git2
- 移除旧版本:
- 安装 epel-release repository:
1
| yum install epel-release
|
- 安装 IUS repository:
1
| yum install https://centos7.iuscommunity.org/ius-release.rpm
|
- 安装 git2u:
7. /etc/rc.local 开机不自动运行
查看 /etc/rc.local 内容发现:
1
2
| # Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
|
CentOS 7 建议创建 systemd 用于开机自启动。
如果需要使用旧的方式,则需要添加到 /etc/rc.d/rc.local。同时,执行 chmod +x /etc/rc.d/rc.local,赋予可执行权限。
8. 查看端口占用
1
2
| yum install -y lsof
lsof -i:30948
|
1
2
| yum install -y net-tools
netstat -apn | grep 30948
|
9. tcpdump 查看指定端口、指定 IP 来源数据
1
2
| yum install -y tcpdump
tcpdump -i eth0 -nnA 'port 30948 and src host 192.168.10.3' -vv
|
10. 安装 GLIBC 2.18
查看已经安装的 GLIBC 版本:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| strings /lib64/libc.so.6 |grep GLIBC_*
GLIBC_2.2.5
GLIBC_2.2.6
GLIBC_2.3
GLIBC_2.3.2
GLIBC_2.3.3
GLIBC_2.3.4
GLIBC_2.4
GLIBC_2.5
GLIBC_2.6
GLIBC_2.7
GLIBC_2.8
GLIBC_2.9
GLIBC_2.10
GLIBC_2.11
GLIBC_2.12
GLIBC_2.13
GLIBC_2.14
GLIBC_2.15
GLIBC_2.16
GLIBC_2.17
|
安装 GLIBC 2.18:
1
2
3
4
5
6
7
| wget http://ftp.gnu.org/gnu/glibc/glibc-2.XX.tar.gz
tar -xvf glibc-2.18.tar.gz
cd glibc-2.18
mkdir build && cd build
../configure --prefix=/usr
make -j4
make install
|