分步执行
增加用户并设置明码
- 增加用户 unicom,uid 与 groupId 均为 1024, 登录默认终端为 bash, 主目录为 /home/unicom.
useradd -u 1024 -U -s /bin/bash -m -d /home/unicom unicom
查看增加后果:
cat /etc/passwd |grep unicom
输入如下:
unicom:x:1024:1024::/home/unicom:/bin/bash
- 设置登录明码
echo "mypwd" |passwd --stdin unicom
或者:
echo "unicom:mypwd" |chpasswd
赋予用户 docker 权限
usermod -aG docker unicom
如果提醒用户组 docker 不存在,新建即可:
groupadd docker
赋予用户 sudo 权限
echo -e "\nunicom ALL=(ALL) ALL" >> /etc/sudoers
批处理及在线执行
命令整合
mkdir static
cat > ./static/add_user.sh <<-EOF
#!/bin/sh
useradd -u 1024 -U -s /bin/bash -m -d /home/unicom unicom
cat /etc/passwd |grep unicom
echo "Cuscri@1109" |passwd --stdin unicom
echo "unicom:Cuscri@1109" |chpasswd
echo "add user unicom,default password:Cuscri@1109"
groupadd docker
usermod -aG docker unicom
echo "append user to group docker"
echo -e "\nunicom ALL=(ALL) ALL" >> /etc/sudoers
echo "append user to sudoers"
EOF
动态资源服务器配置
应用 nginx 作为动态资源服务器。nginx 配置片段:
server {
listen 80;
location ~*\.(sh|svg|png|css|js)$ {root /usr/share/nginx/static/;}
}
docker-compose 配置:
version: '3.8'
services:
nginx:
image: nginx:1.22.1-perl
container_name: nginx
ports:
- "80:80"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
- ./static:/usr/share/nginx/static
fluent 格调在线执行
curl http://${NGINX_HOST}/add_user.sh |sh