opsmanage 自动化运维管理平台

时间:2021-07-21 15:39:04

关闭防火墙、selinux

更换阿里云 yum源

依赖环境

yum install -y epel-release
yum install vim net-tools nmon htop rsync tree ntp iftop wget clamav -y

安装easy_install

cd /tools
[root@jason tools]# wget --no-check-certificate https://pypi.python.org/packages/f7/94/eee867605a99ac113c4108534ad7c292ed48bf1d06dfe7b63daa51e49987/setuptools-28.0.0.tar.gz#md5=9b23df90e1510c7353a5cf07873dcd22
[root@jason tools]# tar -xzvf setuptools-28.0.0.tar.gz
[root@jason tools]#cd setuptools-28.0.0
[root@jason tools]#python setup.py install

安装pip

# wget --no-check-certificate https://github.com/pypa/pip/archive/1.5.5.tar.gz -O pip-1.5.5.tar.gz
# tar -xzvf pip-1.5.5.tar.gz
# cd pip-1.5.5/
# python setup.py install
# pip install -U pip

安装模块

依赖环境

yum install -y mysql-devel python-devel

# cd /mnt/
# git clone https://github.com/welliamcao/OpsManage.git
# cd /mnt/OpsManage/
#vim requirements.txt
将Django版本改为1.8.17
# pip install -r requirements.txt
pip install paramiko

 

安装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 #128行

loglevel warning #158行
logfile "/var/log/redis.log" #163行
bind 你的服务器ip地址 #61行
例如: bind 127.0.0.1 192.168.88.201

opsmanage  自动化运维管理平台

# cd ../
# mv redis-3.2.8 /usr/local/redis
# /usr/local/redis/src/redis-server /usr/local/redis/redis.conf

开机自启

将/usr/local/redis/src/redis-server /usr/local/redis/redis.conf加入到/etc/rc.d/rc.local

安装mysql

配置文件添加

[root@jason ~]# cat /etc/my.cnf |grep -Ev '^%|^$'
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
character_set_server = utf8
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' ##添加
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at % of total RAM for dedicated server, else %.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

 创建数据库opsmanage ,并赋予全部权限

# 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 'jason_zhang';
mysql> FLUSH PRIVILEGES;

 配置OpsManage

[root@jason ~]# cd /mnt/OpsManage/
[root@jason OpsManage]# cd OpsManage/
[root@jason OpsManage]# cat settings.py |grep -Ev '^%|^$'
#!/usr/bin/env python
# _#_ coding:utf- _*_
"""
Django settings for OpsManage project.
Generated by 'django-admin startproject' using Django 1.9..
For more information on this file, see
https://docs.djangoproject.com/en/1.9/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
"""
import os
import djcelery
from celery import platforms
from kombu import Queue,Exchange
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
''' celery config '''
djcelery.setup_loader()
BROKER_URL = 'redis://192.168.199.224:6379/4' ##redis的IP、端口和库
CELERY_RESULT_BACKEND = 'djcelery.backends.database.DatabaseBackend'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TASK_SERIALIZER='pickle'
CELERY_ACCEPT_CONTENT = ['pickle','json']
CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler'
CELERY_TASK_RESULT_EXPIRES = * *
CELERYD_MAX_TASKS_PER_CHILD =
CELERY_TRACK_STARTED = True
CELERY_ENABLE_UTC = False
CELERY_TIMEZONE='Asia/Shanghai'
platforms.C_FORCE_ROOT = True
#celery route config
CELERY_IMPORTS = ("OpsManage.tasks.assets","OpsManage.tasks.ansible",
"OpsManage.tasks.cron","OpsManage.tasks.deploy",
"OpsManage.tasks.sql","OpsManage.tasks.sched")
CELERY_QUEUES = (
Queue('default',Exchange('default'),routing_key='default'),
Queue('ansible',Exchange('ansible'),routing_key='ansible'),
)
CELERY_ROUTES = {
'OpsManage.tasks.sql.*':{'queue':'default','routing_key':'default'},
'OpsManage.tasks.assets.*':{'queue':'default','routing_key':'default'},
'OpsManage.tasks.cron.*':{'queue':'default','routing_key':'default'},
'OpsManage.tasks.sched.*':{'queue':'default','routing_key':'default'},
'OpsManage.tasks.ansible.AnsibleScripts':{'queue':'ansible','routing_key':'ansible'},
'OpsManage.tasks.ansible.AnsiblePlayBook':{'queue':'ansible','routing_key':'ansible'},
}
CELERY_DEFAULT_QUEUE = 'default'
CELERY_DEFAULT_EXCHANGE_TYPE = 'topic'
CELERY_DEFAULT_ROUTING_KEY = 'default'
REDSI_KWARGS_LPUSH = {"host":'192.168.199.224','port':6379,'db':4}
REDSI_LPUSH_POOL = None
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'kd8f&jx1h^1m-uldfdo3d#10d9mbc-ijjz!tozusy@aw#h+875'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['*']
# Channels settings
CHANNEL_LAYERS = {
"default": {
"BACKEND": "asgi_redis.RedisChannelLayer", # use redis backend
"CONFIG": {
"hosts": [("localhost", )],
"channel_capacity": {
"http.request": ,
"websocket.send*": ,
},
"capacity": ,
},
"ROUTING": "OpsManage.routing.channel_routing", # load routing from our routing.py file
},
}
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'OpsManage',
'rest_framework',
'djcelery',
'channels',
'storages',
'wiki',
'orders',
'api',
'filemanage',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
# 'django.middleware.csrf.CsrfResponseMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.BasicAuthentication',
),
}
ROOT_URLCONF = 'OpsManage.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ["/mnt/OpsManage/OpsManage/static/",'/mnt/OpsManage/OpsManage/templates/'], ##根据下载的opsmanage存放位置
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'OpsManage.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE':'django.db.backends.mysql',
'NAME':'opsmanage',
'USER':'root',
'PASSWORD':'jason_zhang',
'HOST':'192.168.199.224'
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.9/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Asia/Shanghai'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
'/mnt/OpsManage/OpsManage/static/',
)
MEDIA_ROOT = os.path.join(BASE_DIR,'upload/')
MEDIA_URL = '/upload/'
SFTP_CONF = {
'port':,
'username':'root',
'password':'welliam',
'timeout':
}
WORKSPACES = '/var/lib/opsmanage/workspaces/'
LOGIN_URL = '/login'

