centos7安装python开发环境(python3_postgresql_sublime_supervisor)

一. 安装gnome

1.最小化安装centos7。
2.安装X11。yum groupinstall "X Window System"。
3.安装gnome。
    全安装:yum groupinstall -y "GNOME Desktop"。
    最小安装:yum install gnome-classic-session gnome-terminal。 nautilus-open-terminal control-center liberation-mono-fonts。
4.开机启动图形界面:ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target。
5.重启:reboot。
6.安装字体:yum groupinstall Fonts。
7.更新字体缓存: fc-cache。
8.安装优化工具:yum install gnome-tweak-tool.noarch。
9.安装归档工具:yum install file-roller。

二.安装python3

1.官网下载python。
2.解压下载好的压缩包。
3.创建目录mkdir /usr/local/python_3.5.2。
4.进入解压目录sudo ./configure --prefix=/usr/local/python_3.5.2 。
5.make。
6.make install。
7.创建连接 ln -s /usr/local/python_3.5.2/bin/python3.5  /usr/local/bin/python3。
说明:yum和supversion等使用python2,所以不将/usr/bin/python连接到python3.使用python3时加#!/usr/bin/env python3。
8.python资源。
   编程网站:The Python Challenge,Project Euler。
   语法参考:《python学习手册》,官方网站。

三.安装PostgreSQL9.5

1.下载。
   在postgresql的官方即可找到源码文件目录,地址如下:https://www.postgresql.org/ftp/source/,在下载列表中根据需求选择版本。
2. 配置编译安装。
   进入pg压缩包目录通过tar -zxvf ./postgresql-9.5.5.tar.gz进行解压,进入解压目录。
   通过./configure --help可以看到编译相关的帮助信息。
   编译时指定一个安装目录./configure --prefix=/usr/local/postgresql。配置完成了。
   接下来就可以编译安装了:make install clean。
  (新系统安装过程中可能出现的问题)没有c编译器,提示缺少readline库,缺少zlib库。分别执行yum install gcc,yum install readline-devel,yum install zlib-devel。
3.用户权限与环境变量。
   编译安装成功后,接下来要做的就是创建一个普通用户,因为默认超级用户(root)不能启动postgresql,所以需要创建一个普通用户来启动数据库,执行以下命令创建用户:useradd postgres。
   接下来需要设置权限,将postgres的数据目录全部赋权给postgres用户(此处我将postgres的数据目录指定在在/usr/local/postgresql/data目录下):chown -R postgres:postgres /usr/local/postgresql/。
   最后为了方便起见设置一下相关的环境变量,此处仅仅设置postgres用户的环境变量,所以首先通过su - postgres切换到postgres用户,打开.bash_profile文件并追加以下内容:PGHOME=/usr/local/postgresql,export PGHOME,PGDATA=/usr/local/postgresql/data,export PGDATA。 ln -s /usr/local/postgresql/bin/pg_ctl  /usr/local/bin/pg_ctl。
4.初始化数据库。
   由于配置了环境变量,所以此处我们直接执行initdb即可完成db初始化,但在这之前我们可以通过initdb --help看一下初始化相关的帮助信息。可以看到在使用initdb进行初始化的同时我们可以指定参数来同时进行一些初始化工作,例如指定pgdata(postgresql数据目录)、指定encoding(编码)、指定数据库超级用户的用户名和密码等等,在最后面我标记出的这段话指出了如果data目录没有指定,则会默认使用环境变量中的PGDATA,由于之前我们刚刚设置了PGDATA环境变量,所以此处我们也就无需再额外指定,最后执行初始化命令即可:initdb。同时在postgresql的目录可以看到生成的数据目录data以及该目录的相关数据和配置文件。
5.配置文件。
   pg_hba.conf和postgresql.conf两个配置文件,一个是访问控制配置(127.0.0.1改为信任的客户端ip网段使其可以远程访问),一个是postgresql主配置文件(listen_address=localhost改为星号使其监听整个网络),方便起见我这里将pg_hba.conf的ip地址修改为0.0.0.0/0,而加密方式改为md5,就表示需要密码访问,算是提供一个最低级的安全防护。开放pg的5432端口。
6.将端口加入防火墙。
   firewall-cmd --zone=public --add-port=5432/tcp --permanent 或者 firewall-cmd --add-service=postgresql --permanent  开放postgresql服务
   firewall-cmd --reload 重载防火墙
7.启动和连接。
   pg_ctl start -D /usr/local/postgresql/data -l /usr/local/postgresql/log/pg_server.log
8.设置postgres用户的密码(默认为空)。
   切换用户,su - postgres。
   登录数据库,psql -U postgres ,执行后提示符变为 'postgres=#'。
   设置postgres用户密码, ALTER USER postgres WITH PASSWORD 'abc123'  ,会提示输入两次密码。
   退出数据库, q  。
