温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Docker如何配置WebSSH

发布时间:2023-03-08 10:40:21 来源:亿速云 阅读:110 作者:iii 栏目:开发技术

本篇内容介绍了“Docker如何配置WebSSH”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

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 server's 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

 访问方式(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

“Docker如何配置WebSSH”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI