-
PostgreSQL數據庫部署管理
1.rpm方式安裝
掛載系統安裝鏡像:
[root@localhost ~]# mount /dev/cdrom /mnt
進入安裝包路徑:
[root@localhost ~]# cd /mnt/Packages
依次安裝如下程序包:
[root@localhost Packages]# rpm -ihv postgresql-libs-9.2.7-1.el7.x86_64.rpm
[root@localhost Packages]# rpm -ihv postgresql-9.2.7-1.el7.x86_64.rpm
[root@localhost Packages]# rpm -ihv postgresql-server-9.2.7-1.el7.x86_64.rpm
2.初始化數據庫并建立數據庫和用戶
切換系統用戶:
[root@localhost ~]# su - postgres
初始化數據庫:
[postgres@localhost ~]$ initdb -D /var/lib/pgsql/data/
3.數據庫啟停
啟動數據庫:
[postgres@localhost ~]$?pg_ctl -D /var/lib/pgsql/data start
停用數據庫:
[postgres@localhost ~]$?pg_ctl -D /var/lib/pgsql/data?stop
重啟數據庫:
[postgres@localhost ~]$?pg_ctl -D /var/lib/pgsql/data restart
查看數據庫是否啟動:
[postgres@localhost ~]$?ps -A | grep postgres
4.數據庫管理
創建數據庫:
[postgres@localhost ~]$ createdb 數據庫名
創建數據庫用戶:
[postgres@localhost ~]$ createuser 用戶名
訪問數據庫:
[postgres@localhost ~]$ psql -d 數據庫名 -U 用戶名
使用"\q"命令退出postgresql管理工具
查看postgresql使用的端口:
[postgres@localhost ~]$?netstat -a | grep postgresql
postgresql數據目錄:/var/lib/pgsql/data5.數據庫參數配置
/var/lib/pgsql/data目錄下編輯postgresql.conf文件:
listen_addresses = '*' ?#將前面注釋去掉并將值改為* ? ? ?
# PostgreSQL安裝完成后,默認是只接受來在本機localhost的連接請求,此處將數據庫服務器的監聽模式修改為監聽所有主機發出的連接請求
port = 5432 ? ? #將前面注釋去掉?
# ?默認端口
/var/lib/pgsql/data目錄下,修改pg_hba.conf文件,配置對數據庫的訪問權限:在最后一行添加如下內容:
host ? ? ?all ? ? ?all ? ? ? ? 192.168.61.0/24 ? ? ? ? trust
保存退出
修改默認數據庫用戶名登陸密碼:su - postgres
psql?
postgres=# \password
提示修改密碼。
參數修改后,需要重啟數據庫
-
Apache+PHP環境搭建配置
Apache安裝配置:
1.安裝apache軟件包
yum install httpd -y2.啟動apache服務
systemctl start httpd ? ?//開啟服務
systemctl enable httpd ? //開機自啟3.Apache的配置
Apache主配置文件:/etc/httpd/conf/httpd.conf
ServerRoot “/etc/httpd” 用于指定Apache的運行目錄
Listen 80 監聽端口
DocumentRoot “/var/www/html” 網頁文件的存放目錄<Directory "/var/www/html">
? ? ? ?Require all granted ? ?自定義目錄權限?
?</Directory>?ErrorLog “logs/error_log” 錯誤日志存放位置
DirectoryIndex index.html 默認主頁名稱PHP安裝配置:
1.安裝php
yum -y install php php-mysql2.修改/etc/php.ini文件
cgi.fix_pathinfo=0
date.timezone = PRC3.重啟Apache服務
systemctl restart httpd