一)安装python3.5.2
安装依赖库:yuminstall zlib-devel
yum install zlib
yum install openssl-devel
wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz
tar -xvf Python-3.5.2.tgz
cd Python-3.5.2
./configure
make
make install
rm python
ln -s /usr/local/bin/python3 /usr/bin/python
二)安装pip for python3
unzip setuptools-39.1.0.zip
python setup.py install
python -m pip install--upgrade pip
pip –V
三)安装Django
pip install Django==1.11.13
四)安装mysql
安装所依赖的包
yum-y install make gcc-c++ cmake bison-devel ncurses-devel libaio
yuminstall libaio libaio-devel –y
yuminstall perl-Data-Dumper –y
yum installnet-tools –y
yum install perl
yum install -y perl-Module-Install.noarch
安装boost
wget https://sourceforge.mirrorservice.org/b/bo/boost/boost/1.59.0/boost_1_59_0.tar.gz
检查系统是否安装mysql或Mariadb数据库:
rpm -qa | grep mariadb
rpm -qa | grep mysql
卸载mariadb数据库
yum -y remove mari*
查系统是没有安装过 MySQL 和 Mariadb 数据库的
获取mysql源码
wgethttps://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.22.tar.gz
解压后(可执行 ./ bootstrap.sh ./b2 install)
ln -s /usr/local/ mysql-5.7.22/usr/local/mysql
解压:
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.7.22/ \
-DMYSQL_DATADIR=/usr/local/mysql-5.7.22/data \
-DSYSCONFDIR=/etc \
-DEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DENABLED_LOCAL_INFILE=1 \
-DEXTRA_CHARSETS=all
make & make install
中间提示错误:
c++: internal compiler error:Killed (program cc1plus)
Please submit a full bugreport,
with preprocessed source ifappropriate.
See<http://bugzilla.redhat.com/bugzilla> for instructions.
make[2]: ***[sql/CMakeFiles/sql.dir/item_geofunc.cc.o] Error 4
make[1]: ***[sql/CMakeFiles/sql.dir/all] Error 2
交换区不够,设置2G交换区。
# dd if=/dev/zeroof=/swapfile bs=1k count=2048000 --获取要增加的2G的SWAP文件块
# mkswap /swapfile -- 创建SWAP文件
# swapon /swapfile -- 激活SWAP文件
# swapon -s -- 查看SWAP信息是否正确
# echo "/var/swapfile swap swap defaults 0 0">> /etc/fstab -- 添加到fstab文件中让系统引导时自动启动。
(应该是内存不足,换成低版本5.6.40安装,下再mysql 源码
wget https://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.40.tar.gz
cmake .-DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.6.40/-DMYSQL_DATADIR=/usr/local/mysql-5.6.40/data -DSYSCONFDIR=/etc-DEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1-DMYSQL_USER=mysql
-DENABLED_LOCAL_INFILE=1 -DEXTRA_CHARSETS=all)
#useradd -g mysql mysql
执行命令创建mysql用户组
#groupadd mysql
chown -Rmysql:mysql /usr/local/mysql/
添加开机启动:执行命令cpsupport-files/mysql.server /etc/init.d/mysql,把启动脚本放到开机初始化目录
chmod +x/etc/init.d/mysql 赋予可执行权限
**如果/etc/目录下有my.cnf存在,需要把这个配置删除了**
perlscripts/mysql_install_db --user=mysql
拷贝support-files下的my-default.cnf文件。cp ./my-default.cnf /etc/my.cnf
供参考的配置文件
[mysqld]
# Remove leading # and set tothe amount of RAM for the most important data
# cache in MySQL. Start at 70%of total RAM for dedicated server, else 10%.
innodb_buffer_pool_size = 128M
# Remove leading # to turn ona very important data integrity option: logging
# changes to the binary logbetween backups.
log_bin
# These are commonly set,remove the # and set as required.
basedir = /usr/local/mysql
datadir =/usr/local/mysql/data
port = 3306
# server_id = .....
socket =/tmp/mysql.sock
# Remove leading # to setoptions mainly useful for reporting servers.
# The server defaults arefaster for transactions and fast SELECTs.
# Adjust sizes as needed,experiment to find the optimal values.
join_buffer_size = 128M
sort_buffer_size = 2M
read_rnd_buffer_size = 2M
添加mysql的bin路径
vim/etc/profile
PATH=$PATH:/usr/local/mysql/bin
exportPATH
添加mysql库路径
vim /etc/ld.so.conf
/usr/local/mysql/lib/
路径生效:
ldconfig
chkconfig --addmysql 添加服务
chkconfig --list 显示服务列表
如果看到mysql的服务,并且3,4,5都是on的话则成功,如果是off,则键入
chkconfig mysql on
启动mysql服务:执行命令service mysql start
修改mysql的root用户密码,root初始密码为空的:
执行命令:./bin/mysqladmin -u root password '密码' (注意前面有个“.”)
登录: mysql-hlocalhost -uroot -p
安装mysql驱动
pip install mysqlclient.
修改
建立数据库:createdatabase mydatabase character set utf8;
五) 使用Django
1) 新建django项目:
django-admin startproject projectname
cd projectname
2)新建应用
django-admin startapp appname
3)使用mysql数据库
修改setting.py
DATABASES = {
'default': {
'ENGINE':'django.db.backends.mysql',
'NAME': 'mydatabase',
'USER': 'root',
'PASSWORD': '密码',
'HOST': '127.0.0.1',
'PORT': '3306',
}
}
4)创建数据库
python manage.py makemigrations
python manage.py migrate
5)启动服务器
修改新建项目下的setting.py
ALLOWED_HOSTS = ['127.0.0.1','你的外网ip','localhost']
运行服务器
python manage.py runserver 0.0.0.0:8008