CentOS6.5下搭建LAMP環(huán)境源碼編譯方式

上傳人:痛*** 文檔編號:45039166 上傳時間:2021-12-06 格式:DOC 頁數(shù):19 大?。?78.50KB
收藏 版權(quán)申訴 舉報 下載
CentOS6.5下搭建LAMP環(huán)境源碼編譯方式_第1頁
第1頁 / 共19頁
CentOS6.5下搭建LAMP環(huán)境源碼編譯方式_第2頁
第2頁 / 共19頁
CentOS6.5下搭建LAMP環(huán)境源碼編譯方式_第3頁
第3頁 / 共19頁

下載文檔到電腦,查找使用更方便

0 積分

下載資源

還剩頁未讀,繼續(xù)閱讀

資源描述:

《CentOS6.5下搭建LAMP環(huán)境源碼編譯方式》由會員分享,可在線閱讀,更多相關(guān)《CentOS6.5下搭建LAMP環(huán)境源碼編譯方式(19頁珍藏版)》請在裝配圖網(wǎng)上搜索。

1、CentOS 6.4安裝配置LAMP服務(wù)器(Apache+PHP5+MySQL)學(xué)習(xí)PHP腳本編程語言之前,必須先搭建并熟悉開發(fā)環(huán)境,開發(fā)環(huán)境有很多種,例如LAMP ,WAMP,MAMP等。這里我介紹一下LAMP環(huán)境的搭建,即Linux、 Apache、 MySQL 、PHP環(huán)境。一、首先安裝操作系統(tǒng)操作系統(tǒng):centos6.5操作系統(tǒng)安裝步驟,此處不再詳述。備注:服務(wù)器系統(tǒng)采用最小化安裝,安裝一下GCC編譯工具和一個桌面即可。如下圖所示:由于安裝系統(tǒng)的時候我是最小化安裝,只安裝了一個桌面,GCC編譯工具也是系統(tǒng)裝完之后安裝的,所以沒有默認的LAMP環(huán)境,如下圖示:如果安裝的時候有選擇默認全部

2、安裝,就已經(jīng)安裝了LAMP環(huán)境,但是相對版本較低,而且安裝的路徑等可能不是我們想要的結(jié)果。所以這里順便介紹一下,如果存在默認的LAMP環(huán)境,進行卸載的方法,以apache為例:#rpm -qa | grep -i httd/ 查詢系統(tǒng)中已安裝的Apache相關(guān)軟件包#service httpd stop/如果 apache已開啟,停止運行apache服務(wù)器#rpm -e httpd-xxx -nodeps /卸載 apache服務(wù)器php、 mysql卸載方法同上。【搭建LAMP環(huán)境須知】搭建LAMP環(huán)境時,需要安裝的所有軟件都要按照一定的順序安裝,我們按照Apache-MySQL-PHP的順

3、序安裝。但是在安裝PHP之前,應(yīng)先安裝PHP5需要的最新版本庫文件,例如libxml2、libmcrypt,以及GD2庫等文件。安裝GD2庫是為了讓PHP5支持 GIF、PNG和JPEG圖片格式,所以在安裝GD2庫之前還要先安裝最新的zlib、libpng、freetype和jpegsrc等庫文件。而且中間還會穿插安裝一些軟件。二、LAMP安裝前的準備1、獲取軟件包httpd-2.4.9.tar.gzhttp:/httpd.apache.org/mysql-5.7.4.tar.gzphp-5.5.14.tar.gz phpMyAdmin-4.2.5-all-languages.tar.gzli

4、bxml2-2.9.0.tar.gz ftp:/xmlsoft.org/libxml2/libmcrypt-2.5.8.tar.gzftp:/mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libgd-2.1.0.tar.gzhttps:/bitbucket.org/libgd/gd-libgd/downloadszlib-1.2.8.tar.gzautoconf-2.69.tar.gzhttp:/ftp.gnu.org/gnu/autoconf/freetype-2.5.3.tar.gzhttp:/download.savannah.gnu.org/

