apache 驱动django服务器搭建

操作系统:centos6.8 final 版本 64位,安装操作系统时选择自定义安装,将所有软件包勾选。
下面是操作系统安装完成后的环境配置,以下操作均为root用户,非root用户需要前加sudo :
一、安装apache
1、yum安装
yum install httpd httpd-devel httpd-server
2、设置开机启动
chkconfig httpd on
3、开启apche
service httpd start
在浏览器输入地址:127.0.0.1验证是否安装成功,如果成功会有apache欢迎界面。
二、安装python2.7
1、wget http://python.org/ftp/python/2.7.6/Python-2.7.6.tgz
2、tar -xzvf Python-2.7.6.tgz
3、./configure --enable-shared --prefix=/usr/local/python2.7
4、make && make install
5、 mv /usr/bin/python /usr/bin/python.bak
6、ln -s /usr/local/python2.7/bin/python2.7 /usr/bin/python
7、检验python指向是否成功
8、python -v
9、安装了python2.7,第一次执行时报错: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
10、::解决方法如下:
11、编辑 vi /etc/ld.so.conf
12、如果是非root权限帐号登录,使用 sudo vi /etc/ld.so.conf
13、添加上python2.7的lib库地址,如我的/usr/local/python2.7/lib,保存文件
14、执行 /sbin/ldconfig -v命令,如果是非root权限帐号登录,使用 sudo /sbin/ldconfig -v。这样 ldd 才能找到这个库,执行python2.7就不会报错了
三、修复不能正常工作的yum
1、vi /usr/bin/yum
2、将首行显示的 !#/usr/bin/python 修改为 !#/usr/bin/python2.6
四、安装mod_wsgi
如何使Apache支持django
采用mod_wsgi的方式。
首先需要下载mod_wsgi-2.4.tar.gz。
可以到官网下载。
接下来执行如下命令,对压缩包进行解压;
tar –zxvf mod_wsgi-3.4.tar.gz
然后cd到解压之后的目录,执行如下命令,产生配置编译配置文件;
./configure --with-apxs=/usr/local/apache2/bin/apxs --with-python=/usr/bin/python

============================================================

mod_python 编译出错的解决办法
下载源码包,解压得到目录,进入该目录,执行:
./configure --with-apxs=/usr/local/apache2/bin/apxs --with-python=/usr/bin/python2.4
make 后出错退出