9.postgresql服务脚本。
   vim /lib/systemd/system/postgresql.service 。
    # It's not recommended to modify this file in-place, because it will be
    # overwritten during package upgrades.  If you want to customize, the
    # best way is to create a file "/etc/systemd/system/postgresql.service",
    # containing
    #   .include /lib/systemd/system/postgresql.service
    #   ...make your changes here...
    # For more info about custom unit files, see
    # http://fedoraproject.org/wiki/Systemd#How_do_I_customize_a_unit_file.2F_add_a_custom_unit_file.3F

    # For example, if you want to change the server's port number to 5433,
    # create a file named "/etc/systemd/system/postgresql.service" containing:
    #   .include /lib/systemd/system/postgresql.service
    #   [Service]
    #   Environment=PGPORT=5433
    # This will override the setting appearing below.

    # Note: changing PGPORT or PGDATA will typically require adjusting SELinux
    # configuration as well; see /usr/share/doc/postgresql-*/README.rpm-dist.

    # Note: do not use a PGDATA pathname containing spaces, or you will
    # break postgresql-setup.

    # Note: in F-17 and beyond, /usr/lib/... is recommended in the .include line
    # though /lib/... will still work.

    [Unit]
    Description=PostgreSQL database server
    After=network.target

    [Service]
    Type=forking

    User=postgres
    Group=postgres

    # Port number for server to listen on
    Environment=PGPORT=5432

    # Location of database directory
    Environment=PGDATA=/usr/local/postgresql_9.6.2/data

    # Where to send early-startup messages from the server (before the logging
    # options of postgresql.conf take effect)
    # This is normally controlled by the global default set by systemd
    # StandardOutput=syslog

    # Disable OOM kill on the postmaster
    OOMScoreAdjust=-1000

    ExecStart=/usr/local/postgresql_9.6.2/bin/pg_ctl start -D ${PGDATA} -s -o "-p ${PGPORT}" -w -t 300 -l /usr/local/postgresql_9.6.2/data/log/pg_server.log
    ExecStop=/usr/local/postgresql_9.6.2/bin/pg_ctl stop -D ${PGDATA} -s -m fast
    ExecReload=/usr/local/postgresql_9.6.2/bin/pg_ctl reload -D ${PGDATA} -s

    # Give a reasonable amount of time for the server to start up/shut down
    TimeoutSec=300

    [Install]
    WantedBy=multi-user.target
10.自启动脚本都能够添加到systemctl自启动服务。
    systemctl enable postgresql.service
    systemctl start/restart/stop postgresql.service

四.安装supervisor。

1.安装supervisor。
    pip install supervisor。
2.产生配置文件。
    echo_supervisord_conf > /usr/local/etc/supervisord.conf。
3.supervisor服务启动脚本。
    vim /lib/systemd/system/supervisord.service 。
    supervisord开机自启动脚本(各版本系统):https://github.com/Supervisor/initscripts 。
        # supervisord service for systemd (CentOS 7.0+)
        # by ET-CS (https://github.com/ET-CS)
    [Unit]
    Description=Supervisor daemon

    [Service]
    Type=forking
    ExecStart=/usr/bin/supervisord -c /usr/local/etc/supervisord.conf
    ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown
    ExecReload=/usr/bin/supervisorctl $OPTIONS reload
    KillMode=process
    Restart=on-failure
    RestartSec=42s

    [Install]
    WantedBy=multi-user.target
4.自启动脚本都能够添加到systemctl自启动服务。
    systemctl enable supervisord.service
    systemctl start/restart/stop supervisor.service

五.安装Sublime Text 3。

1.下载解压。
   进入解压目录:ln -s /usr/local/sublime-text-3/sublime_text  /usr/local/bin/sublime3。
2.安装插件管理器。
   从 Sublime Text 3 官方获取用于安装Package Control 的代码。依次点击 View > Show Console (快捷键Ctrl + `)打开控制台。在控制台中粘贴官方代码,然后点击回车。最后重启。
3.安装插件。
   主题Flatland,Agila,Material Theme,Brogrammer;扩展侧边栏中菜单选项SideBarEnhancements;终极 Python 插件Anaconda;文件创建AdvancedNewFile;版本控制git;函数生成描述DocBlockr_python;代码静态检查工具框架SublimeLinter-pyflakes。
4.配置。
   修改快捷键 Sublime Text > Preferences > Package Settings > 插件 > Key Bindings – User。
   修改配置Sublime Text > Preferences > Package Settings > 插件 > Settings – User。
5.配置python3版本。
   Sublime Text > Preferences > Package Settings >Anaconda> Settings – default。将"python_interpreter": "python"改为"python_interpreter": "python3"。
原文地址:https://www.cnblogs.com/iyulang/p/6830609.html