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。
三.安裝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
# https://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
最後更新:2017-05-07 15:01:15