分步执行
增加用户并设置明码
- 增加用户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 staticcat > ./static/add_user.sh <<-EOF#!/bin/shuseradd -u 1024 -U -s /bin/bash -m -d /home/unicom unicomcat /etc/passwd |grep unicomecho "Cuscri@1109" |passwd --stdin unicomecho "unicom:Cuscri@1109" |chpasswdecho "add user unicom,default password:Cuscri@1109"groupadd dockerusermod -aG docker unicomecho "append user to group docker"echo -e "\nunicom ALL=(ALL) ALL" >> /etc/sudoersecho "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