5、releases/freetype/libpng-1.6.12.tar.gzftp:/ftp.simplesystems.org/pub/libpng/png/src/jpegsrc.v9a.tar.gzhttp:/www.ijg.org/files/ZendGuard-5_5_0.tar.gzapr-1.5.1.tar.gz http:/apr.apache.org/download.cgiapr-util-1.5.3.tar.gz http:/apr.apache.org/download.cgipcre-8.35.zip 把上面下載的16個源代碼包放到linux系統(tǒng)下的/usr/loca

6、l/src/LAMP目錄中2、編譯工具安裝如果安裝系統(tǒng)的時候已經(jīng)安裝了GCC編譯工具,則顯示上圖中的信息,如果沒有安裝,可以使用下面的方法進行安裝:檢查是否安裝:rootcentos6 # rpm -q make gcc gcc-c+zlib-devellibaio備注:安裝libpng時候需要zlib-devel安裝mysql時候需要libaio如果沒安裝則yum安裝:rootcentos6 # yum -y install make gcc gcc-c+zlib-devel libaio3、配置防火墻,開啟80端口、3306端口編輯/etc/sysconfig/iptables文件,配置防

7、火墻rootcentos6 # vi /etc/sysconfig/iptables添加下面兩句,開啟相應(yīng)端口:-A INPUT -m state -state NEW -m tcp -p tcp -dport 80 -j ACCEPT #允許80端口通過防火墻-A INPUT -m state -state NEW -m tcp -p tcp -dport 3306 -j ACCEPT #允許3306端口通過防火墻備注:很多網(wǎng)友把這兩條規(guī)則添加到防火墻配置的最后一行,導(dǎo)致防火墻啟動失敗,正確的應(yīng)該是添加到默認的22端口這條規(guī)則的下面如下所示:# 添加好之后防火墻規(guī)則如下所示 # Firewa

8、ll configuration written by system-config-firewall# Manual customization of this file is not recommended.*filter:INPUT ACCEPT 0:0:FORWARD ACCEPT 0:0:OUTPUT ACCEPT 0:0-A INPUT -m state -state ESTABLISHED,RELATED -j ACCEPT-A INPUT -p icmp -j ACCEPT-A INPUT -i lo -j ACCEPT-A INPUT -m state -state NEW -

9、m tcp -p tcp -dport 22 -j ACCEPT-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-A INPUT -j REJECT -reject-with icmp-host-prohibited-A FORWARD -j REJECT -reject-with icmp-host-prohibitedCOMMIT# 添加好之后防火墻規(guī)則如上所示 #最后重啟防火墻使配置生效

10、rootcentos6 # /etc/init.d/iptables restart 4、關(guān)閉SELINUX編輯/etc/selinux/config文件rootcentos6 # vi /etc/selinux/config詳細修改如下所示:#SELINUX=enforcing #注釋掉#SELINUXTYPE=targeted #注釋掉SELINUX=disabled #增加:wq #保存,關(guān)閉rootcentos6 #shutdown -r now #重啟系統(tǒng)三、開始搭建LAMP環(huán)境安裝時的主要步驟:(1)解壓tar.gz為后綴的壓縮包軟件LAMP環(huán)境搭建所需要的每個軟件的源代碼文件,都

11、是以.tar.gz提供給我們的打包壓縮文件,所以我們必須將其解壓再解包。可通過命令#tar zxvf tarfile.tar.gz達到目的。(2)在linux系統(tǒng)中源代碼包安裝過程進行解壓后的目錄,LAMP環(huán)境搭建所需要的軟件都使用C語言開發(fā)的,所以安裝源代碼文件最少需要配置(configure)、編譯(make)、安裝(make install)三個步驟。1、確認搭建LAMP所需要的環(huán)境是否已經(jīng)安裝此步驟前面已經(jīng)完成。2、編譯安裝libxml2注:libxml2是一個xml的c語言版的解析器,不僅支持c語言,還支持c+、php、Pascal、Ruby、Tcl等語言的綁定rootcentos6

12、 LAMP# pwd/usr/local/src/LAMProotcentos6 LAMP# tar -zxvf libxml2-2.7.8.tar.gzrootcentos6 LAMP# cd ./libxml2-2.7.8rootcentos6 libxml2-2.7.8# ./configure -prefix=/usr/local/libxml2/rootcentos6 libxml2-2.7.8# makerootcentos6 libxml2-2.7.8# make install注:選項-prefix=/usr/local/libxml2作用是將軟件安裝到/usr/local/l

13、ibxml2 目錄下。如果安裝成功以后,在/usr/local/libxml2/目錄下將生成bin,include,lib,share四個目錄。在后面安裝 PHP5源代碼的配置時,會通過在configure命令的選項中加上-with-libxml-dir=/usr/local/libxml2選項,用于指定安裝libxml2庫文件的位置。3、編譯安裝libmcrypt注:libmcrypt是加密算法擴展庫。支持DES, 3DES, RIJNDAEL, Twofish, IDEA, GOST, CAST-256, ARCFOUR, SERPENT, SAFER+等算法。rootcentos6 LA

14、MP# pwd/usr/local/src/LAMProotcentos6 LAMP# tar -zxvf libmcrypt-2.5.8.tar.gzrootcentos6 LAMP# cd ./libmcrypt-2.5.8rootcentos6 libmcrypt-2.5.8# ./configure -prefix=/usr/local/libmcrypt/rootcentos6 libmcrypt-2.5.8# make;make install如果安裝成功就會在/usr/local/libmcrypt/目錄下生成bin,include,lib,man,share五個目錄。然后在安

15、裝PHP5源代碼包的配置時,就可以通過configure命令加上“-with-mcrypt-dir=/usr/local/libmcrypt” 選項,指定這個libmcrypt庫文件的位置。如./configure時報錯:configure: error: C+ compiler cannot create executables 。解決方案:運行下面命令,然后重新configure(配置)yum install gcc gcc-c+ gcc-g77安裝完成libmcrypt庫以后,不同的linux系統(tǒng)版本有可能還要安裝一下libltdl庫。安裝方法和前面的步驟相同,可以進入到解壓縮的 目錄/

16、usr/local/src/libmcrypt-2.5.8下,找到libltdl庫源代碼所在的目錄libltdl,進入這個目錄按照下面幾個 命令配置、編譯、安裝就可以了。rootlocalhost libltdl# pwd/usr/local/src/libmcrypt-2.5.8/libltdl/進入軟件源代碼目錄rootlocalhost libltdl# ./configure enable-ltdl-install/配置ltdl庫的安裝rootlocalhost libltdl# make/編譯rootlocalhost libltdl# make install/安裝4、編譯安裝zl

17、ib注:zlib是提供數(shù)據(jù)壓縮用的函式庫rootcentos6 LAMP# pwd/usr/local/src/LAMProotcentos6 LAMP# tar -zxvf zlib-1.2.5.tar.gzrootcentos6 LAMP# cd ./zlib-1.2.5rootcentos6 zlib-1.2.5# ./configure -prefix=/usr/local/zlib/rootcentos6 zlib-1.2.5# make ; make install如果安裝成功將會在/usr/local /zlib目錄下生成include,lib,share三個目錄。在安裝PHP5

18、配置時,在configure命令的選項中加上“-with- zlib-dir=/usr/local/libmcrypt”選項,用于指定zlib庫文件位置。5、編譯安裝libpngrootcentos6 LAMP# pwd/usr/local/src/LAMProotcentos6 LAMP# tar -zxvf libpng-1.5.4.tar.gzrootcentos6 LAMP# cd ./libpng-1.5.4rootcentos6 libpng-1.5.4#./configure -prefix=/usr/local/libpng/ -enable-sharedrootcentos6

19、 libpng-1.5.4# make ; make install在./configure -prefix=/usr/local/libpng這步最后會提示:configure: error: ZLib not installed解決方法如下:1)進入zlib的源文件目錄,執(zhí)行命令 make clean,清除zlib;2)重新配置 ./configure,后面不要接-prefix參數(shù);3)make & make install;4)進入libpng目錄,執(zhí)行命令 ./configure -prefix=/usr/local/libpng;5)make & make install;6)安裝成

20、功.如果安裝成功將會在/usr/local/libpng目錄下生成bin,include,lib和share四個目錄。在安裝GD2庫配置時,通 過在configure命令選項中加上“-with-png=/usr/local/libpng”選項,指定libpng庫文件的位置。6、編譯安裝jpeg注:安裝GD2庫前所需的jpeg8庫文件,需要自己手動創(chuàng)建安裝需要的目錄,它們在安裝時不能自動創(chuàng)建。rootcentos6 LAMP# pwd/usr/local/src/LAMProotcentos6 LAMP# tar -zxvf jpegsrc.v8c.tar.gzrootcentos6 LAMP#

21、 cd ./jpeg-8c/rootcentos6 jpeg-8c# mkdir /usr/local/jpeg/(創(chuàng)建jpeg軟件的安裝目錄)rootcentos6 jpeg-8c# mkdir /usr/local/jpeg/bin/(創(chuàng)建存放命令的目錄)rootcentos6 jpeg-8c# mkdir /usr/local/jpeg/lib/(創(chuàng)建jpeg庫文件所在目錄)rootcentos6 jpeg-8c# mkdir /usr/local/jpeg/include/(創(chuàng)建存放頭文件目錄)rootcentos6 jpeg-8c# mkdir -p /usr/local/jpeg/

22、man/man1(建立存放手冊的目錄)rootcentos6 jpeg-8c# ./configure -prefix=/usr/local/jpeg/ -enable-shared -enable-static(建立共享庫使用的GNU的libtool和靜態(tài)庫使用的GNU的libtool)rootcentos6 jpeg-8c# make ; make install在安裝GD2庫配置時,可以在configure命令的選項中加上“-with-jpeg=/usr/local/jpeg8”選項,指定jpeg8庫文件的位置。安裝PHP時也要指定該庫文件的位置。7、編譯安裝freetyperootce

23、ntos6 LAMP# pwd/usr/local/src/LAMProotcentos6 LAMP# tar -zxvf freetype-2.4.6.tar.gzrootcentos6 LAMP# cd ./freetype-2.4.6rootcentos6 freetype-2.4.6#./configure -prefix=/usr/local/freetype/ -enable-sharedrootcentos6 freetype-2.4.6# make ;make install如果安裝成功將會在/usr/local/freetype目錄下存在bin,include,lib和sha

24、re四個目錄。并在安裝GD2庫時,通過configure命令選項中加上“-with-freetype=/usr/local/freetype/”選項,指定freetype庫文件位置。8、編譯安裝autoconf唯一注意的地方是configure時,不用指定路徑。rootcentos6 LAMP# pwd/usr/local/src/LAMProotcentos6 LAMP# tar -zxvf autoconf-2.68.tar.gzrootcentos6 LAMP# cd ./autoconf-2.68rootcentos6 autoconf-2.68# ./configurerootcen

25、tos6 autoconf-2.68# make ; make install9、編譯安裝GDrootcentos6 LAMP# pwd/usr/local/src/LAMProotcentos6 LAMP# tar -zxvf gd-2.0.35.tar.gzrootcentos6 LAMP# cd ./gd-2.0.35rootcentos6 gd-2.0.35# ./configure /配置命令 -prefix=/usr/local/gd /指定安裝軟件的位置 -with-jpeg=/usr/local/jpeg/ /指定去哪找jpeg庫文件 -with-png=/usr/local/

26、libpng/ /指定去哪找png庫文件 -with-zlib=/usr/local/zlib/指定去哪找zlib庫文件 -with-freetype=/usr/local/freetype/指定去哪找freetype 2.x字體庫的位置rootcentos6 gd-2.0.35# make ; make install如果安裝成功會在/usr/local/gd/目錄下存在bin、include和lib這三個目錄。在安裝PHP5時,通過在configure命令選項中加上“-with-gd=/usr/local/gd”選項,指定GD庫文件的位置。如果報錯:gd_png.c 中 gdMalloc函

27、數(shù)的問題make2: * gd_png.lo Error 1make2: Leaving directory /tmp/gd-2.0.35make1: * all-recursive Error 1make1: Leaving directory /tmp/gd-2.0.35make: * all Error 2解決方案:vi gd_png.c找到#include png.h改成#include /usr/local/libpng/include/png.h如果報錯:unrecognized option with-zlib那就重新安裝一次zlib,注意,需要把原先解壓出來的源碼刪掉,重新解壓

