2014年7月27日 星期日

Centos6.5 中安裝MariaDB 5.5 資料庫與phpMyAdmin軟體

上午11:54:00 Posted by Amos , , No comments

簡介

本文概述簡單的步驟,教導如何建置LAMP環境(Apache、PHP、MariaDB),並安裝phpmyadmin管理MariaDB資料庫。

環境介紹及前置作業

作業系統版本 : Centos 6.5 (64位元)

MariaDB資料庫版本 : 5.5.38 (64位元)

PHP版本 : 5.4.X (REMI版本)

安裝編輯及wget套件

若於Centos中已有安裝vim (編輯工具)和wget(抓檔案工具)時,可以忽略該步驟
yum -y install wget vim

關閉SELinux

編輯 /etc/sysconfig/selinux檔案,將SELINUX=enforcing 改成 SELINUX=disabled,重新開機。
# This file controls the state of SELinux on the system
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,>
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

設定Open File個數

編輯 /etc/security/limits.conf檔案,設定Open File個數
* hard nofile 65535
* soft nofile 65535

開啟防火牆

編輯 /etc/sysconfig/iptables檔案,開啟8080防火牆(用於node.js的服務),設定完成後請重新啟動防火牆。
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
/etc/init.d/iptables restart 

安裝及設定Apache

輸入 yum install httpd* ,安裝Apacher Server相關套件,並設定於開機時自動啟用,請參考以下步驟進行設定。
yum -y install httpd*
chkconfig --level 345 httpd on
chkconfig --list httpd

為了安全性考量,設定用戶無法瀏覽Apache預設的首頁,請參考以下步驟進行設定(每行前面都加入#符號,共計4行)。
vi /etc/httpd/conf.d/welcome.conf 

#<LocationMatch "^/+$">
    #Options -Indexes
    #ErrorDocument 403 /error/noindex.html
#</LocationMatch>

啟用Apache時若有出現Could not reliably determine the server's fully qualified domain name訊息,請修改如下之檔案內容
vi /etc/httpd/conf/httpd.conf
ServerName  localhost:80    #新增加這一項參數

安裝及設定php

安裝php套件

安裝PHP相關套件(套件來源使用remi與EPEL),並設定於開機時自動啟用,請參考以下步驟進行設定。
rpm -ivh http://mirror01.idc.hinet.net/EPEL/6/x86_64/epel-release-6-8.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

yum install --enablerepo=remi php
yum install --enablerepo=remi php-mysql
yum install --enablerepo=remi php-mbstring
yum install --enablerepo=remi php-mcrypt

重新啟動Apache Server。
/etc/init.d/httpd restart

設定php.ini檔案

編輯 /etc/php.ini檔案,設定以下參數
vi /etc/php.ini 
修改為: max_execution_time = 300 修改為: max_input_time = 600 修改為: post_max_size = 800M 修改為: upload_max_filesize = 800M 修改為: default_charset="utf8" 修改為: default_socket_timeout = 300 修改為: short_open_tag = On 修改為: date.timezone = "Asia/Taipei"

安裝及設定MariaDB資料庫

設定MariaDB的來源碼

編輯 /etc/yum.repos.d/mariadb.repo檔案,若是32位元系統請根據以下方式設定
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/5.5/centos6-x86
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

若為64位元系統請根據以下方式設定
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/5.5/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

安裝MariaDB

安裝MariaDB相關套件,並設定於開機時自動啟用,請參考以下步驟進行設定。
yum install MariaDB-devel MariaDB-client MariaDB-server  MariaDB-common MariaDB-shared MariaDB-devel

service mysql start

駐: 安裝後啟動MariaDB,MariaDB的服務稱為mysql,與MySQL服務名稱(mysqld)不同

設定MariaDB自動啟動

chkconfig --level 345 mysql on
chkconfig --list mysql

MariaDB 設定檔的位置位於/etc/my.cnf.d

my.cnf.d目錄中有兩個檔案,mysql-clients.cnf和server.cnf檔案,可將設定檔之範例檔案拷貝至my.cnf.d/目錄中,範例檔位於 /usr/share/mysql/ 目錄中,可根據主機的記憶體規格選擇合適的設定檔
  • my-innodb-heavy-4G.cnf: 適合大於 4GB RAM的伺服器使用。
  • my-huge.cnf: 適合 1GB – 2GB RAM的伺服器使用。
  • my-large.cnf: 適合 512MB RAM的伺服器使用。
  • my-medium.cnf: 適合64MB~512 RAM 的伺服器使用。
  • my-small.cnf: 適合記憶體小於 64MB的伺服器。

拷貝範例設定檔至/etc/my.cnf.d/目錄中,命名為mysql-clients.cnf
cp /usr/share/mysql/my-huge.cnf /etc/my.cnf.d/mysql-clients.cnf
service mysql restart

修改/etc/my.cnf.d/mysql-clients.cnf檔案,設定資料庫預設的字元碼為UTF8

init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake

重新啟動 MariaDB Server
/etc/init.d/mysql restart

設定MariaDB root帳號之密碼

/usr/bin/mysqladmin -u root password '新密碼'

安裝及設定phpMyAdmin

下載phpMyAdmin-4.0.10.1-all-languages.tar.gz並安裝

解壓縮phpMyAdmin-4.0.10.1-all-languages
tar -zxvf phpMyAdmin-4.0.10.1-all-languages.tar.gz

搬移 phpMyAdmin-4.0.10.1-all-languages目錄到/usr/share,並修改名稱為phpMyAdmin-4.0.10.1
mv phpMyAdmin-4.0.10.1-all-languages /usr/share/phpMyAdmin-4.0.10.1

複製範本設定檔 config.sample.inc.php 並重新命名為 config.inc.php
cd /usr/share/phpMyAdmin-4.0.10.1
cp config.sample.inc.php config.inc.php

修改 phpMyAdmin 的認證方式,請編輯config.inc.php檔案,重新啟動 Apache
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'cookies';
/etc/init.d/httpd restart

修改config.inc.php檔案的權限
chmod 644 config.inc.php

移除setup安裝資料夾
mv setup setup.org

設定phpMyAdmin網站別名(可視情況設定)

編輯 /etc/httpd/conf/httpd.conf 檔案

#Set Virtual Host
Alias /mysqladm "/usr/share/phpMyAdmin-4.0.10.1"
<Directory "/usr/share/phpMyAdmin-4.0.10.1">
  Options -Indexes FollowSymLinks
  AllowOverride None
  Order allow,deny
  Allow from all
</Directory>

開啟瀏覽器輸入http://您的IP/mysqladm將會看到phpMyAdmin登入網頁,輸入使用者名稱及密碼後即可開始管理MySQL資料庫

0 意見:

張貼留言