OpsManage是什么?
一款代码部署、应用部署、计划任务、设备资产管理平台。
开源协议:GNU General Public License v2
开源声明:欢迎大家star或者fork我的开源项目,如果大家在自己的项目里面需要引用该项目代码,请在项目里面申明协议和版权信息。
开发语言与框架:
- 编程语言:Python3.6 + HTML + JScripts
- 前端Web框架:Bootstrap
- 后端Web框架:Django
- 后端Task框架:Celery + Redis
OpsManage环境要求
- 编程语言:Python 3.6
- 操作系统:CentOS 6+
- Ansible版本:2.6 +
- 部署平台及节点服务器:Rsync 3+
- MySQL版本:5.1-5.6 #如果用5.7请查看
OpsManage功能说明
安装环境配置
一、安装Python
# yum install epel-release -y
# yum install zlib zlib-devel readline-devel sqlite-devel bzip2-devel openssl-devel gdbm-devel libdbi-devel ncurses-libs kernel-devel libxslt-devel libffi-devel python-devel zlib-devel openldap-devel sshpass gcc git rabbitmq-server supervisor -y
# yum localinstall http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
# yum install mysql-community-server mysql-devel -y
# wget https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tgz #CentOS 7不用安装python2.7
# tar -xzvf Python-3.6.6.tgz
# cd Python-3.6.6
# ./configure --prefix=/usr/local/python3
# make all
# make install
# make clean
# make distclean
# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
二、安装模块
# cd /mnt/
# git clone -b v3 https://github.com/welliamcao/OpsManage.git
# cd /mnt/OpsManage/
# pip3 install -r requirements.txt #CentOS 7使用pip3
三、安装Redis
# wget http://download.redis.io/releases/redis-3.2.8.tar.gz
# tar -xzvf redis-3.2.8.tar.gz
# cd redis-3.2.8
# make
# make install
# vim redis.conf
修改以下配置(不要配置认证)
daemonize yes
loglevel warning
logfile "/var/log/redis.log"
bind 你的服务器ip地址
例如: bind 127.0.0.1 192.168.88.201
# cd ../
# mv redis-3.2.8 /usr/local/redis
# /usr/local/redis/src/redis-server /usr/local/redis/redis.conf
四、安装MySQL
# vim /etc/my.cnf
[mysqld]
character_set_server = utf8
添加以上字段
# /etc/init.d/mysqld restart #centos 6
# systemctl start mysqld.service #centos 7
# mysql -uroot -p #初始密码为空,直接回车就行
mysql> create database opsmanage DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
mysql> grant all privileges on opsmanage.* to root@'%' identified by 'password';
mysql>\q
五、配置RabbitMQ
# systemctl start rabbitmq-server.service #启动RabbitMQ
# systemctl enable rabbitmq-server.service #设置开机自启动RabbitMQ
# rabbitmqctl add_user admin admin #添加RabbitMQ账户
# rabbitmqctl set_user_tags admin administrator
# rabbitmqctl set_permissions -p '/' admin '.' '.' '.'
# rabbitmqctl list_users
# rabbitmqctl delete_user guest #删除guest账户(可以不删除)
# rabbitmq-plugins enable rabbitmq_management #开启Web UI,可以通过http://server_IP:15672/访问
六、配置OpsManage
# cd /mnt/OpsManage/conf
# vim opsmanage.ini
根据自己的情况修改配置
七、生成数据表与管理员账户
# cd /mnt/OpsManage/
# /usr/local/python3/bin/python3 manage.py makemigrations account
# /usr/local/python3/bin/python3 manage.py makemigrations wiki
# /usr/local/python3/bin/python3 manage.py makemigrations orders
# /usr/local/python3/bin/python3 manage.py makemigrations navbar
# /usr/local/python3/bin/python3 manage.py makemigrations databases
# /usr/local/python3/bin/python3 manage.py makemigrations asset
# /usr/local/python3/bin/python3 manage.py makemigrations deploy
# /usr/local/python3/bin/python3 manage.py makemigrations cicd
# /usr/local/python3/bin/python3 manage.py makemigrations sched
# /usr/local/python3/bin/python3 manage.py makemigrations apply
# /usr/local/python3/bin/python3 manage.py migrate
# /usr/local/python3/bin/python3 manage.py createsuperuser #创建管理员账户与密码
# 如果出现错误ImportError: cannot import name 'LDAPError'
pip3 uninstall python-ldap
pip3 install --upgrade python-ldap
八、启动部署平台
# echo_supervisord_conf > /etc/supervisord.conf
# export PYTHONOPTIMIZE=1
# vim /etc/supervisord.conf
最后添加,/var/log/celery-*.log这些是日志文件,如果有错误请注意查看,directory的值是代码路径
[program:celery-worker-default]
environment=C_FORCE_ROOT="true",PYTHONOPTIMIZE=1
command=/usr/local/python3/bin/celery -A OpsManage worker --loglevel=info -E -Q default -n worker-default@%%h
directory=/mnt/OpsManage
stdout_logfile=/var/log/celery-worker-default.log
autostart=true
autorestart=true
redirect_stderr=true
stopsignal=QUIT
numprocs=1
[program:celery-worker-ansible]
environment=C_FORCE_ROOT="true",PYTHONOPTIMIZE=1
command=/usr/local/python3/bin/celery -A OpsManage worker --loglevel=info -E -Q ansible -n worker-ansible@%%h
directory=/mnt/OpsManage
stdout_logfile=/var/log/celery-worker-ansible.log
autostart=true
autorestart=true
redirect_stderr=true
stopsignal=QUIT
numprocs=1
[program:celery-beat]
environment=C_FORCE_ROOT="true",PYTHONOPTIMIZE=1
command=/usr/local/python3/bin/celery -A OpsManage beat --loglevel=info --scheduler django_celery_beat.schedulers:DatabaseScheduler
directory=/mnt/OpsManage
stdout_logfile=/var/log/celery-beat.log
autostart=true
autorestart=true
redirect_stderr=true
stopsignal=QUIT
numprocs=1
[program:apply-task]
environment=C_FORCE_ROOT="true",PYTHONOPTIMIZE=1
command=/usr/local/python3/bin/python3 manage.py apply_task
directory=/mnt/OpsManage
stdout_logfile=/var/log/apply-task.log
autostart=true
autorestart=true
redirect_stderr=true
stopsignal=QUIT
numprocs=1
[program:opsmanage-web]
command=/usr/local/python3/bin/python3 manage.py runserver 0.0.0.0:8000 --http_timeout 1200
directory=/mnt/OpsManage
stdout_logfile=/var/log/opsmanage-web.log
stderr_logfile=/var/log/opsmanage-web-error.log
autostart=true
autorestart=true
redirect_stderr=true
stopsignal=QUIT
启动celery
# supervisord -c /etc/supervisord.conf
# supervisorctl status #要检查是否都是running状态,uptime是不是递增
配置nginx(请注意服务器上面是否安装了Nginx):
# vim /etc/nginx/conf.d/opsmanage.conf
server {
listen 80 ;
server_name 192.168.1.233; #192.168.1.233替换成自己服务器的IP地址
access_log /var/log/nginx/opsmanage_access.log;
error_log /var/log/nginx/opsmanage_error.log;
location / {
proxy_next_upstream off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://192.168.1.233:8000$request_uri; #192.168.1.233替换成自己服务器的IP地址
}
location /static/ {
expires 30d;
autoindex on;
add_header Cache-Control private;
alias /mnt/OpsManage/static/;
}
location /media/navbar/ {
expires 30d;
autoindex on;
add_header Cache-Control private;
alias /mnt/OpsManage/upload/navbar/;
}
location /media/avatar/ {
expires 30d;
autoindex on;
add_header Cache-Control private;
alias /mnt/OpsManage/upload/avatar/;
}
location /media/apply/icon/ {
expires 30d;
autoindex on;
add_header Cache-Control private;
alias /mnt/OpsManage/upload/apply/icon/;
}
}
# nginx -t #检查配置文件
# service start nginx #CentOS 6
# systemctl start nginx.service #CentOS 7
九、使用OpsManage分布式任务调度功能,不使用的话可以不进行下面的步骤
# mkdir -p /usr/local/opsched
# cp /mnt/OpsManage/opsched/* /usr/local/opsched/
# vim /usr/local/opsched/sched.conf
# 注意修改里面secret跟ops_address的值,修改成自己的配置
# /usr/local/opsched/opsched -f /usr/local/opsched/sched.conf -a check #检查配置看看有没有报错
# /usr/local/opsched/opsched -f /usr/local/opsched/sched.conf -a runserver #正式运行
十、demo地址
URL: http://42.194.214.22:8000/
UserName:demo
Password:demo
docker安装OpsManage
1、安装docker
# yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# yum install docker-ce docker-ce-cli containerd.io
# systemctl start docker
2、安装docker-compse
# sudo curl -L "https://github.com/docker/compose/releases/download/1.29.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
# ln -sf /usr/local/bin/docker-compose /usr/bin/docker-compose
3、下载代码
# mkdir /data/apps && cd /data/apps
# git clone -b v3 https://github.com/welliamcao/OpsManage.git
4、修改docker-compse.yaml
# cd /data/apps/OpsManage
# vim docker/docker-compse.yaml
version: "3.7"
services:
mysql:
image: mysql:5.7
container_name: mysql
environment:
- MYSQL_HOST=%
- MYSQL_DATABASE=opsmanage
- MYSQL_USER="数据库用户名" #自行修改
- MYSQL_PASSWORD="数据库用户密码" #自行修改
- MYSQL_ROOT_PASSWORD="数据库root密码" #自行修改
volumes:
- /data/apps/mysql:/var/lib/mysql
command: ['mysqld', '--sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION', '--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci']
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
timeout: 20s
retries: 10
restart: always
networks:
- default
redis:
container_name: redis
image: redis:3.2.8
command: /bin/sh -c "redis-server --requirepass $$REDIS_PASSWORD"
environment:
REDIS_PASSWORD: "密码" #自行修改
REDIS_AOF_ENABLED: "no"
ports:
- "6379:6379"
volumes:
- /data/apps/redis:/data
networks:
- default
rabbitmq:
container_name: rabbitmq
image: rabbitmq:management
environment:
RABBITMQ_DEFAULT_USER: admin #自行修改
RABBITMQ_DEFAULT_PASS: admin #自行修改
volumes:
- '/data/apps/rabbitmq/data/:/var/lib/rabbitmq/mnesia/'
ports:
- "5672:5672"
- "15672:15672"
networks:
- default
ops_web:
image: opsmanage-base:latest
container_name: ops_web
environment:
MYSQL_USER: root
MYSQL_DATABASE: opsmanage
MYSQL_PASSWORD: "数据库用户密码" #记得自己修改
ports:
- "8000:8000"
volumes:
- /data/apps/OpsManage:/data/apps/opsmanage
- /data/apps/OpsManage/upload:/data/apps/opsmanage/upload
- /data/apps/OpsManage/logs:/data/apps/opsmanage/logs
command: bash /data/apps/opsmanage/docker/start.sh
links:
- mysql
- redis
- rabbitmq
depends_on:
mysql:
condition: service_healthy
redis:
condition: service_started
rabbitmq:
condition: service_started
restart: always
networks:
- default
nginx:
image: nginx
container_name: nginx
ports:
- "80:80"
volumes:
- /data/apps/nginx/logs:/var/log/nginx
- /data/apps/OpsManage/docker/opsmanage.conf:/etc/nginx/conf.d/default.conf
- /data/apps/OpsManage/static:/data/apps/opsmanage/static
- /data/apps/OpsManage/upload:/data/apps/opsmanage/upload
depends_on:
- ops_web
links:
- ops_web:ops_web
networks:
- default
networks:
default:
5、构建基础镜像
# cd /data/apps/OpsManage
# docker build -t opsmanage-base -f docker/Dockerfile .
6、 修改应用配置文件conf/opsmanage.ini
# cd /data/apps/OpsManage
# vim conf/opsmanage.ini #把MySQL/Redis/RabbitMQ的host/password改成docker-compose里面配置的一致,host等于具体container_name
7、 启动OpsManage
# cd /data/apps/OpsManage/docker
# docker-compose up -d
8、访问页面
http://<ip>:80
User: admin
Password: admin