28、進行安裝。10、安裝apache卸載apr、apr-utilrootcentos6 LAMP# yum remove apr apr-util編譯安裝apr-1.5.1.tar.gzrootcentos6 LAMP# tar zxvf apr-1.5.1.tar.gzrootcentos6 LAMP# cd apr-1.5.1rootcentos6 apr-1.5.1# ./configure -prefix=/usr/local/apr-httpd/ & make & make install編譯安裝apr-util-1.5.3.tar.gzrootcentos6 LAMP# tar zxv

29、f apr-util-1.5.3.tar.gzrootcentos6 LAMP# cd apr-util-1.5.1rootcentos6 apr-util-1.5.3# ./configure -prefix=/usr/local/apr-util-httpd/ -with-apr=/usr/local/apr-httpd/ & make & make install編譯安裝pcre-8.35.ziprootcentos6 LAMP# unzip -o pcre-8.35.ziprootcentos6 LAMP# cd pcre-8.35rootcentos6 pcre-8.35# ./co

30、nfigure -prefix=/usr/local/pcrerootcentos6 pcre-8.35# makerootcentos6 pcre-8.35# make install編譯安裝apacherootcentos6 LAMP# tar zxvf httpd-2.4.9.tar.gzrootcentos6 LAMP# cd httpd-2.4.9rootcentos6 httpd-2.4.9# ./configure -prefix=/usr/local/apache249 -enable-mods-shared=all -enable-deflate -enable-spelin

31、g -enable-cache -enable-file-cache -enable-disk-cache -enable-mem-cache -enable-so -enable-expires=shared -enable-rewrite=shared -enable-static-support -sysconfdir=/etc/httpd -with-z=/usr/local/zlib/ -with-apr=/usr/local/apr-httpd/ -with-apr-util=/usr/local/apr-util-httpd/ -with-pcre=/usr/local/pcre

32、/ -disable-userdirrootcentos6 httpd-2.4.9# make & make install安裝完成后,進入/usr/local/apache243/目錄下,檢查是否有以下文件:bin build cgi-bin error htdocs icons include logs man manual modules啟動Apache服務(wù)器,并查端口是否開啟,啟動Apache服務(wù)器的命令行如下:rootcentos6 httpd-2.4.9# /usr/local/apache249/bin/apachectl start提示信息:AH00558: httpd: Co

33、uld not reliably determine the servers fully qualified domain name, using :1. Set the ServerName directive globally to suppress this message解決方案:rootcentos6 httpd-2.4.9# vi /etc/httpd/httpd.conf加上下面一行,重啟apacheServerName localhost:80查看端口命令行如下:#netstat -tnl|grep 80tcp 0 0 0.0.0.0:80 0.0.0.0:* LIST測試安裝

34、結(jié)果,打開瀏覽器,在地址欄中輸入URL為:http:/192.168.146.129/如果瀏覽器中出現(xiàn)It works!則表明Apache服務(wù)器可以使用。每種服務(wù)器軟件都有必要制成開機時自動啟動,Apache服務(wù)器開機自動啟動,只要在“/etc/rc.d/rc.local”文件,加上 Apache服務(wù)器的啟動命令即可??梢灾苯哟蜷_“/etc/rc.d/rc.local”文件,在最后一行寫入Apache啟動命令,也可以用echo 命令追加進去,如下命令行示:rootlocalhost apache243# echo /usr/local/apache243/bin/apachectl start

35、 /etc/rc.d/rc.localrootcentos6 LAMP# /usr/local/apache/bin/apachectl startrootcentos6 LAMP# cp /usr/local/apache/bin/apachectl /etc/init.d/httpdrootcentos6 LAMP# chmod +x /etc/init.d/httpdrootcentos6 # chkconfig -add httpd注意:如果提示servicehttpddoes not support chkconfig錯誤解決辦法:編輯/etc/rc.d/init.d/httpd在文

36、件第二行加入 #chkconfig:234510 90 #description:Activates/Deactivates Apache Web Serverrootcentos6 # chkconfig -level 2345 httpd onrootcentos6 LAMP# service httpd restart開機自動啟動apache的另一種方法:修改/etc/rc.local文件# vim /etc/rc.local在文件中添加/usr/local/apache/bin/apachectl start11、編譯安裝mysql(新版本的mysql編譯)mysql版本5.5以上編譯

