前言
- 自动化运维管理工具OpsManagerhttp://mp.weixin.qq.com/s?__biz=Mzk0NTQ3OTk3MQ==&mid=2247487736&idx=1&sn=efef3a930b88649033f61942a77f42d2&chksm=c31598b4f46211a240ffc5360ae238b27d0f495fcbe8dc18abdbd79bc25c00726f74a7312dd0&scene=21#wechat_redirect
环境
-
OS:Rocky Linux 9.3
-
docker-ce-26.1.1
-
docker-compose v2.27.0
-
OpsManage v3.0.5
配置docker
参考:
Docker学习入门http://mp.weixin.qq.com/s?__biz=Mzk0NTQ3OTk3MQ==&mid=2247486316&idx=1&sn=9d3413d38adc8ccce13aacf5c45d68ea&chksm=c3158320f4620a36ef3cfd482f32f5ba2eebac8dc4a612408f203f66ee507d21bb7f3586be7c&scene=21#wechat_redirect
安装docker
# 安装基础包,添加docker源
dnf install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/rhel/docker-ce.repo# 安装docker-ce
dnf install -y docker-ce# 启动docker服务并配置自启及查看状态
systemctl enable docker --now && systemctl status docker
安装docker-compose
GitHub下载:https://github.com/docker/compose/releases
备用地址:https://pan.baidu.com/s/12EkNfgGBcz8OivFIdZF4VA?pwd=ch60
# 下载docker-compose并添加执行权限
curl -L https://github.com/docker/compose/releases/download/v2.27.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose# 检查版本
docker-compose -v
添加图片注释,不超过 140 字(可选)
配置OpsManage
获取代码
GitHub下载:https://github.com/welliamcao/OpsManage/releases 备用地址:https://pan.baidu.com/s/11vNzwO6P5zLD7CzT-FZTsQ?pwd=plcj
构建镜像
# 下载
curl -L https://github.com/welliamcao/OpsManage/archive/refs/tags/v3.0.5.tar.gz -o /opt/OpsManage.tar.gz
# 解压并改名
cd /opt
tar xzvf OpsManage-3.0.5.tar.gz
mv OpsManage-3.0.5/ OpsManage# 构建基础镜像
cd OpsManage/ && sh docker/build.sh
修改配置文件conf/opsmanage.ini
-
host
-
user
-
password
[db]
engine = mysql
host = 192.168.199.152
port = 3306
user = root
password = Linuxjsz
database = opsmanage
[redis]
#ansible实时输出数据
host = 127.0.0.1
port = 6379
password = Linuxjsz
ansible_db = 3
celery_db = 4
default_db = 0
[amqp]
#celery消息队列中间件
host = 127.0.0.1
port = 5672
user = guest
password = guest
[deploy]
path = /var/lib/opsmanage/workspaces/
[ldap]
#启动ldap认证没有可以设置为false
enable = false
server = 192.168.10.128
port = 389
bind_dn = cn=root,dc=opsmanage,dc=com
bind_password = 123456
search_dn = ou=People,dc=opsmanage,dc=com
filter = OpenLDAP
[inception]
#SQL审核工具没有可以设置为false
enable = false
host = 192.168.1.233
port = 6669
backup_host = 192.168.1.201
backup_passwd = Linuxjsz
backup_user = root
backup_port = 3306
[email]
#发送邮箱
smtp_account = test@163.com
smtp_host = smtp.163.com
smtp_passwd = Linuxjszx12
[apply]
max_task = 10
max_expire_sec = 3600
修改配置文件docker/docker-compose.yml
-
将opsmanage.ini和docker-compose.yml文件中相关密码配置一致。
-
MYSQL_USER
-
MYSQL_PASSWORD
-
MYSQL_ROOT_PASSWORD
sed -ri 's@/mnt/@/opt/@' /opt/OpsManage/docker/docker-compose.yml
sed -ri 's@- /data/apps/@- /opt/OpsManage/@' /opt/OpsManage/docker/docker-compose.yml
cat /opt/OpsManage/docker/docker-compose.yml
#version: "3"
services:db:container_name: dbimage: mysql:5.6ports:- "3306:3306"environment:- MYSQL_HOST=localhost- MYSQL_DATABASE=opsmanage- MYSQL_USER=opsmanage- MYSQL_PASSWORD=Linuxjsz- MYSQL_ROOT_PASSWORD=Linuxjszvolumes:- /opt/OpsManage/mysql:/var/lib/mysqlrestart: alwaysnetworks:- defaultredis:container_name: redisimage: redis:3.2.8command: redis-serverports:- "6379:6379"volumes:- /opt/OpsManage/redis:/data/redisnetworks:- defaultrabbitmq:container_name: rabbitmqimage: rabbitmq:managementports:- "5672:5672"- "15672:15672"networks:- defaultops_web:image: opsmanage-base:latestcontainer_name: ops_webenvironment:MYSQL_DATABASE: opsmanageMYSQL_USER: "opsmanage"MYSQL_PASSWORD: "Linuxjsz"ports:- "8000:8000" #vim /opt/OpsManage/OpsManage/settings.py文件里面的DEBUG设置为DEBUG = Truevolumes:- /opt/OpsManage:/data/apps/opsmanage- /opt/OpsManage/upload:/data/apps/opsmanage/upload- /opt/OpsManage/logs:/data/apps/opsmanage/logscommand: bash /data/apps/opsmanage/docker/start.shlinks:- db- redis- rabbitmqdepends_on:- db- redis- rabbitmqrestart: alwaysnetworks:- default
# nginx:
# image: opsmanage-nginx
# container_name: nginx
# ports:
# - "80:80"
# volumes:
# - /opt/OpsManage/static:/usr/share/nginx/html/static
# depends_on:
# - ops_web
# links:
# - ops_web:ops_web
# networks:
# - default
networks:default:
(可选)修改Django配置文件OpsManage/setting.py
-
需要使用Django来访问静态文件时需要修改DEBUG = True(Django仅在调试模式下能对外提供静态文件访问)
(可选)构建静态文件镜像
cd /opt/OpsManage
docker build -t opsmanage-static -f docker/Dockerfile-static .
部署服务
cd /opt/OpsManage/docker/
docker-compose up -d
查看docker状态
docker ps -a
cd /opt/OpsManage/docker/
docker-compose stats
创建Web管理员
docker exec -it ops_web bash
python3 manage.py createsuperuser
访问Web
-
http://ip:8000
-
登录信息为上面创建的账号密码
单独部署服务
启动redis服务
cd /opt/OpsManage/docker/
docker-compose up -d redis
查看日志
docker-compose logs -f
启动db服务
docker-compose up -d db
查看日志,会有几次重启过程。
docker-compose logs -f
启动rabbitmq服务
docker-compose up -d rabbitmq
查看日志
docker-compose logs -f
启动ops_web服务
docker-compose up -d ops_web
查看日志
docker-compose logs -f
异常处理
查看ops_web服务启动日志及访问Web报错
访问web显示,报错原因为数据不匹配导致。
重建数据库(密码为前面配置文件设置好的)
docker exec -it db bashmysql -uroot -pdrop database opsmanage;create database opsmanage;flush privileges;mysql> exitroot@96c2940efa5b:/# exit
初始化数据库
docker exec -it ops_web bashpython3 manage.py makemigrations account
python3 manage.py makemigrations wiki
python3 manage.py makemigrations orders
python3 manage.py makemigrations navbar
python3 manage.py makemigrations databases
python3 manage.py makemigrations asset
python3 manage.py makemigrations deploy
python3 manage.py makemigrations cicd
python3 manage.py makemigrations sched
python3 manage.py makemigrations apply
python3 manage.py migrate
好了,本次部署就到这里了,登陆后测试了一下,还是不错的,但试了一下左下角3个功能无反应,具体待后续排查。
来自: OpsManage基于docker的部署与使用https://mp.weixin.qq.com/s?__biz=Mzk0NTQ3OTk3MQ==&mid=2247487794&idx=1&sn=e60615c882cd0fc428a8129c6b75dfb8&chksm=c315997ef46210683775c202b36a7b72fc5521a0bd979c69a6b2b6818632b5da374e1c3bb715&token=113329682&lang=zh_CN#rd