CentOS7下的Django2集成部署二:Nginx1.14.2、Mysql5.7和Python3.7的安装

nginx

  •   安装依赖
    yum install -y gcc pcre-devel zlib zlib-devel
  •   默认安装
    rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
    yum install -y nginx
  •   配置
    [root@gz-ct76211 ~]# nginx -v
    nginx version: nginx/1.14.2
    [root@gz-ct76211 ~]# systemctl enable nginx
    Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
    [root@gz-ct76211 ~]# systemctl start nginx
    [root@gz-ct76211 ~]# lsof -i :80
    COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
    nginx   11227  root    6u  IPv4  34477      0t0  TCP *:http (LISTEN)
    nginx   11228 nginx    6u  IPv4  34477      0t0  TCP *:http (LISTEN)
  •   调试
    [root@gz-ct76211 ~]# elinks http://localhost --dump
                                   Welcome to nginx!
    
       If you see this page, the nginx web server is successfully installed and
       working. Further configuration is required.
    
       For online documentation and support please refer to [1]nginx.org.
       Commercial support is available at [2]nginx.com.
    
       Thank you for using nginx.
    
    References
    
       Visible links
       1. http://nginx.org/
       2. http://nginx.com/

    此刻nginx基本上就已经可以正常工作了!调试过程中,为了避免干扰,请务必把selinux和防火墙 firewalld或iptables 都关闭了