37、安裝時需要用到軟件cmake,cmake特性是獨立于源碼編譯,編譯工作可以在另外一個目錄中而非源碼目錄中進行,好處是可以保證源碼目錄不受任何一次編譯的影響。估計以后的版本也會采用這種方式,所以特地記錄一下安裝步驟及過程,以供參考。注意:此安裝是默認centos下已經(jīng)安裝了最新工具包,比如GNUmake,GCC,Perl,libncurses5-dev,如果在編譯安裝過程中發(fā)現(xiàn)有缺失的工具包,先yuminstall單獨下載安裝再繼續(xù)即可。以下安裝中涉及的幾點需要提前說明的問題:l 所有下載的文件將保存在/usr/local/src/目錄下l mysql將以mysql用戶運行,而且將加入servi

38、ce開機自動運行l(wèi) mysql將被安裝在/usr/local/mysql/目錄下l mysql默認安裝使用utf8字符集l mysql的數(shù)據(jù)和日志文件保存在/usr/local/mysql/data/對應(yīng)目錄下l mysql的配置文件保存于/etc/f1.下載安裝cmake下載軟件cmake-3.0.0.tar.gzhttp:/www.cmake.org/rootcentos6 # tar zxvf cmake-3.0.0.tar.gz rootcentos6 # cd cmake-3.0.0 rootcentos6 # ./bootstrap rootcentos6 # gmakerootc

39、entos6 # make & make install在使用時可能會出現(xiàn)error,若提示是/usr/bin/cmake文件不存在。解決辦法:rootcentos6 #whereis cmake得到cmke的可執(zhí)行文件的路徑,如在:/usr/local/bin/cmakerootcentos6 # ln -s /usr/local/bin/cmake /usr/bin/cmake創(chuàng)建一個鏈接文件即可解決。2.安裝ncurses-devel首先需要使用yum安裝了下ncurses-develrootcentos6 # yum y install ncurses-devel否則在下面安裝過程中會

40、出現(xiàn)缺少如下的ERROR:Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH) CMake Error at cmake/readline.cmake:83 (MESSAGE): Curses library not found. Please install appropriate package, 3.安裝mysql(1)創(chuàng)建用戶、組和目錄rootcentos6 # groupadd mysqlrootcentos6 # useradd mysql -g mysqlrootcentos6 # passwd m

41、ysql/設(shè)置密碼為:123rootcentos6 # mkdir /usr/local/mysql /創(chuàng)建安裝目錄rootcentos6 # mkdir /usr/local/mysql/data/創(chuàng)建數(shù)據(jù)倉庫目錄(不創(chuàng)建的話默認就/是這個目錄即$PREFIX_DIR/data)rootcentos6 # chown -R mysql.mysql /usr/local/mysql/(2)編譯安裝mysql-5.7.4rootcentos6 # tar zxvf mysql-5.7.4.tar.gz rootcentos6 # cd mysql-5.7.4 rootcentos6 # cmak

42、e -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql.sock /最好不要指定 -DMYSQL_DATADIR=/usr/local/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMO

43、RY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306rootcentos6 # make & make install注意:若第一次的配置錯誤,需要先刪除當前mysql源碼目錄中的CMakeCache.txt (不是cmake源碼目錄中的),然后再重新進行cmake配置。cmake參數(shù)說明:-DCMAKE_INSTALL_PREFIX= 數(shù)據(jù)庫程序安裝路徑;-DMYSQL_DATADIR= 數(shù)據(jù)庫文件存放路徑(不配置的話會默認創(chuàng)建$PREFI

44、X_DIR/data)-DMYSQL_UNIX_ADDR= 默認位置是/var/lib/mysql/mysql.sock,如果指定其他路徑,需要做一個軟鏈接,或者在配置文件f中進行設(shè)置。-DDEFAULT_CHARSET= 默認數(shù)據(jù)庫編碼-DDEFAULT_COLLATION= 默認數(shù)據(jù)庫整理編碼-DWITH_EXTRA_CHARSETS= 擴展支持編碼(all | utf8,gbk,gb2312 | none)-DWITH_MYISAM_STORAGE_ENGINE= MYISAM引擎支持(1|0)-DWITH_INNOBASE_STORAGE_ENGINE= innoDB引擎支持(1|0)

