新机器初始化是个很繁琐的事情,结合前两篇实践文章完成初始化脚本
有道云笔记【 Ubuntu 18.04 配置基于Traefik v2的 Web 服务器 && traefik 配置CA证书HTTP转HTTPS 】
知乎地址【 Ubuntu 18.04 配置基于Traefik v2的 Web 服务器 && traefik 配置CA证书HTTP转HTTPS】
文件名称及域名根据需要可自行更改
快速初始化
1 wget -q -O - https://gitee.com/halobug/bash.halobug.cn/raw/master/bash/Ubuntu-init.sh | bash
或
1 wget -q -O - https://gitee.com/halobug/bash.halobug.cn/raw/master/bash/Ubuntu-init.sh > bash.sh
2
3 bash bash.sh
初始化完成后绑定hosts或解析域名
120.**.**.** dashboard.halobug.cn
成功访问
脚本内容如下
1 echo "* soft nofile 51200">>/etc/security/limits.conf
2
3 echo "* hard nofile 51200">>/etc/security/limits.conf
4
5 echo "session required pam_limits.so">>/etc/pam.d/common-session
6
7 echo "ulimit -SHn 51200">>/etc/profile
8
9 sed -i 's/http:\/\/.*.ubuntu.com/http:\/\/mirrors.tuna.tsinghua.edu.cn/' /etc/apt/sources.list
10
11 apt update && apt upgrade -y
12
13 apt-get install git zsh curl unzip vim -y
14
15 apt install -y apt-transport-https ca-certificates software-properties-common
16
17 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
18
19 apt-key fingerprint 0EBFCD88
20
21 add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
22
23 echo "安装 install docker"
24
25 apt install -y docker-ce
26
27 echo "启动 docker ..."
28
29 service docker start
30
31 #创建文件
32 mkdir -p /data/docker/lib
33 # 同步
34 rsync -avz /var/lib/docker /data/docker/lib
35
36 touch /etc/docker/daemon.json
37
38 echo '{"data-root": "/data/docker/lib"}' > /etc/docker/daemon.json
39
40 echo "重启 docker ...."
41 service docker restart
42
43 echo "创建 traefik 网卡"
44 docker network create traefik
45
46 #github
47 # curl -L https://github.com/docker/compose/releases/download/1.25.3/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
48 #微软
49 # curl -L http://mirror.azure.cn/docker-toolbox/linux/compose/1.25.4/docker-compose-Linux-x86_64 -o /usr/local/bin/docker-compose
50
51 mkdir ~/halobug && cd ~/halobug
52 echo "安装 docker compose"
53
54 git clone https://gitee.com/halobug/bash.halobug.cn.git && cd ~/halobug/bash.halobug.cn/file/ && cp docker-compose-Linux-x86_64 /usr/local/bin/docker-compose
55
56 chmod +x /usr/local/bin/docker-compose
57
58 #运行traefik
59 echo "run traefik ..."
60 cd ~/halobug && git clone https://gitee.com/halobug/traefik.halobug.cn.git && cd ~/halobug/traefik.halobug.cn
61
62 bash ca.sh && docker-compose down && docker-compose up -d
63
64 echo "运行完毕,新机器初始化完毕!"
65
66 echo "更换shell"
67 curl -L http://install.ohmyz.sh | sh
68
69 chsh -s /bin/zsh