ubuntu系统初始化制作模板机.md
1、更新系统包
这里用的是aws的标准ami,如果有其他软件需要安装请自定义
apt-get update upgrade -y
apt-get install lrzsz iotop iftop -y
2、禁用防火墙
ufw disable
3、 配置时区
timedatectl set-timezone Asia/Shanghai
sudo apt-get install ntpdate
4、 创建跳板机所需用户
方便跳板机直接连接新开服务器
useradd -m user -s /bin/bash
su - user
mkdir -m 700 /home/user/.ssh
echo 'user ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/90-cloud-init-users
echo '跳板机公钥' > /home/server/.ssh/authorized_keys
chmod 600 /home/rd/.ssh/authorized_keys
echo "net.ipv4.conf.all.rp_filter=0" | tee -a /etc/sysctl.conf
sysctl -p
5、 ulmit及系统参数配置
系统
echo 'fs.file-max = 65535' | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
用户
sudo tee -a /etc/security/limits.conf << EOF
* hard nofile 65535
* soft nofile 65535
root hard nofile 65535
root soft nofile 65535
EOF
Systemd
sudo sed -i '/DefaultLimitNOFILE/c DefaultLimitNOFILE=65535' /etc/systemd/*.conf
sudo systemctl daemon-reexec
cat >> /etc/sysctl.conf<
查看系统限制
cat /proc/sys/fs/file-max
查看用户硬限制
ulimit -Hn
查看用户软限制
ulimit -Sn
6、时间同步
sudo apt install ntp
vim /etc/ntp.conf
server 0.amazon.pool.ntp.org iburst
server 1.amazon.pool.ntp.org iburst
server 2.amazon.pool.ntp.org iburst
server 3.amazon.pool.ntp.org iburst
systemctl restart ntp.service
7、修改网卡名称
sed -i 's/GRUB_CMDLINE_LINUX=""/GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"/g' /etc/default/grub
update-grub
sed -i 's/ens5/eth0/g' /etc/netplan/50-cloud-init.yaml
sed -i 's/set-name: ens5/set-name: eth0/g' /etc/netplan/50-cloud-init.yaml
netplan apply # 更新网卡信息
需要reboot
8、配置AMI默认数据盘分区
之后创建的AMI数据盘便会自动挂载
parted /dev/nvme1n1
mkpart gpt
mkpart primary 0 -1
print
mkfs.ext4 /dev/nvme1n1
echo 'UUID=aab36f7c-610b-4a80-9c2c-91e6e947e269 /data ext4 defaults 0 0' >>/etc/fstab
mkdir /data
mount -a #检查挂载
df -h #查看挂载
9、修改dns地址
/etc/systemd/resolved.conf
DNS=172.18.40.128 172.18.41.183
systemctl restart systemd-resolved
systemctl enable systemd-resolved
mv /etc/resolv.conf /etc/resolv.conf.bak
ln -s /run/systemd/resolve/resolv.conf /etc/
10、安装node_exporter
1、上传或者下载node_exporter
chmod +x node_exporter
ln -s /data/node_exporter /usr/local/bin/
mkdir -p /opt/ops/node/
#2、ubuntu启动脚本位置和centos不同
cat >>/lib/systemd/system/node_exporter.service<>/opt/ops/node/node_start_args <
11、配置命令补全
apt-get install bash-completion
source <(kubectl completion bash)
补充:如果AMI镜像在启动实例是选择了大容量的数据盘直接resize2fs就可以扩容到磁盘最大容量
结合业务本身制作镜像,可能还需要配置各种agent,安装docker或其他软件