45、-DWITH_MEMORY_STORAGE_ENGINE= MEMORY引擎支持(1|0)(3)配置mysql權(quán)限設(shè)置:rootresource mysql# pwd/usr/local/mysql/mysql安裝目錄rootlocalhost mysql# chown -R root.mysql . /設(shè)置安裝目錄下所有文件的權(quán)限r(nóng)ootresource mysql# chown -R mysql.mysql ./data/data的權(quán)限r(nóng)ootresource mysql# chown -R mysql.mysql /var/lib/mysql/mysql.sock的權(quán)限修改配置文件f首先

46、查看是否存在/etc/f文件,有則直接打開編輯,否則請復(fù)制配置文件,目標路徑自己設(shè)定:rootcentos6 # cp support-files/my-f /usr/local/mysql/f修改f參數(shù),沒有則加入如下:basedir = /usr/local/mysql(不配置的話默認為$PREFIX_DIR)datadir = /usr/local/mysql/data(不配置的話默認為$PREFIX_DIR/data)log-error = /usr/local/mysql/mysql_error.log(不配置的話默認為$PREFIX_DIR/data/$hostname.err)p

47、id-file = /usr/local/mysql/mysql.pid(不配置的話默認為$PREFIX_DIR/data/$hostname.pid)user = mysqltmpdir = /tmp(不配置的話默認為/tmp)/etc/f的配置請參考下面的例子進行配置:* /etc/f配置示例 *mysqldbasedir=/usr/local/mysqldatadir=/usr/local/mysql/datasocket=/var/lib/mysql/mysql.sock/要正確配置user=mysqlport=3306# Disabling symbolic-links is rec

48、ommended to prevent assorted security riskssymbolic-links=0mysqld_safelog-error=/var/log/mysqld.logpid-file=/usr/local/mysql/data/CentOS6.5.pid/這個要配置正確* /etc/f配置示例 *注意:在/etc/f文件中的pid-file一定要設(shè)定正確,否則后面會出現(xiàn)無法登錄的情況,我在這里被耽誤來好久好久。該pid-file的路徑名在哪里,可使用下面的命令:rootcentos6 # ps aux | grep mysql會出現(xiàn)類似下面的情況,如果沒有則重新

49、啟動mysql就有了,在下面的輸出信息中找到pid-file的路徑名。root 3534 0.0 0.0 106232 1408 pts/0 S 23:40 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe -datadir=/usr/local/mysql/data -pid-file=/usr/local/mysql/data/CentOS6.5.pidmysql 3741 2.0 26.8 1248408 550728 pts/0 Sl 23:40 0:00 /usr/local/mysql/bin/mysqld -basedir=/usr/lo

50、cal/mysql -datadir=/usr/local/mysql/data -plugin-dir=/usr/local/mysql/lib/plugin -user=mysql -log-error=/var/log/mysqld.log -pid-file=/usr/local/mysql/data/CentOS6.5.pid -socket=/var/lib/mysql/mysql.sock -port=3306root 3952 0.0 0.0 103252 824 pts/3 S+ 23:41 0:00 grep mysql初始化數(shù)據(jù)庫執(zhí)行前需賦給scripts/mysql_i

51、nstall_db文件執(zhí)行權(quán)限:rootcentos6 # pwd/usr/local/mysql/mysql安裝目錄rootcentos6 # chmod 755 scripts/mysql_install_dbrootcentos6 # scripts/mysql_install_db -user=mysql -basedir=/usr/local/mysql -datadir=/usr/local/mysql/data注:basedir:mysql安裝路徑 datadir:數(shù)據(jù)庫文件儲存路徑,(-user一定要加,其他可不加,默認會是$PREFIX_DIR和$PREFIX_DIR/dat

52、a,因為-help看到說不加-user會以當前系統(tǒng)登錄用戶啟動mysql)在數(shù)據(jù)庫成功初始化之后,可以根據(jù)現(xiàn)在屏幕上的提示信息來做,先啟動mysql:/usr/local/mysql574/bin/mysqld_safe -user=mysql & /啟動mysql/usr/local/mysql574/bin/mysqladmin -version /測試下再修改root密碼:/usr/local/mysql574/bin/mysqladmin -u root password 123456設(shè)置mysqld的開機啟動rootcentos6 # cp support-files/mysql.s

