docker和docker-compose一键安装脚本

行云流水
2022-03-07 / 41 评论 / 3,619 阅读 / 正在检测是否收录...

前言

脚本说明

脚本下载



系统初始化

一键执行脚本

sh system_init_v4.sh

手动执行过程

配置yum源

    yum install -y wget
    mv /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.cloud.tencent.com/repo/centos7_base.repo
    wget -O /etc/yum.repos.d/epel.repo http://mirrors.cloud.tencent.com/repo/epel-7.repo
    yum clean all
    yum makecache

安装必要的软件,创建目录

    yum install -y vim wget lrzsz telnet traceroute iotop tree rsync
    yum install -y git zlib-devel openssl-devel unzip xz libxslt-devel libxml2-devel libcurl-devel
    #yum -y install ipset  ipset-service  >/dev/null 2>&1
    yum -y install net-tools.x86_64 vim lsof
    yum install -y openssl openssl-devel openssh openssh-server
    yum install -y ntpdate crontabs

修改系统限制

cat <<EOF >>/etc/security/limits.conf
* soft nofile 1048576
* hard nofile 1048576
EOF

cat <<EOF >/etc/security/limits.d/20-nproc.conf
*             soft    nproc     1048576
*             soft    nproc     1048576
EOF

增加操作系统记录数量

if ! grep "HISTTIMEFORMAT" /etc/profile >/dev/null 2>&1
then echo '
UserIP=$(who -u am i | cut -d"("  -f 2 | sed -e "s/[()]//g")
export HISTTIMEFORMAT="[%F %T] [`whoami`] [${UserIP}] " ' >> /etc/profile;
fi
sed -i "s/HISTSIZE=1000/HISTSIZE=999999999/" /etc/profile

系统内核优化

cat <<EOF > /etc/sysctl.conf
fs.file-max = 6553560
net.core.netdev_max_backlog = 32768
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.somaxconn = 32768
net.core.wmem_default = 8388608
net.core.wmem_max = 16777216
net.ipv4.conf.all.arp_ignore = 0
net.ipv4.conf.lo.arp_announce = 0
net.ipv4.conf.lo.arp_ignore = 0
net.ipv4.ip_local_port_range = 5000 65000
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_intvl = 30
net.ipv4.tcp_keepalive_probes = 3
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_max_syn_backlog = 65536
net.ipv4.tcp_max_tw_buckets = 5000
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
vm.overcommit_memory = 1
EOF

关闭selinux

    sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
    sed -i 's/SELINUX=permissive/SELINUX=disabled/g' /etc/selinux/config
    setenforce 0
    yum -y remove firewalld
    yum -y install iptables-services  iptables

同步系统时间,时区设置

    rm -f /etc/localtime
    ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
    /usr/sbin/ntpdate  ntp.ntsc.ac.cn
    /usr/sbin/hwclock  -w

    #计划任务,每5分钟同步系统时间
    echo "*/5 * * * * flock -xn /tmp/ntp.lock -c '/usr/sbin/ntpdate ntp.ntsc.ac.cn  >> /tmp/ntp.log 2>&1 &'" >> /var/spool/cron/root

登录欢迎语设置

    /usr/bin/cp -f ../support/login.sh  /usr/local/bin/login.sh && chmod +x /usr/local/bin/login.sh
    echo "/usr/local/bin/login.sh" >> /etc/profile

docker安装

一键执行脚本

sh app_install_docker.sh

手动执行过程

安装python3环境

yum update -y
yum groupinstall Development tools -y
yum -y install zlib-devel
yum install -y openssl-devel libxslt-devel libxml2-devel libcurl-devel
yum install python3 -y

安装docker-ce

yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

yum-config-manager --enable docker-ce-edge
yum install -y docker-ce

安装docker-compose编排工具

/bin/cp -f ../support/docker-compose /usr/local/bin/docker-compose && chmod +x /usr/local/bin/docker-compose

docker服务开机自启

/bin/systemctl enable --now  docker

评论 (41)

取消
只有登录/注册用户才可评论
  1. 头像
    szhuangzhifeng
    中国广东省 · Windows 10 · Google Chrome
    沙发

    感谢博主

    回复
  2. 头像
    Robinson
    中国河南省 · Windows 10 · Google Chrome
    板凳

    受益匪浅,感谢博主。

    回复
  3. 头像
    程序兔
    中国北京市 · Android · Google Chrome
    地毯

    继续努力啊,多一些脚本啊::(嗯哼)

    回复
    1. 头像
      行云流水 作者
      中国河北省 · MacOS · Google Chrome
      @ 程序兔

      好的,一起学习

      回复
  4. 头像
    jiangfayu
    中国上海市 · Windows 10 · Google Chrome
    第4楼

    受益匪浅,感谢博主。对小白真的很友好,写的很全面。

    回复
  5. 头像
    tiger
    · Windows 10 · Google Chrome
    第5楼

    这篇文章肯定会火,作者666大顺

    回复
  6. 头像
    fengxs
    · Windows 10 · Google Chrome
    第6楼

    表情 牛逼

    回复
  7. 头像
    fengxs
    中国北京市 · Windows 10 · Google Chrome
    第7楼

    对小白真的很友好,写的很全面。

    回复
  8. 头像
    coder00001
    中国广东省 · Windows 10 · Google Chrome
    第8楼

    喜欢这篇文章,作者666,文章真棒!

    回复
  9. 头像
    喜欢阅读的东方雨蝶
    中国湖北省 · Windows 10 · Google Chrome
    第9楼

    很方便,很有用

    回复
  10. 头像
    914602625@qq.com
    中国广东省 · Windows 10 · Google Chrome
    第10楼

    谢谢传授

    回复