Centos 7 Docker 安裝

泽翰發表於2024-06-16

1、設定主機網路,關閉防火牆,selinux等

[root@localhost ~]# cat  /etc/sysconfig/network-scripts/ifcfg-ens32 
TYPE=Ethernet
BOOTPROTO=static
NAME=ens32
DEVICE=ens32
ONBOOT=yes
IPADDR=192.168.xxx.10
NETMASK=255.255.255.0
GATEWAY=192.168.xxx.2
DNS1=192.168.xxx.2
DNS2=114.114.114.114
DNS3=8.8.8.8
[root@localhost ~]# systemctl restart network

#!/bin/bash
echo "----關閉selinux----"
sed -i '/^SELINUX=.*/c SELINUX=disabled' /etc/selinux/config
sed -i 's/^SELINUXTYPE=.*/SELINUXTYPE=disabled/g' /etc/selinux/config
grep --color=auto '^SELINUX' /etc/selinux/config
setenforce 0

sleep 1
echo "----關閉防火牆----"
systemctl stop firewalld
systemctl disable firewalld
systemctl stop iptables
systemctl disable iptables

sleep 1
echo "----關閉network管理系統----"
systemctl stop NetworkManager
systemctl disable NetworkManager

sleep 1
echo "----安裝依賴外掛----"
yum -y install epel-release wget
mkdir -p /etc/yum.repos.d/bak
mv /etc/yum.repos.d/* /etc/yum.repos.d/bak
wget http://mirrors.aliyun.com/repo/Centos-7.repo -P /etc/yum.repos.d/
wget http://mirrors.aliyun.com/repo/epel-7.repo -P /etc/yum.repos.d/
yum -y install wget vim ntp unzip zip net-snmp* telnet sysstat gcc gcc-c++ make openssl* perl ncurses* nethogs lsof lrzsz libselinux-python bash-completion net-tools setuptool system-config-network-tui ntsysv expat-devel psmisc nmap fping traceroute python2-pip readline-devel cpp cmake bison libaio-devel ncurses-devel perl-DBD-MySQL perl-Time-HiRes openssh-clients libaio zlib-devel libssl.so.6 numactl jemalloc compat-readline5-devel bind-utlis lsof

sleep 1
echo "----修改時區----"
timedatectl set-timezone Asia/Shanghai
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

sleep 1
echo "----禁止使用Ctrl+Alt+Del重啟----"
mv /usr/lib/systemd/system/ctrl-alt-del.target /usr/lib/systemd/system/ctrl-alt-del.target.bak
init q

sleep 1
echo "----修改字元編碼----"
echo 'LANG="en_US.UTF-8"
SUPPORTED="zh_CN.GB18030:zh_CN:zh:en_US.UTF-8:en_US:en"
SYSFONT="latarcyrheb-sun16"' > /etc/locale.conf

#sleep 1
#echo "----內網伺服器,配置同步時間----"
#systemctl stop ntpd
#systemctl disable ntpd

sleep 1
echo "----可上外網伺服器,配置同步時間----"
ntpdate ntp1.aliyun.com
echo '*/5 * * * * /usr/sbin/ntpdate ntp1.aliyun.com > /dev/null 2>&1' >> /var/spool/cron/root



echo "----最佳化tcp連線數----"
sleep 1
echo "----使用者可用的最大程序數量----"
cat >> /etc/security/limits.conf << EOF
* soft nproc 65536
* hard nproc 65536
* soft nofile 65536
* hard nofile 65536
EOF

sleep 1
echo "----Linux最大程序數最大程序數量----"
cat >> /etc/security/limits.d/20-nproc.conf << EOF
* soft nproc unlimited
* hard nproc unlimited
EOF

sleep 1
#這裡使用的是64位的系統,所以目錄是lib64,請先確認此檔案是否存在,不然會導致密碼登陸報moudule is unknow
#cat >> /etc/pam.d/login << EOF
#session required /lib64/security/pam_limits.so
#session required pam_limits.so
#EOF

sleep 1
echo "----Linux系統所有程序共計可以開啟的檔案數量----"
cat >> /etc/sysctl.conf << EOF
fs.file-max = 65535
EOF

sleep 1
echo "----使用者登入系統後開啟檔案數量----"
cat >> /etc/profile << EOF
ulimit -HSn 65535
EOF



sleep 1
#echo "----設定使用者登入記錄----"
echo '#!/bin/bash
loginFile="/var/log/sshd/sshlogin.log"
user=$USER
ip=${SSH_CLIENT%% *}
#if [ "$user" != "root" ] || [ "$ip" != "192.168.31.88" ]
 #then
echo "LoginUser:"$user"--IP:"$ip"--LoginTime:"`date "+%Y-%m-%d %H:%M:%S"` >> "$loginFile";
#fi' >> /etc/ssh/sshrc
mkdir /var/log/sshd
touch /var/log/sshd/sshlogin.log
chmod -R 777 /var/log/sshd
chmod +x /etc/ssh/sshrc

sleep 1
#echo "----檢視歷史操作記錄,並加時間戳----"
echo 'export HISTTIMEFORMAT="%F %T `whoami` "' >> /etc/profile
source /etc/profile

sleep 1
#echo "----系統啟動配置檔案賦權----"
chmod +x /etc/rc.d/rc.local

2、安裝docekr

[root@localhost ~]# yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
[root@localhost ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@localhost ~]# yum -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
[root@localhost ~]# systemctl start docker
[root@localhost ~]# systemctl enable docker
[root@localhost ~]# docker info

相關文章