# linux 运维

* [linux 运维](#linux-运维)
  * [企业内协作工作平台搭建](#企业内协作工作平台搭建)
    * [用到的工具与平台](#用到的工具与平台)
    * [cockpit 安装](#cockpit-安装)
    * [dzzoffice安装](#dzzoffice安装)
    * [sonarqube安装](#sonarqube安装)
      * [soanr的使用](#soanr的使用)
    * [其他私有云平台](#其他私有云平台)
  * [Ansible](#ansible)
  * [web console 网页终端工具](#web-console-网页终端工具)
    * [Cockpit Admin Console](#cockpit-admin-console)
    * [rtty](#rtty)
  * [代码/程序 相关](#代码程序-相关)
    * [数据库版本管理，表结构变化管理](#数据库版本管理表结构变化管理)
      * [flyway](#flyway)
    * [简易灰度部署项目脚本 不使用jenkins的纯shell方式](#简易灰度部署项目脚本-不使用jenkins的纯shell方式)
    * [代码性能调优工具 监控 xrebel](#代码性能调优工具-监控-xrebel)
    * [java代码诊断工具/代码debug工具 Arthas](#java代码诊断工具代码debug工具-arthas)
      * [athas技巧](#athas技巧)
    * [maven项目增加编译版本号](#maven项目增加编译版本号)
    * [可视化辅助工具](#可视化辅助工具)
      * [ES](#es)
      * [Redis](#redis)

## 企业内协作工作平台搭建

### 用到的工具与平台

* [Cockpit](https://cockpit-project.org/) web端的机器管理，除了监控机器运行状态还可以管理docker镜像，最重要是带有web终端工具
* [dzzoffice](http://www.dzzoffice.com) 一个开源的办公平台，带有网盘功能和其他各类可安装的插件、支持在线文档编辑和预览，支持任务版(类似trello)
* [sonarqube](https://www.sonarqube.org) 代码质量管理平台

### cockpit 安装

官网：<https://cockpit-project.org>

使用默认配置安装非常简单，以centos为例：<https://cockpit-project.org/running.html#centos\\>
安装后访问地址：`https://ip-address-of-machine:9090`

```bash
#安装
sudo yum install cockpit
# 启用
sudo systemctl enable --now cockpit.socket
# 如果启用了防火墙，则放行改服务
sudo firewall-cmd --permanent --zone=public --add-service=cockpit
sudo firewall-cmd --reload
```

详细配置：<https://cockpit-project.org/guide/latest/>

### dzzoffice安装

官网：<http://www.dzzoffice.com>

dzzoffice是一个php的web项目，使用mysql存储。php的环境部署较为麻烦，这里我制作了docker版的\
参考：<https://github.com/othorizon/Dockerfiles/blob/master/dzzoffice/install.md\\>
安装步骤

```bash
#安装mysql
## 端口可以暴露出来也可以做成封闭环境，看情况
docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7

#安装dzz
## 这里使用了link的方式连接mysql服务，其实更推荐使用network的方式好扩展管理，这里就使用link从简了
docker run --name dzzoffice --link mysql:mysql -d -p 8080:80 -v /workspacec/dzz/dzz_data/:/var/www/html/data/attachment/dzz itrizon/dzzoffice

## php的docker镜像的默认用户为www-data,因此如果挂载了外部目录需要进入容器重新授权一下
docker exec -i dzzoffice chown -R www-data:www-data /var/www/html/config /var/www/html/data

# 打开网页后按照安装步骤安装就好了
```

**支持office在线预览与编辑** [office文档编辑预览方案 - DzzOffice](http://dzz.cc/corpus/list?cid=3) dzzoffice支持多种office的预览与编辑方式，可以在dzz的应用商店安装,如果你的服务器是内部的无法被外网的office预览api访问你的文件，那么就只能安装自己的office预览服务了。\
文档预览服务也有很多选择，这里以dzz支持的onlyoffice为例，使用docker安装\
~~`docker run --name onlyoffice -itd -p 9011:80 dzzoffice/onlyoffice`~~\
`docker run --name onlyoffice -itd -p 9011:80 onlyoffice/documentserver`\
然后在dzz中的onlyoffice应用中配置serverUrl地址就好了：`http://[可访问的外部ip]:9011/web-apps/apps/api/documents/api.js`\
\&#xNAN;*要注意的就是这里的ip地址必须是你的本地浏览器客户端可以访问到的ip，而不是服务器内部地址*

**2022-03-23 更新，网上的安装版本**

```
sudo docker pull mysql:5.7.27 # 拉取数据库镜像

sudo docker run -d --name mysql -p 3308:3306 -e MYSQL_ROOT_PASSWORD=数据库密码 mysql:5.7.27 # 启动mysql数据库，由于该服务器还有其他数据库应用所有端口做了调整

sudo docker pull imdevops/dzzoffice # 拉取dxxoffice镜像

sudo docker run -d --name dzzoffice -p 88:80 imdevops/dzzoffice:latest # 启动应用设置端口

sudo docker pull onlyoffice/documentserver # 拉取onlyoffice镜像

sudo docker run -i -t -d -p 9000:80 onlyoffice/documentserver # 启动应用设置端口

阿里云服务器添加放行端口88、3308、9000

http://阿里云服务器IP:88/install/index.php # 进去配置页面进行初始化配置

refer: https://zhuanlan.zhihu.com/p/449358523
```

### sonarqube安装

官网：<https://www.sonarqube.org\\>
官网-文档：<https://docs.sonarqube.org/latest\\>
官网-插件文档：<https://docs.sonarqube.org/display/PLUG>

sonar有很多版本，也提供了免费的社区办(Community Edition),官方提供了下载版的安装和docker般的，以docker为例\
docker版官网：<https://hub.docker.com/\\_/sonarqube/>

```bash
#sonar可以选择使用mysql数据库，如果不配置数据库则会使用内置的H2数据库
$ docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7
## 登录mysql创建sonar的数据库 "sonar"
## mysql数据库连接sonar要求加上的"useUnicode=true\&characterEncoding=utf8"
$ docker run -d --name sonarqube \
    --link mysql:mysql \
    -p 9000:9000 \
    -e sonar.jdbc.username=root \
    -e sonar.jdbc.password=root \
    -e sonar.jdbc.url=jdbc:mysql://mysql/sonar?useUnicode=true\&characterEncoding=utf8\&useSSL=false \
    sonarqube
```

#### soanr的使用

登录后创建一个项目，会提示如何操作。\
示例

```bash
mvn sonar:sonar \
  -Dsonar.links.homepage=http://code-home-page.com \
  -Dsonar.links.scm=http://code-git.com/project.git \
  -Dsonar.projectKey=sonar_project_name \
  -Dsonar.host.url=http://192.168.1.1:9000 \
  -Dsonar.login=[token]
```

**支持单元测试覆盖率** 采用jacoco的插件，参考：<https://docs.sonarqube.org/display/PLUG/Usage+of+JaCoCo+with+SonarJava\\>
在执行分析之前，先执行jacoco的插件 `mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install -Dmaven.test.failure.ignore=false` 然后在执行分析就好了

### 其他私有云平台

* nextcloud
* [Seafile - 开源的企业私有网盘 私有云存储软件](https://www.seafile.com/home/)
* [小z文件管理系统](https://doc.xiaoz.me/#/zdir/)

## Ansible

[Ansible的安装和全面介绍 - 直到世界的尽头 - CSDN博客](https://blog.csdn.net/zzq900503/article/details/80158767)

## web console 网页终端工具

### Cockpit Admin Console

<https://cockpit-project.org/>

web端的shell终端工具，不仅是shell终端，而且带有丰富的运维功能，容器管理等等

### rtty

rtty由服务端和客户端两部分 服务端： <https://github.com/zhaojh329/rttys\\>
客户端： <https://github.com/zhaojh329/rtty>

服务端可以通过网页访问，会有客户端列表页面，来统一管理和登录客户端。

***

## 代码/程序 相关

### 数据库版本管理，表结构变化管理

Liquibase: [Flyway对比Liquibase - WillPan1234的博客 - CSDN博客](https://blog.csdn.net/WillPan1234/article/details/80509861)

#### flyway

[SpringBoot系列: 使用 flyway 管理数据库版本 - harrychinese - 博客园](https://www.cnblogs.com/harrychinese/p/springboot_flyway.html)

通过在数据库中创建一张表来维护sql文件的版本。 支持多实例部署，flyway使用数据库锁机制来协调多个节点的情况，从而保证可以集群部署。 flyway 不好理解的参数：

```yml
flyway:
  # schema中 已经有了表但是没有flyway_schema_history表的话,baselineOnMigrate 为true 时自动创建一个baseline，版本等于以及低于baselineVersion的将不会被执行
  baselineOnMigrate: true
  baselineVersion: 2019.08.28.1

  # 为true时 每次执行会检查已经合并过的sql文件是否发生了变动，如果变动了则会报错
  validate-on-migrate: true
```

参考： [Flyway学习笔记](https://blog.csdn.net/tanghin/article/details/51264795)

### 简易灰度部署项目脚本 不使用jenkins的纯shell方式

[linux/project\_deploy\_sh](/linux/project_deploy_sh.md)

### 代码性能调优工具 监控 xrebel

xrebel通过配置javaagent实现，对代码无侵入，支持web console\
[XRebel](https://jrebel.com/software/xrebel/quick-start)

### java代码诊断工具/代码debug工具 Arthas

Arthas 是Alibaba开源的Java诊断工具，深受开发者喜爱。\
Arthas支持web console。\
[alibaba/arthas](https://github.com/alibaba/arthas)\
[Arthas 用户文档 — Arthas 3.1.1 文档](https://alibaba.github.io/arthas/index.html)

#### athas技巧

[Alibaba Arthas实践--获取到Spring Context，然后为所欲为 · Issue #482 · alibaba/arthas](https://github.com/alibaba/arthas/issues/482)

### maven项目增加编译版本号

[maven/buildnumber-maven-plugin](/maven/buildnumber-maven-plugin.md)

### 可视化辅助工具

#### ES

**kibanna** 只能绑定一个es

**ElasticHD** 查询很难用 不推荐 [360EntSecGroup-Skylar/ElasticHD](https://github.com/360EntSecGroup-Skylar/ElasticHD)

**elasticsearch-head** 查询很难用 不推荐 es可视化web端，输入es的http地址既可以连接，相比笨重的kibana可以随意切换es源 [mobz/elasticsearch-head](https://github.com/mobz/elasticsearch-head)\
[ElasticSearch Head](http://mobz.github.io/elasticsearch-head/)

#### Redis

redis web可视化工具，支持docker [erikdubbelboer/phpRedisAdmin](https://github.com/ErikDubbelboer/phpRedisAdmin)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://book.rizon.top/linux/yun-wei.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
