Cockpit 一个基于WEB的交互式服务器管理工具

2019年11月21日


参考 https://github.com/cockpit-project/cockpit https://cockpit-project.org/

简介

Cockpit 是一个免费开源的服务器管理软件,通过 web 前端界面可以轻松地管理我们的 GNU/Linux 服务器。Cockpit 使得 linux 系统管理员、系统维护员和开发者能轻松地管理他们的服务器并执行一些简单的任务,例如管理存储、启动容器、配置网络、检测日志、启动或停止服务以及一些其它任务。它的报告界面添加了一些很好的功能使得可以轻松地在终端和 web 界面之间切换。另外,它不仅使得管理一台服务器变得简单,更重要的是可以在一个地方同时管理多个通过网络连接的服务器

支持的Linux 版本包括: Debian ,Ubuntu ,FedoraCentOSRHELArch Linux 等。

支持的浏览器包括:Google Chrome,Mozilla Firefox,Microsoft Edge,Apple Safari,Opera 等。

软件界面支持中文。

screenshot-system-dark

特点

  1. 自带WEB服务,无需另行安装。
  2. 使用系统用户帐号登录/权限,不用设置特别用户帐号。
  3. 允许在一个Cockpit会话中管理多个服务器。
  4. 在终端窗口中提供基于Webshell
  5. 支持手机浏览器查看/管理系统。
  6. 可管理容器(例如:Docker,需要安装 Cockpit docker包)
  7. 使用Performance Co-Pilot框架收集系统性能信息,并将其显示在图形中。
  8. 支持使用sosreport收集系统配置和诊断信息。
  9. 还支持Kubernetes集群或Openshift v3集群。
  10. 允许修改网络设置。
  11. 基于 GNU LGPL 协议下完全免费。

安装

CentOS

Cockpit is included in CentOS 7.x:

  • Install cockpit:
sudo yum install cockpit
  • Enable cockpit:
sudo systemctl enable --now cockpit.socket
  • Open the firewall if necessary:
sudo firewall-cmd --permanent --zone=public --add-service=cockpit
sudo firewall-cmd --reload

Ubuntu

Cockpit is included in Ubuntu 17.04 and later, and available as an official backport for 16.04 LTS and later. Backports are enabled by default, but if you customized apt sources you might need to enable them manually.

  • Install the package:
sudo apt-get install cockpit

Debian

Cockpit is included in Debian unstable and in backports for 9 (Stretch).

  • For Debian 9 you have to enable the backports repository:
echo 'deb http://deb.debian.org/debian stretch-backports main' >> /etc/apt/sources.list.d/backports.list
apt-get update
  • Install the package:
sudo apt-get install cockpit

Fedora

Cockpit comes installed by default in Fedora Server.

To install Cockpit on other variants of Fedora use the following commands. For the latest versions use COPR.

  • Install cockpit:
sudo dnf install cockpit
  • Enable cockpit:
sudo systemctl enable --now cockpit.socket
  • Open the firewall if necessary:
sudo firewall-cmd --add-service=cockpit
sudo firewall-cmd --add-service=cockpit --permanent

Red Hat Enterprise Linux

Cockpit is included in Red Hat Enterprise Linux 7 and later.

  • On RHEL 7, enable the Extras repository.
sudo subscription-manager repos --enable rhel-7-server-extras-rpms
RHEL 8 does not need any non-default repositories.
  • Install cockpit:
sudo yum install cockpit
  • Enable cockpit:
sudo systemctl enable --now cockpit.socket
  • On RHEL 7, or if you use non-default zones on RHEL 8, open the firewall:
sudo firewall-cmd --add-service=cockpit
sudo firewall-cmd --add-service=cockpit --permanent

Project Atomic

Connect to an Atomic Host from another instance of Cockpit with the Add Server dashboard UI.

Alternatively you can access Cockpit directly on the Atomic Host if SSH password authentication is enabled:

  • Run the Cockpit web service container:
sudo atomic install cockpit/ws
sudo atomic run cockpit/ws

Clear Linux

Cockpit is in Clear Linux OS and can be installed using swupd:

sudo swupd bundle-add sysadmin-remote
sudo systemctl enable --now cockpit.socket

Arch Linux

Cockpit can be found in the Arch Community Repository as package cockpit.

使用

访问 Server

安装成功后,浏览器打开地址: https://ip-address-of-machine:9090 ,使用系统用户帐号/密码登录 Cockpit。Cookpit 默认启用自定义签名证书,浏览器会提示 SSL 认证警告,忽略即可,在 chrome/chromium 中,点击高级 (Show Advanced), 然后点击 继续前往 ip-address-of-machine (不安全)。

如果是基于127.0.0.0/8的HTTP访问,Cockpit 允许直接访问而不会重定向到HTTPS。

增加/删除 Server

Cockpit 首页,点击仪表盘>+按钮,在弹出的 添加主机到仪表盘 窗口输入要添加的主机 ip或域名地址;如果主机 SSH 端口是默认的 22则地址栏直接输入 ip或域名地址;如果不是 ,地址栏输入 ip:port

screenshot-dashboard-addserver

若要从列表中删除服务器,单击选中(√)图标,然后单击红色垃圾桶图标。

部分界面

  • 登录

login-reuse-password-checked

  • Shell

screenshot-shell

  • 存储

screenshot-storage

  • 网络