53、erver /etc/init.d/mysqlrootcentos6 # chmod 755 /etc/init.d/mysqlrootcentos6 # chkconfig mysql on可使用chkconfig list | grep mysql 命令查詢剛才的設(shè)置情況。為MySQL配置環(huán)境變量將mysql的bin目錄加到PATH中,有利于以后管理和維護,在/etc/profile中加入myslq/bin,同時增加兩個別名方便操作。注:后面兩個別名不加也可以,加上以后的操作更方便。rootcentos6 # export PATH=/usr/local/mysql/bin:$PATHro

54、otcentos6 # alias mysql_start=mysqld_safe &rootcentos6 # alias mysql_stop=mysqladmin -u root -p shutdown啟動mysql服務(wù):rootcentos6 # /etc/init.d/mysql start啟動完成之后用ps -ef |grep mysql 命令查看是否啟動登陸mysql:rootcentos6 # mysql -u root -p問題 如果出現(xiàn)錯誤:MYSQL:The server quit without updating PID file。一種可能是selinux惹的禍,如果是

55、centos系統(tǒng),默認會開啟selinux。解決方法就是關(guān)閉它。rootcentos6 # vi /etc/selinux/config詳細修改如下所示:#SELINUX=enforcing #注釋掉#SELINUXTYPE=targeted #注釋掉SELINUX=disabled #增加:wq #保存,關(guān)閉rootcentos6 #shutdown -r now #重啟系統(tǒng)另外一種可能就是pid文件的路徑設(shè)置不正確,可參考上文中對pid文件的設(shè)置方法。問題 Cant connect to local Mysql server through socket /tmp/mysql.sock (

56、2)問題分析:mysql安裝之后,需要使用mysql.sock的socket文件鏈接mysql數(shù)據(jù)庫,默認的引用位置為/tmp/mysql.sock,而mysql.sock文件一般在/var/lib/mysql/路徑下,因此需要做一個軟鏈接。另外注意mysql.sock的權(quán)限屬性。解決方法:rootcentos6 # ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sockrootCentOS6 hcyj# ll /tmp/mysql.sock lrwxrwxrwx 1 mysql mysql 25 Jul 17 23:21 /tmp/mysql.sock

57、 - /var/lib/mysql/mysql.sockrootCentOS6 hcyj# ll /var/lib/mysql/mysql.sock srwxrwxrwx 1 mysql mysql 0 Jul 18 10:05 /var/lib/mysql/mysql.sock再次連接:rootcentos6 # /usr/local/mysql/bin/mysql -u root -p連接上了,問題解決。問題 若出現(xiàn)ERROR 1045 (28000): Access denied for user rootlocalhost (using password: YES(NO)) 這種情況。

58、解決方法,如下:rootcentos6 # /etc/init.d/mysql stoprootcentos6 # /usr/local/mysql/bin/mysqld_safe -user=mysql -skip-grant-tables -skip-networking &rootcentos6 # /usr/local/mysql/bin/mysql -u root mysqlmysql UPDATE user SET Password=PASSWORD(newpassword) where USER=root;/請將newpassword更換為自己設(shè)定的密碼即可,其他不變mysql FLUSH PRIVILEG

展開閱讀全文
溫馨提示:
1: 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
2: 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
3.本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
5. 裝配圖網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

相關(guān)資源

更多
正為您匹配相似的精品文檔

相關(guān)搜索

關(guān)于我們 - 網(wǎng)站聲明 - 網(wǎng)站地圖 - 資源地圖 - 友情鏈接 - 網(wǎng)站客服 - 聯(lián)系我們

copyright@ 2023-2025  zhuangpeitu.com 裝配圖網(wǎng)版權(quán)所有   聯(lián)系電話:18123376007

備案號:ICP2024067431-1 川公網(wǎng)安備51140202000466號


本站為文檔C2C交易模式,即用戶上傳的文檔直接被用戶下載,本站只是中間服務(wù)平臺,本站所有文檔下載所得的收益歸上傳人(含作者)所有。裝配圖網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對上載內(nèi)容本身不做任何修改或編輯。若文檔所含內(nèi)容侵犯了您的版權(quán)或隱私,請立即通知裝配圖網(wǎng),我們立即給予刪除!