1. #!/bin/bash
    2. # Version: v0.0.1                                 
    3. # Debian/Ubuntu Linux systems. (May 10, 2019)
    4. # (GNU/General Public License version 2.0)
    5. # For Centos 7 and up, Linux lzone_zkong_cluster_01 3.10.0-862.el7.x86_64.
    6. # ...And away we go!
    7. Package='/server/tools'
    8. function tools {
    9. if [ ! -d "$Package" ]; then
    10. mkdir "$Package" -p
    11. fi
    12. }
    13. function INSTALL {
    14. cp /usr/local/esl/scripts/docker-19.03.9.tgz $Package
    15. cd $Package && tar xf docker-19.03.9.tgz
    16. mv $Package/docker/* /usr/bin/
    17. cat >/etc/systemd/system/docker.service <<-EOF
    18. [Unit]
    19. Description=Docker Application Container Engine
    20. Documentation=https://docs.docker.com
    21. After=network-online.target firewalld.service
    22. Wants=network-online.target
    23. [Service]
    24. Type=notify
    25. # the default is not to use systemd for cgroups because the delegate issues still
    26. # exists and systemd currently does not support the cgroup feature set required
    27. # for containers run by docker
    28. ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
    29. ExecReload=/bin/kill -s HUP $MAINPID
    30. # Having non-zero Limit*s causes performance problems due to accounting overhead
    31. # in the kernel. We recommend using cgroups to do container-local accounting.
    32. LimitNOFILE=infinity
    33. LimitNPROC=infinity
    34. LimitCORE=infinity
    35. # Uncomment TasksMax if your systemd version supports it.
    36. # Only systemd 226 and above support this version.
    37. #TasksMax=infinity
    38. TimeoutStartSec=0
    39. # set delegate yes so that systemd does not reset the cgroups of docker containers
    40. Delegate=yes
    41. # kill only the docker process, not all processes in the cgroup
    42. KillMode=process
    43. # restart the docker process if it exits prematurely
    44. Restart=on-failure
    45. StartLimitBurst=3
    46. StartLimitInterval=60s
    47. [Install]
    48. WantedBy=multi-user.target
    49. EOF
    50. chmod +x /etc/systemd/system/docker.service
    51. systemctl daemon-reload && systemctl start docker && systemctl enable docker.service >/dev/null 2>&1
    52. systemctl status docker >/dev/null 2>&1
    53. echo "当前Docker版本: `docker -v`"
    54. }
    55. function UNINSTALL {
    56. cd /usr/local/esl/ && docker-compose stop && systemctl stop docker
    57. rpm -qa | grep docker | xargs yum remove -y >/dev/null 2>&1
    58. rm -rf /var/lib/docker
    59. sed -i '/web_code.sh/d;/Monitoring.sh/d;/docker-log.sh/d' /var/spool/cron/root
    60. sed -i '/Monitoring/d;/Check/d;/Clear/d' /var/spool/cron/root
    61. Package=`rpm -qa|grep bridge-utils|wc -l`
    62. if [ $Package -ne 1 ];then
    63. yum -y install bridge-utils
    64. fi
    65. BRIDGE_LIST=$( brctl show | cut -f 1 | grep br-)
    66. ifconfig $BRIDGE_LIST down
    67. brctl delbr $BRIDGE_LIST
    68. }
    69. echo '
    70. Please enter the action you want to perform:"install" | "uninstall"
    71. 请输入您要执行的操作:“安装install” 或者 “卸载uninstall”'
    72. read -p "Please enter the action you want to perform: " action
    73. case $action in
    74. install)
    75. tools
    76. INSTALL
    77. ;;
    78. uninstall)
    79. UNINSTALL && echo 'Docker uninstall Successfully'
    80. ;;
    81. *)
    82. echo '
    83. The action you entered is not supported.
    84. Please enter the following format: install | uninstall'
    85. exit 1
    86. esac