connobject.c: In function ‘_conn_read’:
connobject.c:142: error: request for member ‘next’ in something not a structure
or union
apxs:Error: Command failed with rc=65536
.
make[1]: *** [mod_python.so] Error 1
make[1]: Leaving directory `/usr/src/rpm/BUILD/mod_python-3.3.1/src’
make: *** [do_dso] Error 2

这是一个bug,作如下修改
需修改mod_python-3.3.1/src/connobject.c中
!(b == APR_BRIGADE_SENTINEL(b)

!(b == APR_BRIGADE_SENTINEL(bb)

完毕之后,mod_python 会在 /usr/local/apache2/modules 中添加 mod_python.so 库文件,并且在 /usr/lib/python2.4/site-packages/中添加 mod_python 包。
如果编译程序没有检测到 apache 和 python,会报错退出。

===========================================================

其中/usr/local/apache2为Apache的安装目录,确保apxs存在于bin目录中,/usr/bin/python为Ubuntu中python默认安装位置。
接下来执行make 命令,进行编译;
make
最后执行如下命令,进行安装;
sudo make install
如果到这里都顺利的话,会提示“chmod 755 /usr/local/apache2/modules/mod_wsgi.so” 为mod_wsgi.so赋权。如图:

照着提示输入命令即可:
chmod 755 /usr/local/apache2/modules/mod_wsgi.so

五、配置apache文件
1、vi /etc/httpd/conf/httpd.conf
2、找到LoadModule组,在下面添加:LoadModule wsgi_module modules/mod_wsgi.so
3、在2添加处的下面添加:
WSGIScriptAlias / “/home/www/test/wsgi/django.wsgi”
4、添加:
<VirtualHost *:80>
ServerAdmin yangmaoqiang@hmmachine.com
directoryIndex index.html index.php index.htm index.shtml login.php
ServerName www.xinyicheng.com
DocumentRoot /home/www/test
<Directory “/home/www/test”>
Options -Indexes
AllowOverride All
Order allow,deny
Allow from all


Alias /static/ /home/www/test/static/
<Directory “/static/”>
Order allow,deny
Options Indexes
Allow from all
IndexOptions FancyIndexing

注:标黄色部分替换为为前端项目test的真实路径
5、重启apache
service httpd restart
六、安装mysql
1、 yum install mysql mysql-server mysql-devel
2、service mysqld start
3、chkconfig mysqld on
4、修改mysql root密码
mysql> use mysql;
mysql> update user set password=password(‘test’) where user=‘root’ and host=‘localhost’;
mysql> flush privileges;
5、设置mysql远程访问:
mysql>GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘hm.2016’ WITH GRANT OPTION ;

mysql>FLUSH PRIVILEGES ;
注:在fedoral下启动mysql失败解决:
1、用命令service mariadb start
2、根据错误提示百度之。

七、安装setuptools
去官网下载安装包解压,进入目录执行python setup.py install
八、安装pip
去官网下载安装包解压,进入目录执行python setup.py install
在终端输入pip,如果提示command not found 等相关信息,则需要配置:
1)、编辑/etc/profile文件(永久生效)
找到export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL这行上面加入
PATH=$PATH:/usr/local/python2.7/bin
重新初始化文件,使文件立即生效
source /etc/profile or . /etc/profile
2)、在用户目录下的~/.bashrc文件中增加变量,对单一用户生效(永久的)
九、安装django
1、执行命令pip install django==1.4.20
2、下载完成后验证:
3、终端执行: python
4、import django
5、django.VERSION
6、不报错即为成功。
十、安装mysql-python
1、执行命令pip install mysql-python
2、下载完成后验证:
3、终端执行: python
4、import MySQLdb
5、不报错即为成功。
十一、安装websocket-client
pip install websocket-client
十二、配置django项目wsgi文件
1、在/home/www/test目录下新建目录wsgi
2、在/home/www/test/wsgi目录下新建django.wsgi
3、在django.wsgi文件中添加如下代码:
import os
import sys
sys.path = sys.path + ["/home/www/test/"]
os.environ[‘DJANGO_SETTINGS_MODULE’] = ‘test.settings’
#os.environ[‘PYTHON_EGG_CACHE’] = ‘/tmp/.python-eggs’
##current_dir = os.path.dirname(file)
current_dir = ‘/home/www/test/wsgi/’

sys.stdout = sys.stderr

DEBUG = True

if current_dir not in sys.path:
sys.path.append(current_dir)
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

十三、关闭selinux
1、vi /etc/selinux/config
2、将SELINUX=enforcing更改为SELINUX=disabled,保存关闭
3、执行 setenforce 0
十四、关闭防火墙
service iptables stop
十五、解决无权限访问问题
1、chmod 777 /
2、chmod 777 /home
3、chmod 777 /home/www/
4、chmod 777 -R /home/www/test
将/home/www/test/替换为前端项目真实目录
十六、验证前端配置成功
1、重启apache:
service httpd restart
2、浏览器输入127.0.0.1即可访问前端页面
备注:如果有报错,一定要看apache错误日志,非常重要!!!
查看apache错误日志方法:vi /etc/httpd/logs/errorlog
根据apache错误日志遇到的问题进行百度,我遇到过的问题都是在日志里查到的,问题解决方法
以上配置为apache启动django 的完全配置步骤,已经非常详细了。这些是我在配置中遇到的问题及解决方法。如果还有遇到其他问题,要善于利用搜索引擎,百度一定会找到答案。
十七、安装qt
1、官网下载qt安装包,下载完成后,在终端执行
2、./安装包名称全称
3、根据提示进行安装
十八、配置qmake环境变量
1、vi ~/.bashrc
2、添加export PATH=/opt/Qt5.7.0/5.7/gcc_64/bin:$PATH
3、保存关闭,执行source ~/.bashrc
十九、安装mod_ssl
yum install -y mod_ssl
二十、安装ssh
1、yum install openssh*
2、设置开机启动
chkconfig sshd on
3、开启ssh服务
service sshd start
二十一、安装telnet
1、查看本机是否安装telnet
#rpm -qa | grep telnet
如果什么都不显示。说明你没有安装telnet
2、开始安装
yum install xinetd
yum install telnet
yum install telnet-server
3、装好telnet服务之后,默认是不开启服务的,下面我们需要修改文件来开启服务。
vim /etc/xinetd.d/telnet 修改 disable = yes 为 disable = no
4、需要激活xinetd服务

service xinetd restart 或者 #/etc/rc.d/init.d/xinetd restart

5、设置开机启动
chkconfig xinetd on
二十二、安装nfs
1、安装NFS服务端
yum install -y nfs-utils rpcbind
2、为NFS指定固定端口,运行以下命令:
vi /etc/sysconfig/nfs
搜索和设置如下所示的端口配置:
RQUOTAD_PORT=30001
LOCKD_TCPPORT=30002
LOCKD_UDPPORT=30002
MOUNTD_PORT=30003
STATD_PORT=30004
3、开放防火墙中的上述端口,运行以下命令:
iptables -I INPUT -p tcp --dport 111 -j ACCEPT
iptables -I INPUT -p udp --dport 111 -j ACCEPT
iptables -I INPUT -p tcp --dport 2049 -j ACCEPT
iptables -I INPUT -p udp --dport 2049 -j ACCEPT
iptables -I INPUT -p tcp --dport 30001:30004 -j ACCEPT
iptables -I INPUT -p udp --dport 30001:30004 -j ACCEPT
service iptables save
service iptables restart
4、创建共享目录,运行以下命令:
mkdir -p /data/nfs_share
5、配置exports文件,运行以下命令:
vi /etc/exports
在上述文件的末尾新增一行,如下所示:
/data/nfs_share 192.168.4.212(rw,sync,no_root_squash)
/data/nfs_share *(ro)
这一行表示只有192.168.4.212客户端能够以读写权限挂载共享目录,其他客户端只能以只读权限挂载。
6、启动NFS相关服务,运行以下命令:
chkconfig nfs on
chkconfig rpcbind on
service nfs start
service rpcbind start
7、检查NFS的相关端口是否已经启用,运行以下命令:
service iptables status
rpcinfo -p localhost
8、NFS客户端不需要启动NFS服务,但需要安装nfs-utils,运行以下命令:
yum install -y nfs-utils
9、手动挂载NFS共享目录
1):确定挂载点,运行以下命令:
showmount -e 192.168.4.211
-e选项显示NFS服务端的导出列表。
2):创建挂载目录,运行以下命令:
mkdir -p /root/remote_dir
其中,/root/remote_dir为共享目录的挂载点目录。
3):挂载共享目录,运行以下命令:
mount -t nfs 192.168.4.211:/data/nfs_share /root/remote_dir
其中,-t选项用于指定文件系统的类型为nfs。
4):共享目录使用结束之后,卸载共享目录,运行以下命令:
umount /root/remote_dir
10、开机自动挂载:
向fstab文件中添加共享目录的挂载条目,即可实现开机自动挂载,但是随后与NFS服务端的连接将始终处于活动状态。运行以下命令:
mkdir -p /root/remote_dir
vi /etc/fstab
在上述文件末尾加入共享目录的挂载条目,如下所示:
192.168.4.211:/data/nfs_share /root/remote_dir nfs defaults 0 0
其中,第5个字段设置为0表示共享目录的文件系统不需要使用dump命令进行转储,第6个字段设置为0表示共享目录的文件系统不需要使用fsck命令进行检查。
除此之外,还可以使用自动挂载器(autofs)实现按需自动挂载网络共享目录。当共享不再使用,并处于不活动状态一定时间之后,自动挂载器会对共享解除挂载。
二十三、安装ntp
1、yum install ntp
2、添加全球 NTP 服务器用于同步时间:
vim /etc/ntp.conf
server 0.oceania.pool.ntp.org
server 1.oceania.pool.ntp.org
server 2.oceania.pool.ntp.org
server 3.oceania.pool.ntp.org
3、开机启动:
chkconfig ntpd on
4、开启ntp服务:
service ntpd start
二十四、将gcc版本升级至4.8以上
参考链接:
https://blog.csdn.net/bubbleyang/article/details/86261888

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值