mysql

  •   安装依赖
    yum -y install ncurses-devel gcc-* bzip2-*
  •   编译安装
    • cmake
      #获取cmake
      wget https://github.com/Kitware/CMake/releases/download/v3.13.1/cmake-3.13.1.tar.gz
      #解压
      tar xf cmake-3.13.1.tar.gz
      #进入程序目录
      cd cmake-3.13.1
      #编译并安装
      ./configuare
      
      make
      
      make install
    • boost
      #获取boost1.59
      wget https://nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.bz2
      #解压
      tar xf boost_1_59_0.tar.bz2
      #移动目录给mysql编译使用
      mv boost_1_59_0 /usr/local/boost
    • mysql
      #获取mysql
      wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24.tar.gz
      tar xf
      mysql-5.7.24.tar.gz
      cd mysql-5.7.24

      用cmake编译,耗时有点久编译安装差不多1小时左右

      cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql 
      -DMYSQL_DATADIR=/usr/local/mysql/data/ 
      -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock 
      -DDOWNLOAD_BOOST=0 
      -DWITH_INNODBBASE_STORAGE_ENGINE=1 
      -DENABLE_LOCAL_INFILE=1 
      -DEXTRA_CHARSETS=all 
      -DDEFAULT_CHARSET=utf8 
      -DDEFAULT_COLLATION=utf8_general_ci -DWITH_DEBUG=0 
      -DWITH_EMBEDED_SERVER=0 
      -DDOWNLOAD_BOOST=1 
      -DWITH_BOOST=/usr/local/boost


      # -DMYSQL_USER=mysql 稍后新建mysql用户
      make && make install
  •   配置
    • 添加启动文件
      cp support-files/mysql.server /etc/init.d/mysql
      #授权
      chmod 755 /etc/init.d/mysql
    • 用户配置
      #添加用户
      useradd -s /sbin/nologin -r mysql
      #用户授权
      chown mysql.mysql /usr/local/mysql/ -R
    • 设置链接文件
      ln -sf /usr/local/mysql/bin/* /usr/bin/
      ln -sf /usr/local/mysql/lib/* /usr/lib/
      ln -sf /usr/local/mysql/libexec/* /usr/local/libexec
      ln -sf /usr/local/mysql/share/man/man1/* /usr/share/man/man1
      ln -sf /usr/local/mysql/share/man/man8/* /usr/share/man/man8
    • 配置文件
      #数据目录
      

      [root@home-ct75211 mysql-5.7.24]# mkdir -pv /usr/local/mysql/data
      mkdir: created directory ‘/usr/local/mysql/data’

       配置/etc/my.cnf

       1 [mysqld]
       2 datadir=/usr/local/mysql/data
       3 socket=/usr/local/mysql/mysql.sock
       4 # Disabling symbolic-links is recommended to prevent assorted security risks
       5 symbolic-links=0
       6 # Settings user and group are ignored when systemd is used.
       7 # If you need to run mysqld under a different user or group,
       8 # customize your systemd unit file for mariadb according to the
       9 # instructions in http://fedoraproject.org/wiki/Systemd
      10 
      11 [mysqld_safe]
      12 log-error=/var/log/mysql.log
      13 pid-file=/var/run/mysql.pid
      14 
      15 #
      16 # include all files from the config directory
      17 #
      18 !includedir /etc/my.cnf.d
      vim /etc/my.cnf
  • 生成root密码
    #生成默认密码
    /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

    启动MySQL

    /etc/init.d/mysql start

    设置root密码

    mysql_secure_installation
     1 [root@home-ct75211 mysql-5.7.24]# mysql_secure_installation
     2 
     3 Securing the MySQL server deployment.
     4 
     5 Enter password for user root: 
     6 
     7 The existing password for the user account root has expired. Please set a new password.
     8 
     9 New password: 
    10 
    11 Re-enter new password: 
    12 
    13 VALIDATE PASSWORD PLUGIN can be used to test passwords
    14 and improve security. It checks the strength of password
    15 and allows the users to set only those passwords which are
    16 secure enough. Would you like to setup VALIDATE PASSWORD plugin?
    17 
    18 Press y|Y for Yes, any other key for No: n
    19 Using existing password for root.
    20 Change the password for root ? ((Press y|Y for Yes, any other key for No) : y
    21 
    22 New password: 
    23 
    24 Re-enter new password: 
    25 By default, a MySQL installation has an anonymous user,
    26 allowing anyone to log into MySQL without having to have
    27 a user account created for them. This is intended only for
    28 testing, and to make the installation go a bit smoother.
    29 You should remove them before moving into a production
    30 environment.
    31 
    32 Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
    33 Success.
    34 
    35 
    36 Normally, root should only be allowed to connect from
    37 'localhost'. This ensures that someone cannot guess at
    38 the root password from the network.
    39 
    40 Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
    41 Success.
    42 
    43 By default, MySQL comes with a database named 'test' that
    44 anyone can access. This is also intended only for testing,
    45 and should be removed before moving into a production
    46 environment.
    47 
    48 
    49 Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
    50  - Dropping test database...
    51 Success.
    52 
    53  - Removing privileges on test database...
    54 Success.
    55 
    56 Reloading the privilege tables will ensure that all changes
    57 made so far will take effect immediately.
    58 
    59 Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
    60 Success.
    61 
    62 All done! 
    View Code
  •   调试
     1 [root@home-ct75211 mysql-5.7.24]# mysql -u root -p
     2 Enter password: 
     3 Welcome to the MySQL monitor.  Commands end with ; or g.
     4 Your MySQL connection id is 5
     5 Server version: 5.7.24 Source distribution
     6 
     7 Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
     8 
     9 Oracle is a registered trademark of Oracle Corporation and/or its
    10 affiliates. Other names may be trademarks of their respective
    11 owners.
    12 
    13 Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
    14 
    15 mysql> show databases;
    16 +--------------------+
    17 | Database           |
    18 +--------------------+
    19 | information_schema |
    20 | mysql              |
    21 | performance_schema |
    22 | sys                |
    23 +--------------------+
    24 4 rows in set (0.00 sec)
    25 
    26 mysql> 
    mysql -u root -p
  • python

    其实在编译的时候已经有提示了,下面把Module/Setup重新编辑下

    [root@home-ct75211 Python-3.7.1]# vim Modules/Setup
    #把下边这段话的#去掉
    211 SSL=/usr/local/ssl 212 _ssl _ssl.c 213 -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl 214 -L$(SSL)/lib -lssl -lcrypto

    再次  make -j4 && make install ,然后再升级pip

    [root@home-ct75211 Python-3.7.1]# pip3 install --upgrade pip
    Collecting pip
    ... ...
    Installing collected packages: pip
      Found existing installation: pip 10.0.1
        Uninstalling pip-10.0.1:
          Successfully uninstalled pip-10.0.1
    Successfully installed pip-18.1
    pip3 install --upgrade pip
  •        virtualenv
    [root@home-ct75211 Python-3.7.1]# pip3 install virtualenv
    Collecting virtualenv
      Downloading 
    ... ...
    Installing collected packages: virtualenv
    Successfully installed virtualenv-16.1.0
    pip3 install virtualenv
    #创建py3web虚拟环境
    [root@home-ct75211 ~]# virtualenv -p python3 py3web
    Running virtualenv with interpreter /usr/local/bin/python3
    Using base prefix '/usr/local'
    New python executable in /root/py3web/bin/python3
    Also creating executable in /root/py3web/bin/python
    Installing setuptools, pip, wheel...
    done.
    #进入py3web虚拟环境,顺便安装django2
    [root@home-ct75211 ~]# source py3web/bin/activate
    (py3web) [root@home-ct75211 ~]# pip3 install django==2.*
    ... ...
    Installing collected packages: pytz, django
    Successfully installed django-2.1.4 pytz-2018.7
    #退出虚拟环境
    (py3web) [root@home-ct75211 ~]# deactivate
    [root@home-ct75211 ~]# 
  •        uwsgi
  •                重启uwsgi服务

    [root@home-ct75211 ~]# /etc/init.d/uwsgi stop
    Stopping uwsgi: 
    /usr/local/bin/uwsgi STOPED.
    [root@home-ct75211 ~]# /etc/init.d/uwsgi start
    Starting uwsgi: 
    [uWSGI] getting INI configuration from /etc/uwsgi/uwsgi.ini
    [root@home-ct75211 ~]# elinks http://www.my-django.cc --dump
    [1]django
    
       View [2]release notes for Django 2.1
    
    The install worked successfully! Congratulations!
    
       You are seeing this page because [3]DEBUG=True is in your settings file
       and you have not configured any URLs.
    
        [4]Django Documentation
    
       Topics, references, & how-to's
    
        [5]Tutorial: A Polling App
    
       Get started with Django
    
        [6]Django Community
    
       Connect, get help, or contribute
    
    References
    
       Visible links
       1. https://www.djangoproject.com/
       2. https://docs.djangoproject.com/en/2.1/releases/
       3. https://docs.djangoproject.com/en/2.1/ref/settings/#debug
       4. https://docs.djangoproject.com/en/2.1/
       5. https://docs.djangoproject.com/en/2.1/intro/tutorial01/
       6. https://www.djangoproject.com/community/

    基本上的部署环境已经大功告成了!!!

    相关推荐