代码拉取完成,页面将自动刷新
同步操作将从 Kenny小狼/install-docker 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#! /bin/bash
##### Constants
DOCKER_LIB_HOME=/home/docker/lib/
STEP_COUNT=1
# YOUR_REGISTRY_MIRROR
DOCKER_REGISTRY_MIRROR="$1"
DOCKER_PRIVATE_REGISTRY=foo.registry.docker:5000
CUSTOM_BASE_REPO='http://mirrors.aliyun.com/repo/Centos-7.repo'
CUSTOM_EPEL_REPO='http://mirrors.aliyun.com/repo/epel-7.repo'
##### Functions
function command_installed(){
if [[ -n "$1" ]] && (type "$1" &> /dev/null ); then
return 0; # true
fi
return 1;
}
function service_started(){
if [[ -n "$1" ]]; then
info=$(systemctl status $1 | grep 'Active' )
read prefix status rest <<<"$info"
if [[ $status == 'active' ]]; then
return 0;
fi
fi
return 1;
}
function custom_base_repo(){
mv /etc/yum.repos.d/CentOS-Base.repo{,.backup}
curl -o /etc/yum.repos.d/CentOS-Base.repo $CUSTOM_BASE_REPO
yum clean all && rm -rf /var/cache/yum
}
function custom_epel_repo(){
yum makecache
yum -y install epel-release
mv /etc/yum.repos.d/epel.repo{,.backup}
mv /etc/yum.repos.d/epel-testing.repo{,.backup}
curl -o /etc/yum.repos.d/epel.repo $CUSTOM_EPEL_REPO
yum clean all && rm -rf /var/cache/yum
}
function install_common_package(){
echo "########################"
echo " $STEP_COUNT. install common tools"
echo "########################"
if command_installed 'pip' && command_installed 'git' && command_installed 'iptables'; then
echo "common packages must be already installed."
else
custom_base_repo
custom_epel_repo
yum makecache
yum install -y net-tools vim git \
ntsysv setuptool yum-utils python-pip python-setuptools \
lsof bzip2 unzip tar gcc wget nfs-utils \
device-mapper-persistent-data lvm2
yum install -y policycoreutils-python
mkdir ~/.pip/
tee ~/.pip/pip.conf <<-'EOF'
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
EOF
fi
add_step_count
}
function install_docker_engine(){
docker_repo_file=/etc/yum.repos.d/docker-ce.repo
docker_config_dir=/etc/systemd/system/docker.service.d
echo "########################"
echo " $STEP_COUNT. install docker engine"
echo "########################"
if [ ! -d ${DOCKER_LIB_HOME} ]; then
mkdir -p ${DOCKER_LIB_HOME}
fi
if command_installed 'docker'; then
echo "docker engine must be already installed."
else
yum-config-manager \
--add-repo \
https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
if [[ ! -s ${docker_repo_file} ]]; then
# retry tsinghua mirror
yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
sed -i 's+download.docker.com+mirrors.tuna.tsinghua.edu.cn/docker-ce+' /etc/yum.repos.d/docker-ce.repo
fi
yum makecache fast
# Uninstall old versions
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
yum install -y docker-ce docker-ce-cli containerd.io
mkdir -p ${docker_config_dir}
if [[ -n "$DOCKER_REGISTRY_MIRROR" ]]; then
tee "$docker_config_dir/docker.conf" <<-EOF
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd \
--insecure-registry ${DOCKER_PRIVATE_REGISTRY} \
--graph=${DOCKER_LIB_HOME} \
--registry-mirror=${DOCKER_REGISTRY_MIRROR}
EOF
else
tee "$docker_config_dir/docker.conf" <<-EOF
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd \
--insecure-registry ${DOCKER_PRIVATE_REGISTRY} \
--graph=${DOCKER_LIB_HOME}
EOF
fi
systemctl daemon-reload
systemctl restart docker
systemctl enable docker
# enable IPv4
sysctl -w net.ipv4.ip_forward=1
fi
add_step_count
}
function install_docker_compose(){
echo "########################"
echo " $STEP_COUNT. install Docker-Compose"
echo "########################"
if command_installed 'docker-compose'; then
echo "docker-compose must be already installed."
else
pip install docker-compose
fi
add_step_count
}
function install_supervisor(){
echo "########################"
echo " $STEP_COUNT. install Supervisor"
echo "########################"
if command_installed 'supervisord'; then
echo "supervisord must be already installed."
else
pip install --upgrade pip
pip install supervisor
fi
mkdir -p /etc/supervisor /etc/supervisor/conf.d/
echo_supervisord_conf > /etc/supervisor/supervisord.conf
echo '[include]'>>/etc/supervisor/supervisord.conf
echo 'files = /etc/supervisor/conf.d/*.ini'>>/etc/supervisor/supervisord.conf
sudo tee /usr/lib/systemd/system/supervisord.service<<-'EOF'
[Unit]
Description=Supervisor daemon
[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown
ExecReload=/usr/bin/supervisorctl $OPTIONS reload
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
EOF
add_step_count
}
function add_step_count(){
((STEP_COUNT++))
}
function main(){
install_common_package
install_docker_engine
install_docker_compose
install_supervisor
}
main
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。