安装Python
由于我安装的事centos7的,所以不需要安装python2.7,直接按照下面的步骤来即可。
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 sshpass gcc git -y
mv /usr/bin/python /usr/bin/python2.6.6
ln -s /usr/local/bin/python2.7 /usr/bin/python
vi /usr/bin/yum
安装easy_install
wget --no-check-certificate https://pypi.python.org/packages/f7/94/eee867605a99ac113c4108534ad7c292ed48bf1d06dfe7b63daa51e49987/setuptools-28.0.0.tar.gz#md5=9b23df90e1510c7353a5cf07873dcd22
tar -xzvf setuptools-28.0.0.tar.gz
cd setuptools-28.0.0
python setup.py install
在执行python setup.py install有可能会出错,如下图所示:
问:为什么我上面已经执行定义了为啥还会报错?
解决方式:
由于部分系统原因可能导致这个问题,但是很好解决,只要输入前面mv改成python2.6.6既可以。
安装pip
tar -xzvf pip-1.5.5.tar.gz
cd pip-1.5.5/
python setup.py install
python2.6.6 setup.py install
pip install -U pip
安装模块
cd /mnt/
git clone https://github.com/welliamcao/OpsManage.git
cd /mnt/OpsManage/
pip install -r requirements.txt
easy_install paramiko==2.4.1
在执行pip install -r requirements.txt有可能回报以下错误:
错误1:
解决方式:
升级一下pip即可。
pip install --upgrade pip
问题2:
解决方式:
执行下面语句即可解决
yum install python-devel mysql-devel
安装redis
略
安装MySQL
略
my.cnf添加以下信息
[mysqld]
character_set_server = utf8
创建数据库
mysql> create database opsmanage DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
安装mysql脚本的时候可能会出现这种问题
Can't locate Data/Dumper.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at scripts/mysql_install_db line 42
只要执行这个命令即可
yum install 'perl(Data::Dumper)'
配置OpsManage
#######修改处23行###########
''' celery config '''
djcelery.setup_loader()
BROKER_URL = 'redis://127.0.0.1:6379/4' #改成自己的redis地址以及redis库
###########修改处60行#########
REDSI_KWARGS_LPUSH = {"host":'127.0.0.1','port':6379,'db':4} #改成对应的redis地址以及库
###########修改处75行#########
CHANNEL_LAYERS = {
"default": {
"BACKEND": "asgi_redis.RedisChannelLayer", # use redis backend
"CONFIG": {
"hosts": [("127.0.0.1", 6379)], #无密码方式
"channel_capacity": {
"http.request": 1000,
"websocket.send*": 10000,
},
"capacity": 10000,
},
"ROUTING": "OpsManage.routing.channel_routing", # load routing from our routing.py file
},
}
########修改处136行##########
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ["/alidata/OpsManage/OpsManage/static/",'/alidata/OpsManage/OpsManage/templates/'],
'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',
],
},
},
]
############修改处159行######
DATABASES = {
'default': {
'ENGINE':'django.db.backends.mysql',
'NAME':'opsmanage', #数据库名
'USER':'root', #数据库用户
'PASSWORD':'123456', #数据库密码
'HOST':'127.0.0.1', #数据库地址
'port':'3306' #要加mysql端口,默认是没有的,需要加上去
#######修改处183行#########
STATIC_URL = '/static/'
STATICFILES_DIRS = (
'/alidata/OpsManage/OpsManage/static/', #改成对应路径地址
)
####修改处191行##########
SFTP_CONF = {
'port':22,
'username':'root',
'password':'123456',
'timeout':30
} #修改成能sftp登陆OpsManage的账户
生成数据表与管理员账户
cd /alidata/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
配置证书认证
ssh-keygen -t rsa
ssh-copy-id -i ~/.ssh/id_rsa.pub root@ipaddress
配置Celery异步任务系统
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/local/bin/supervisord -c /etc/supervisord.conf
# supervisorctl status #要检查是否都是running状态
启动部署平台
# cd /alidata/OpsManage/
# python manage.py runserver 0.0.0.0:8000
访问登陆即可
邮件发送接收设置
在数据管理里——基础设置开启图下邮件通知即可。
然后全局设置那邮件设置为图下,密码为授权码。我用的是QQ,其余邮箱根据自行的授权码添加即可,就能再提交申请部署的时候收到邮件提醒。