screenshot-network

备忘

Ubuntu 下安装/升级 Cockpit

选择阿里云安装源,手工编辑安装源文件或者在图形界面选择:

# 手工编辑安装源文件
vi /etc/apt/sources.list

安装源修改为阿里云:

# 阿里云
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
# 首先查看安装源与版本,然后确定使用那个安装源安装哪个包
apt policy cockpit*

# 如果安装了旧的版本,可以先卸载cockpit和依赖包,再执行安装命令
sudo apt-get remove --auto-remove cockpit

# 安装命令
sudo apt-get update
sudo apt-get install cockpit
sudo apt-get install cockpit-storaged
sudo apt-get install cockpit-docker
sudo apt-get install cockpit-system
sudo apt-get install cockpit-machines
sudo apt-get install cockpit-pcp
sudo apt-get install cockpit-bridge
sudo apt-get install cockpit-packagekit
sudo apt-get install cockpit-networkmanager
sudo apt-get install cockpit-dashboard
sudo apt-get install cockpit-doc

# 升级命令
sudo apt-get update
sudo apt-get upgrade cockpit
sudo apt-get upgrade cockpit-pcp cockpit-bridge  cockpit-packagekit
sudo apt-get upgrade cockpit-machines cockpit-storaged cockpit-docker
sudo apt-get upgrade cockpit-networkmanager

# 清理不需要的包
sudo apt autoremove

从 bionic-backports 安装 Cockpit

sudo apt-get update
  • 指定从 bionic-backports 安装包
# 如果版本比较旧的话,可以从 bionic-backports 安装较新版本
sudo apt-get install cockpit/bionic-backports
sudo apt-get install cockpit-storaged/bionic-backports
sudo apt-get install cockpit-docker/bionic-backports
sudo apt-get install cockpit-system/bionic-backports
sudo apt-get install cockpit-machines/bionic-backports
sudo apt-get install cockpit-pcp/bionic-backports
sudo apt-get install cockpit-bridge/bionic-backports
sudo apt-get install cockpit-packagekit/bionic-backports
sudo apt-get install cockpit-networkmanager/bionic-backports
sudo apt-get install cockpit-dashboard/bionic-backports
sudo apt-get install cockpit-doc/bionic-backports
  • 同时从 bionic-backports 安装包和依赖
sudo apt-get install -t bionic-backports cockpit
sudo apt-get install -t cockpit-storaged/bionic-backports
  • 从 bionic-backports 安装其他 cockpit 包和依赖
sudo apt-get install -t bionic-backports cockpit cockpit-docker cockpit-storaged cockpit-networkmanager cockpit-packagekit  cockpit-dashboard cockpit-bridge 

从 bionic backports 升级 Cockpit

某种情况下,Cockpit 总是停留再164.1版本,下面的命令可升级到最新版本。 查看 bionic-backports 中 Cockpit 版本地址:https://packages.ubuntu.com/bionic-backports/cockpit

sudo apt-get upgrade -t bionic-backports cockpit

同时从bionic-backports 升级其他安装包和依赖

sudo apt-get upgrade -t bionic-backports cockpit-pcp cockpit-machines cockpit-storaged
sudo apt-get upgrade -t bionic-backports cockpit-doc cockpit-docker cockpit-packagekit

从 trusty-backports 安装

针对低版本,例如 Ubuntu 16.04 下安装 Cockpit,不过 trusty-backports 中的版本似乎停留再 178.1 ,不更新了?

vi /etc/apt/sources.list

加入trusty-backports 安装源:

deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse

执行命令

sudo apt-get update
# 安装 Cockpit
sudo apt-get install -t trusty-backports cockpit
# 安装 Cockpit 其他包
sudo apt-get install -t trusty-backports cockpit cockpit-docker cockpit-storaged cockpit-networkmanager cockpit-packagekit  cockpit-dashboard cockpit-bridge 

从 trusty backports 升级

# 升级 Cockpit
sudo apt-get upgrade -t trusty-backports cockpit
# 升级 Cockpit 其他包
sudo apt-get upgrade -t trusty-backports cockpit-pcp cockpit-machines cockpit-storaged
sudo apt-get upgrade -t trusty-backports cockpit-doc cockpit-docker cockpit-packagekit

卸载

sudo systemctl stop cockpit
# 仅卸载 cockpit
sudo apt-get remove cockpit
# 卸载 cockpit 和相关依赖
sudo apt-get remove --auto-remove cockpit
# 完全卸载,包括清理配置数据
sudo apt-get purge cockpit
sudo apt-get purge --auto-remove cockpit
# 清理
sudo apt-get autoremove

Cockpit Service 管理

sudo systemctl daemon-reload
sudo systemctl enable cockpit.service cockpit.socket
sudo systemctl disable cockpit.service cockpit.socket
sudo systemctl start cockpit
sudo systemctl stop cockpit.service cockpit.socket
sudo systemctl status cockpit
sudo systemctl restart cockpit

Ubuntu 16.04 cannot refresh cache whilst offline

参考 https://github.com/cockpit-project/cockpit/issues/8477

Cockpit 中执行软件更新时,提示 cannot refresh cache whilst offline

首先,执行命令

sudo systemctl stop NetworkManager.service

软件更新完成后:

sudo systemctl start NetworkManager.service
慢读 慢生活

Slow Rhythm of Life.