1. Opsmanage介绍
OpsManage是一款进行设备资产、代码部署、应用部署、计划任务的管理平台,结合ansible进行自动化运维,可以在很大程度上解放运维工程师的双手。类似的运维平台还有腾讯的蓝鲸运维管理平台。
Git地址:/welliamcao/OpsManage/blob/master/README.md
2. OpsManage安装
安装准备
所需环境:编程语言:Python 2.7 操作系统:CentOS 6+Ansible版本:2.0 +部署平台及节点服务器:Rsync 3+MySQL版本:5.1-5.6
安装所需包
# 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 # yum install -y /downloads/percona-release/redhat/0.1-6/percona-release-0.1-6.noarch.rpm# yum install -y Percona-Server-server-56 install Percona-Server-devel-56# mkdir /software# cd !$
安装python
因为是CentOS7,所以这一步我省略了。
# wget /python/2.7.12/Python-2.7.12.tgz(Centos 7 不用安装python2.7,因为已经默认自带python2.7)# tar -zxf Python-2.7.12.tgz # cd Python-2.7.12# ./configure# make all# make install # make clean# make distclean# mv /usr/bin/python /usr/bin/python2.6.6# ln -s /usr/local/bin/python2.7 /usr/bin/python# vim /usr/bin/yum #做下面修改#!/usr/bin/python2.6.6# vim /usr/libexec/urlgrabber-ext-down #做下面修改#!/usr/bin/python2.6.6
安装easy_install
# cd /software# wget --no-check-certificate /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 /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 /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 yesloglevel warninglogfile "/var/log/redis.log"bind 127.0.0.1 192.168.30.128(服务器IP)# cd ..# mv redis-3.2.8 /usr/local/redis# /usr/local/redis/src/redis-server /usr/local/redis/redis.conf
配置mysql
# vim /etc/f[mysqld]character_set_server = utf8# systemctl start mysqld# mysql -uroot -p #初始密码为空,直接回车就行;或 grep "password" /var/log/mysqld.log 查看初始密码mysql> create database opsmanage DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;mysql> grant all privileges on opsmanage.* to root@'%' identified by '123456789';mysql> flush privileges;mysql> \qsystemctl restart msqld
配置opsmanage
# cd OpsManage/OpsManage/# vim settings.py #做下面修改BROKER_URL = 'redis://127.0.0.1:6379/4'#修改成自己的配置,格式是redis://[:password]@host:port/dbREDSI_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':'123456789','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/', #修改成自己的配置)SFTP_CONF = {'port':22,'username':'root','password':'123456789','timeout':30} #修改成自己的配置
生成数据表与管理员账户
# cd /mnt/OpsManage/# python manage.py makemigrations OpsManage
出错:
django.db.utils.OperationalError: (1045, "Access denied for user 'root'@'opsmanage' (using password: YES)")
解决:
# mysql -uroot -pmysql> grant all privileges on *.* to root@'%' identified by '123456789';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
启动部署平台
# nohup python manage.py runserver 0.0.0.0:8000 &
# systemctl stop firewalld# setenforce 0
后面关机后再打开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 &
打开浏览器,输出 服务器ip:8080 访问:
登陆进来是用户中心
查看仪表板
: 查看资产管理
: 查看代码发布
: 查看任务管理
: 查看应用部署
:
配置认证
# 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 defaultdirectory=/mnt/OpsManagestdout_logfile=/var/log/celery-worker-default.logautostart=trueautorestart=trueredirect_stderr=truestopsignal=QUITnumprocs=1[program:celery-worker-ansible]command=/usr/bin/python manage.py celery worker --loglevel=info -E -Q ansibledirectory=/mnt/OpsManagestdout_logfile=/var/log/celery-worker-ansible.logautostart=trueautorestart=trueredirect_stderr=truestopsignal=QUITnumprocs=1[program:celery-beat]command=/usr/bin/python manage.py celery beatdirectory=/mnt/OpsManagestdout_logfile=/var/log/celery-beat.logautostart=trueautorestart=trueredirect_stderr=truestopsignal=QUITnumprocs=1[program:celery-cam]command=/usr/bin/python manage.py celerycamdirectory=/mnt/OpsManagestdout_logfile=/var/log/celery-celerycam.logautostart=trueautorestart=trueredirect_stderr=truestopsignal=QUITnumprocs=1
启动celery:
# cd /mnt/OpsManage/# supervisord -c /etc/supervisord.conf# supervisorctl status #要检查是否都是running状态
今天就谈谈如何去安装OpsManage,至于怎么去使用后面有机会再说。安装过程不能完全照搬README文档,可能实际操作过程中会遇到一些问题需要我们具体去解决。