欢迎光临范阳布衣的运维博客
分享工作和学习中的知识、技术

OpsManage安装

软件开源地址

https://github.com/welliamcao/OpsManage

安装所需包

yum install -y 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 

mkdir /software
cd !$

安装easy_install

cd /software
wget --no-check-certificate  https://pypi.python.org/packages/f7/94/eee867605a99ac113c4108534ad7c292ed48bf1d06dfe7b63daa51e49987/setuptools-28.0.0.tar.gz#md5=9b23df90e1510c7353a5cf07873dcd22
tar -zxf setuptools-28.0.0.tar.gz
cd setuptools-28.0.0
python setup.py install

安装pip

cd /software
wget --no-check-certificate https://github.com/pypa/pip/archive/1.5.5.tar.gz -O pip-1.5.5.tar.gz
tar -zxf pip-1.5.5.tar.gz
cd pip-1.5.5
python setup.py install
pip install -U pip      #升级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

安装redis

cd /software/
wget http://download.redis.io/releases/redis-3.2.8.tar.gz
tar -zxf 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 127.0.0.1 xxx.xxx.xxx.xxx(服务器IP)

启动Redis

cd ..
mv redis-3.2.8 /usr/local/redis
/usr/local/redis/src/redis-server /usr/local/redis/redis.conf
netstat -lntup| grep 6379

安装配置mariadb

yum install mariadb-server mariadb
mysql -v

配置mariadb

#vim /etc/my.cnf
[mysql]
default-character-set = utf8
socket=/var/lib/mysql/mysql.sock

[mysqld]
socket=/var/lib/mysql/mysql.sock

启动mariadb

# systemctl start mariadb

创建数据库

# mysql -uroot -p         #初始密码为空,直接回车就行;或 grep "password" /var/log/mysqld.log 查看初始密码

MariaDB [(none)]> create database opsmanage DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
mysql> grant all privileges on opsmanage.* to root@'%' identified by '123456';
MariaDB [(none)]> grant all privileges on opsmanage.* to root@'192.9.201.%' identified by '123456';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> \q

必要时可以重启数据库

systemctl restart mariadb.service

配置opsmanage

# cd /mnt/OpsManage/OpsManage/

# vim settings.py         #做下面修改

BROKER_URL = 'redis://127.0.0.1:6379/4'          #修改成自己的配置,格式是redis://[:password]@host:port/db
REDSI_KWARGS_LPUSH = {"host":'127.0.0.1','port':6379,'db':4}         #修改成自己的配置

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
       },
}

DATABASES = {
    'default': {
        'ENGINE':'django.db.backends.mysql',
        'NAME':'opsmanage',
        'USER':'root',
        'PASSWORD':'123456',
        'HOST':'127.0.0.1',
        'PORT':'3306'
#         'ENGINE': 'django.db.backends.sqlite3',
#         'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),         #修改成自己的配置,这一步配置错误会导致django无法连接数据库
    }
}

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': ["/mnt/OpsManage/OpsManage/static/",'/mnt/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',
            ],
        },
    },
]

STATIC_URL = '/static/'
STATICFILES_DIRS = (
     '/mnt/OpsManage/OpsManage/static/',            #修改成自己的配置
    )

生成数据表与管理员账户

# cd /mnt/OpsManage/

# python manage.py makemigrations OpsManage

出错:

django.db.utils.OperationalError: (1045, "Access denied for user 'root'@'opsmanage' (using password: YES)")

解决:

# mysql -uroot -p
mysql> grant all privileges on *.* to root@'%' identified by '123456';
mysql> flush privileges;
mysql> \q

继续执行

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/
nohup python manage.py runserver 0.0.0.0:8000 &

后面关机后再打开Opsmanage:

cd /mnt/OpsManage/
/usr/local/redis/src/redis-server /usr/local/redis/redis.conf
nohup python manage.py runserver 0.0.0.0:8000 &

配置认证

# ssh-keygen -t  rsa          #生成密钥对
# ssh-copy-id -i ~/.ssh/id_rsa.pub  root@ipaddress        #拷贝公钥到指定服务器
例如我想发布代码到192.168.30.129上,我只需要在192.168.30.128上生成密钥对,并将公钥拷贝到129上的 authorized_keys 文件中即可
发布代码时,还需要注意指定服务器上有在项目配置中指定的部署目录,否则项目部署也会失败

配置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:

cd /mnt/OpsManage/
supervisord -c /etc/supervisord.conf
supervisorctl status            #要检查是否都是running状态

SQL审核

自行安装Inception与SQLadvisor,SQLadvisor可执行文件请放在OpsManage服务器/usr/bin/sqladvisor路径

未经允许不得转载:范阳布衣 » OpsManage安装