1. 程式人生 > >centos7安裝python開發環境(python3,postgresql,sublime,supervisor)

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.24.進入解壓目錄sudo ./configure --prefix=/usr/local/python_3.5.25.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://yq.aliyun.com/articles/78727?utm_campaign=wenzhang&utm_medium=article&utm_source=QQ-qun&201759&utm_content=m_20124