Oliver運維管理系統之三安裝部署

源碼下載:git clone https://github.com/oldtian/Oliver.git

1、安裝以下軟件

1.1 安裝nginx

安裝過程略


1.2 安裝mysql

安裝過程略


1.3 安裝python2.7.10

升級安裝python2.7.10

wget https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tgz
tar -zxf Python-2.7.10.tgz
cd Python-2.7.10
./configure
make all 
make install
make clean
make distclean

查看版本

/usr/local/bin/python2.7 -V

建議軟鏈接

mv /usr/bin/python /usr/bin/python2.6.6
ln -s /usr/local/bin/python2.7 /usr/bin/python

重新驗證版本

python -V


1.4 安裝setuptools

wget https://pypi.python.org/packages/source/s/setuptools/setuptools-19.2.tar.gz
tar -zxf setuptools-19.2.tar.gz
cd setuptools-19.2
python setup.py install


1.5 安裝pip8.1.1

wget https://pypi.python.org/packages/source/p/pip/pip-8.1.1.tar.gz
tar -zxf pip-8.1.1.tar.gz
cd pip-8.1.1
python setup.py install


2、關閉selinux並開放iptables的80端口

setenforce 0
sed -i '/^SELINUX=/{s/enforcing/disabled/}' /etc/sysconfig/selinux
sed -i '/^SELINUX=/{s/enforcing/disabled/}' /etc/selinux/config
iptables -I INPUT 4  -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
/etc/init.d/iptables save


3、pip安裝如下包

pip install supervisor
pip install uwsgi
pip install ansible==1.9.4
pip install Django==1.8.3
pip install django-users2
pip install MySQL-python
pip install rpyc


4、創建uwsgi.ini

建議放置在項目所在目錄下

[uwsgi]
socket = /tmp/oliver.sock         #nginx需要使用到的socket文件
chdir=/opt/www/oliver            #切換到項目所在目錄
wsgi-file = Oliver/wsgi.py         #wsgi.py主程序入口,加載相應環境
touch-reload=/opt/www/oliver/reload   #touch一個空白的reload文件,項目重啓
processes = 2                  #初始啓動進程數
threads = 4
chmod-socket = 664#socket文件的屬性
chown-socket = nginx:nginx#socket文件的屬主和屬組


5、創建supervisor配置文件

echo_supervisord_conf > /etc/supervisord.conf


6、編輯supervisor配置文件

在/etc/supervisord.conf末尾追加

[program:oliver]   #oliver是supervisor管理的進程名
command=/usr/local/bin/uwsgi --ini /www/oliver/uwsgi.ini
directory=/www/oliver
startsecs=0
stopwaitsecs=0
autostart=true
autorestart=true


7、啓動supervisor

supervisord -c /etc/supervisord.conf

查看/tmp/oliver.sock文件是否存在,如果不存在可先將/tmp目錄下文件刪除,然後再一次執行上面的命令


supervisor管理進程命令:

停止進程:

supervisorctl -c /etc/supervisord.conf stop oliver

啓動進程:

supervisorctl -c /etc/supervisord.conf start oliver

重啓進程:

supervisorctl -c /etc/supervisord.conf restart oliver


8、修改nginx配置

nginx的配置文件中添加虛擬主機配置:

server {
    listen      80;
    server_name localhost;
    charset     utf-8;
    client_max_body_size 8M;
    location /media  {
        alias /www/oliver/media;
    }
    location /static {
        alias /www/oliver/static;
    }
    location / {
        uwsgi_pass  unix:///tmp/oliver.sock;
        include    /opt/application/nginx/conf/uwsgi_params;
    }
}

django僅在開發模式可加載setting.py配置中指定目錄下的靜態文件,在生產環境要 通過nginx配置來加載靜態文件,創建static和media目錄。


9、添加網站監控腳本到定時任務

*/5 * * * * /usr/local/bin/python /www/oliver/webapi/sniffer.py >/dev/null 2>&1


10、在需要做安全審計的主機的/etc/profile文件中添加如下配置

HISTSIZE=1200
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE
export HISTCONTROL=ignoredups
export HISTFILE=$HOME/.bash_history
export HISTFILESIZE=1200
export HISTTIMEFORMAT="`whoami` %F %T "
export PROMPT_COMMAND="history -a; history -c; history -r;"'/www/OMAudit/OMAudit_agent.py $(history 1)'
shopt -s histappend
typeset -r PROMPT_COMMAND
typeset -r HISTTIMEFORMAT


11、蒐集靜態文件到指定目錄

在setting.py中配置STATIC_ROOT來指定蒐集靜態文件存放目錄:

python manage.py collectstatic

每次修改靜態文件內容,也需要執行一次以上命令,否則修改後的內容nginx加載不到


12、同步數據庫

python manage.py makemigrations
python manage.py migrate


13、啓動OliverServer主進程

python OliverServer.py &


13、重啓nginx和supervisor

service nginx restart
supervisorctl -c /etc/supervisord.conf restart oliver


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章