阿里云快速安装Ubuntu

跟CentOS版类似

#!/bin/sh

echo -e "请尽可能避免在有业务的机器上使用,避免影响已有业务;\n"
read -p "这个脚本只能给阿里云的Ubuntu系统使用,是否继续?(y/n):" goon
if [ ! $goon == "y" ]; then
    exit 0
fi

read -p "设置Docker镜像加速地址:" mirror

# ssh
sudo ssh-keygen
touch ~/.ssh/authorized_keys

# 基础配置
sudo apt-get update -y
sudo apt-get upgrade -y

# 安装常用工具
sudo apt-get install -y git vim lrzsz htop zsh sudo python-pip psmisc lsof curl wget
chsh -s /bin/zsh
wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | sh
echo '[[ -s ~/.autojump/etc/profile.d/autojump.sh ]] && . ~/.autojump/etc/profile.d/autojump.sh' >> ~/.zshrc
sudo sed -i 's/plugins=(git)/plugins=(git autojump)/' ~/.zshrc

# 安装autojump
git clone https://github.com/joelthelion/autojump.git
cd autojump
./install
cd ..
rm -rf autojump

# 安装docker
# step 1: 安装必要的一些系统工具
sudo apt-get update
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
# step 2: 安装GPG证书
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
# Step 3: 写入软件源信息
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
# Step 4: 更新并安装 Docker-CE
sudo apt-get -y update
sudo apt-get -y install docker-ce

sudo mkdir -p /etc/docker

## 这段有点恶心但没找到好方法
sudo cat <<-'EOF' > /etc/docker/daemon.json
{
    "registry-mirrors": [
EOF

sudo echo "        \"${mirror}\"" >> /etc/docker/daemon.json

sudo cat <<-'EOF' >> /etc/docker/daemon.json
    ],
    "storage-driver":"overlay"
}
EOF

# 修理docker swap not suppot
sudo sed -i 's/GRUB_CMDLINE_LINUX_DEFAULT="quiet"/GRUB_CMDLINE_LINUX_DEFAULT="cgroup_enable=memory swapaccount=1 quiet"/' /etc/default/grub
update-grub
update-grub2

# 网络优化
sudo cat <<-'EOF' >> /etc/security/limits.conf 
* soft nofile 262140
* hard nofile 262140
root soft nofile 262140
root hard nofile 262140
* soft core unlimited
* hard core unlimited
root soft core unlimited
root hard core unlimited
EOF

sudo systemctl daemon-reload
sudo systemctl enable docker
sudo systemctl restart docker


# 设置server端的ssh心跳帧
sudo cat <<-'EOF' >> /etc/ssh/sshd_config
ClientAliveInterval 30
ClientAliveCountMax 2
EOF

# 安装docker-compose
sudo mkdir -p ~/.pip
sudo cat <<-'EOF' >~/.pip/pip.conf
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
EOF
sudo pip install --upgrade pip
sudo pip install docker-compose

# 常用别名
cat <<-'EOF' > $ZSH_CUSTOM/alias.zsh
alias 'pt'='pstree -ap|grep '
alias 'vi'='vim'
alias 'la'='ls -la'
alias 'net'='netstat -nalp'
EOF

# 最后处理
sudo apt-get update -y
sudo apt-get upgrade -y
sudo apt-get autoremove -y

# 重启
read -p "是否立即重启计算机?(y/n):" goon
if [ $goon == "y" ]; then
    sudo reboot
fi

发表评论

邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据