Docker配置WebSSH的实现

本站所有内容来自互联网收集,仅供学习和交流,请勿用于商业用途。如有侵权、不妥之处,请第一时间联系我们删除!Q群:迪思分享

免费资源网 – https://freexyz.cn/
目录1、基于DockerHub Centos镜像2、 Centos镜像存在的一个自身问题:启动后的容器内部无法使用systemctl命令3、在基础镜像中安装基础服务 4、在基础镜像中配置WebSSH5、后台启动并指定webssh服务的日志目录 6、加入开机自启 7、制作最终镜像并在迁移后使用  8、页面访问

1、基于DockerHub Centos镜像

docker pull centos:centos7

Docker配置WebSSH的实现插图

2、 Centos镜像存在的一个自身问题:启动后的容器内部无法使用systemctl命令

Failed to get D-Bus connection: Operation not permitted

## docker run -dit eeb6ee3f44bd /bin/bash ## 切勿忘记宿主机防火墙开放8889 2200端口 docker run -dit -p 8889:8888 -p 2200:22 –restart=always –privileged –name t2 centos:centos7 init

3、在基础镜像中安装基础服务

(1)安装sshd、httpd、firewalld服务

yum install -y openssh openssh-server openssh-client yum install httpd yum install firewalld firewall-config

(2) 启动服务后并加入开机自启

## 启动 systemctl start sshd systemctl start httpd systemctl start firewalld ## 开机自启 systemctl enable sshd systemctl enable httpd systemctl enable firewalld

(3)针对于httpd服务

localhost.localdomain httpd[1953]: AH00558: httpd: Could not reliably determine the servers fully qualified domain name, using localhost.localdomain. Set the ServerName directive globally to suppress this message

vi /etc/httpd/conf/httpd.conf 加入一句:ServerName localhost:80 systemctl restart httpd

(4)针对于firewalld服务

WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuration option. It will be removed in a future release. Please consider disabling it now

vi /etc/firewalld/firewalld.conf AllowZoneDrifting=yes ====》》AllowZoneDrifting=no systemctl restart firewalld

(5)开放端口

firewall-cmd –permanent –add-port=8888/tcp firewall-cmd –reload firewall-cmd –list-all

(6)设置默认初始密码:passwd root

 4、在基础镜像中配置WebSSH

(1)安装python3

yum install python3-pip

(2)安装WebSSH

##### pip3 install webssh ##### pip3 报错:Command “python setup.py egg_info” failed with error code 1 in /tmp/pip-build-xxx/xxx/ ##### https://www.modb.pro/db/81767

针对以上报错的解决方案:

### 升级setuptools pip3 install –upgrade setuptools -i https://mirrors.aliyun.com/pypi/simple/ ### 升级pip工具:https://www.cnblogs.com/rychh/p/16206842.html pip3 –default-timeout=1000 install –upgrade pip -i https://mirrors.aliyun.com/pypi/simple/

 额外针对于以下告警的处理可选择性处理:

### WARNING: Running pip as the root user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

### https://blog.csdn.net/m0_58782029/article/details/129049587

进行安装:

pip3 –default-timeout=1000 install webssh -i https://mirrors.aliyun.com/pypi/simple/

5、后台启动并指定webssh服务的日志目录

wssh –log-file-prefix=/data/webssh/wssh.log –timeout=500 –fbidhttp=false &

 6、加入开机自启

vi /etc/rc.local wssh –log-file-prefix=/data/webssh/wssh.log –timeout=500 –fbidhttp=false & chmod 777 /etc/rc.local

 7、制作最终镜像并在迁移后使用 

1、打包正在运行的容器为 image docker commit eeb6ee3f44bd webssh:dev 2、保存image到文件 docker save -o webssh_dev.tar webssh:dev 3、使用已保存的image文件 docker load –input webssh_dev.tar

 8、页面访问

访问方式(1)如图:

Docker配置WebSSH的实现插图1

 访问方式(2)

## password需要进行base64加密 http://ip:8889?hostname=ip&username=root&password=cm9vdA==&port=2200

备注:

## 查看容器启动日志 [vagrant@localhost images]$ sudo docker inspect –format {{.LogPath}} 21431ff039e7 /data/docker/containers/21431ff039e768753702d64cb01b1a75bb250c2c587b0f3396dd30b548a62850/21431ff039e768753702d64cb01b1a75bb250c2c587b0f3396dd30b548a62850-json.log
免费资源网 – https://freexyz.cn/


© 版权声明
THE END
★喜欢这篇文章吗?喜欢的话,麻烦动动手指支持一下!★
点赞15 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容