生成数据表与管理员账户

yum remove python-gssapi.x86_64    不然会django、Paramiko报错 

# cd /mnt/OpsManage/
# python manage.py makemigrations OpsManage
# python manage.py makemigrations wiki
# python manage.py makemigrations orders
# python manage.py makemigrations filemanage
# python manage.py migrate
# python manage.py createsuperuser

启动部署平台

# cd /mnt/OpsManage/
# python manage.py runserver 0.0.0.0:8000

 opsmanage  自动化运维管理平台

注意,启动后,会占用当前终端,需要调整时开启新终端登录

http://192.168.199.224:8000

opsmanage  自动化运维管理平台 

配置Celery异步任务系统

celery-分布式异步任务调度系统

了解:https://blog.csdn.net/bojie5744/article/details/52965668

# echo_supervisord_conf > /etc/supervisord.conf
# export PYTHONOPTIMIZE=1
# vim /etc/supervisord.conf

 在最后面加上

[program:celery-worker-default]
command=/usr/bin/python manage.py celery worker --loglevel=info -E -Q default
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]
command=/usr/bin/python manage.py celery worker --loglevel=info -E -Q ansible
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]
command=/usr/bin/python manage.py celery beat
directory=/mnt/OpsManage
stdout_logfile=/var/log/celery-beat.log
autostart=true
autorestart=true
redirect_stderr=true
stopsignal=QUIT
numprocs=1 [program:celery-cam]
command=/usr/bin/python manage.py celerycam
directory=/mnt/OpsManage
stdout_logfile=/var/log/celery-celerycam.log
autostart=true
autorestart=true
redirect_stderr=true
stopsignal=QUIT
numprocs=1

 启动celery

# /usr/bin/supervisord -c /etc/supervisord.conf    #注意centos7上路径
# supervisorctl status #要检查是否都是running状态

 opsmanage  自动化运维管理平台opsmanage  自动化运维管理平台

 

SQL审核

自行安装Inception与SQLadvisor,SQLadvisor可执行文件请放在OpsManage服务器/usr/bin/sqladvisor路径 (不支持阿里云RDS)
详看inception+archery SQL审核平台 https://www.cnblogs.com/xiaoyou2018/p/9936585.html 参考:http://blog.51cto.com/11555417/2155028
https://github.com/welliamcao/OpsManage
https://www.oschina.net/p/opsmanage

Python 进程管理工具 Supervisor 使用教程
https://www.restran.net/2015/10/04/supervisord-tutorial/