CentOS6.6 32位 Minimal版本純編譯安裝Nginx Mysql PHP Memcached

來源:互聯網
上載者:User

標籤:centos6   nginx   memcached   mysql   php5   

CentOS是紅帽發行的免費的穩定Linux版本,在企業伺服器應用中都會選用Minimal版本,因為Minimal是CentOS”最純潔”的伺服器系統,因為Minimal版本連vim編輯器都需要自己安裝,Minimal組件最少,無案頭,擴充靈活,非常適合做伺服器。

1.配置網卡

Minimal版本的CentOS被安裝後,網卡驅動預設是down狀態,需要手動啟用,在串連好網線後需要執行命令:
[[email protected] soft]# vi /etc/sysconfig/network-scripts/ifcfg-eth0

然後按i進入編輯狀態,進行如下修改:

修改完畢後,按ESC,然後shift+:,wq進行儲存退出。

然後開始配置DNS伺服器位址:

[[email protected] soft]# vi /etc/resolv.conf

最主要的是配置nameserver屬性,可以是自己的網關地址,如所示:

修改完畢後儲存退出。鍵入以下命令啟用網卡:

[[email protected] soft]# ifconfig eth0 up

至此,網卡已經配置好了,如果仍然發現開機網卡未啟動等問題,可以執行以下兩條命令進行完善。

[[email protected] soft]# chkconfig –add network
[[email protected] soft]# chkconfig network on

重啟網卡命令:

2.配置防火牆,開放22(SSH),3306(Mysql),80(Nginx),11211(Memcached),6379(Redis)連接埠
[[email protected] soft]# vi /etc/sysconfig/iptables
修改為:

重啟防火牆使配置生效:
[[email protected] soft]# /etc/init.d/iptables restart

3.安裝組件
更新系統:
[[email protected] soft]# yum update
稍後鍵入y進行確認。

安裝vim:
[[email protected] soft]# yum install vim

安裝編譯工具及依賴:
[[email protected] soft]# yum install make apr* autoconf automake curl-devel gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel gd kernel keyutils patch perl kernel-headers compat* mpfr cpp glibc libgomp libstdc++-devel ppl cloog-ppl keyutils-libs-devel libcom_err-devel libsepol-devel libselinux-devel krb5-devel zlib-devel libXpm* freetype libjpeg* libpng* php-common php-gd ncurses* libtool* libxml2 libxml2-devel patch

4.下載Cmake,Mysql,PHP,Nginx,libevent,libmcrypt,pcre,memcached
如果自己尋找這些很困難,推薦給大家幾個很好的源地址:
阿里:http://mirrors.aliyun.com/
搜狐:http://mirrors.sohu.com/
網易:http://mirrors.163.com/

我的就是在搜狐下載的,版本如下:

5.系統約定
軟體原始碼包存放位置:/usr/local/src
源碼包編譯安裝位置:/usr/local/軟體名字

源碼放在/usr/local/src的實現方案有多種,可以在Windows下載,然後通過Xftp傳送至指定目錄,也可以cd到指定目錄,wget ; 進行下載。

6.正式編譯安裝

安裝Mysql:

Mysql需要Cmake進行編譯安裝,所以在安裝Mysql前必須先安裝Cmake


解壓Cmake:
[[email protected] src]# tar xzvf cmake-3.1.1.tar.gz

進入cmake解壓後目錄:
[[email protected] src]# cd cmake-3.1.1

先行編譯,這個過程可能需要一段時間:
[[email protected] cmake-3.1.1]# ./configure

編譯並安裝:
[[email protected] cmake-3.1.1]# make && make install

添加mysql組
[[email protected] cmake-3.1.1]# groupadd mysql

建立使用者mysql並加入到mysql組,不允許mysql使用者直接登入系統
[[email protected] cmake-3.1.1]# useradd -g mysql mysql -s /bin/false

建立MySQL資料庫存放目錄
[[email protected] cmake-3.1.1]# mkdir -p /data/mysql

設定MySQL資料庫存放目錄許可權
[[email protected] cmake-3.1.1]# chown -R mysql:mysql /data/mysql

建立MySQL安裝目錄
[[email protected] cmake-3.1.1]# mkdir -p /usr/local/mysql

返回/usr/local/src目錄:
[[email protected]jhq0113 cmake-3.1.1]# cd /usr/local/src

解壓mysql:
[[email protected] src]# tar xzvf mysql-5.6.13.tar.gz

進入mysql解壓目錄:
[[email protected] src]# cd mysql-5.6.13

用Cmake先行編譯Mysql,此過程可能需要一段時間:
[[email protected] mysql-5.6.13]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc/

編譯:
[[email protected] mysql-5.6.13]# make

安裝:
[[email protected] mysql-5.6.13]# make install

拷貝設定檔(如果/etc目錄下面預設有一個my.cnf,直接覆蓋即可):
[[email protected] support-files]# cp /usr/local/mysql/support-files/my-default.cnf /etc/init.d/my.cnf

添加Mysql路徑:
[[email protected] support-files]# vim /etc/my.cnf

修改後:

產生Mysql系統資料庫:
[[email protected] support-files]# /usr/local/mysql/scripts/mysql_install_db –user=mysql –basedir=/usr/local/mysql –datadir=/data/mysql

把Mysql加入系統啟動:
[[email protected] support-files]# cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld

增加mysqld執行許可權:
[[email protected] support-files]# chmod 755 /etc/init.d/mysqld

mysqld加入開機啟動:
[[email protected] support-files]# chkconfig mysqld on

編輯設定檔:
[[email protected] support-files]# vim /etc/init.d/mysqld

修改後:

把Mysql服務加入系統內容變數:
[[email protected] support-files]# vim /etc/profile

修改後:

將myslq的庫檔案連結到系統預設的位置,以確保在編譯類似PHP等軟體時可以不用指定mysql的庫檔案地址。
[[email protected] support-files]# ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
[[email protected] support-files]# ln -s /usr/local/mysql/include/mysql /usr/include/mysql

重啟系統:
reboot

建立串連:
[[email protected] ~]# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

重啟Mysqld:
[[email protected] ~]# service mysqld restart

設定Mysql密碼:
[[email protected] support-files]# /usr/local/mysql/bin/mysql_secure_installation

修改root密碼:

預設沒有密碼,直接斷行符號,然後輸入兩次密碼,一路按Y 斷行符號下去

設定Mysql可以遠程登入:
[[email protected] ~]# mysql -uroot -p

輸入密碼登入,然後執行下面的語句,限制Mysql root使用者可以在指定Ip地址下遠程登入
mysql> grant all privileges on . to ‘root’192.168.1.*’%’ identified by ‘你的密碼’;

更新許可權:
mysql> flush privileges;

退出:
mysql> exit;

這樣你的Mysql就可以在192.168.1.*內用Navicat進行遠程登入了。

至此,Mysql安裝完畢。

安裝Nginx:
安裝Nginx之前需要安裝pcre,進入/usr/local/src目錄,解壓pcre,進入pcre解壓目錄,執行以下命令進行編譯安裝:
[[email protected] pcre-8.35]# ./configure –prefix=/usr/local/pcre && make && make install

建立web組合web使用者,不允許web使用者直接登入系統:
[[email protected] pcre-8.35]# groupadd web
[[email protected] pcre-8.35]# useradd -g web web -s /bin/false

編譯安裝nginx,解壓,進入安裝目錄,執行以下命令:
[[email protected] nginx-1.7.0]# ./configure –prefix=/usr/local/nginx –without-http_memcached_module –user=web –group=web –with-http_stub_status_module –with-openssl=/usr/ –with-pcre=/usr/local/src/pcre-8.35
注意:–with-pcre=/usr/local/src/pcre-8.31指向的是源碼包解壓的路徑,而不是安裝的路徑,否則會報錯

編譯安裝:
[[email protected] nginx-1.7.0]# make && make install

編輯Nginx啟動命令:
[[email protected] nginx-1.7.0]# vim /etc/init.d/nginx

加入下面內容:

!/bin/bashnginx Startup script for the Nginx HTTP Serverit is v.0.0.2 version.chkconfig: - 85 15description: Nginx is a high-performance web and proxy server.It has a lot of features, but it’s not for everyone.processname: nginxpidfile: /var/run/nginx.pidconfig: /usr/local/nginx/conf/nginx.conf

nginxd=/usr/local/nginx/sbin/nginx

nginx_config=/usr/local/nginx/conf/nginx.conf

nginx_pid=/usr/local/nginx/logs/nginx.pid

RETVAL=0

prog=”nginx”

Source function library.

. /etc/rc.d/init.d/functions

Source networking configuration.

. /etc/sysconfig/network

Check that networking is up.

[ ${NETWORKING} = “no” ] && exit 0

[ -x $nginxd ] || exit 0

Start nginx daemons functions.

start() {

if [ -e $nginx_pid ];then

echo “nginx already running….”

exit 1

fi

echo -n "Startingprog: “

daemon nginxd?c{nginx_config}

RETVAL=$?

echo

[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx

return $RETVAL

}

Stop nginx daemons functions.

stop() {

echo -n "Stoppingprog: “

killproc $nginxd

RETVAL=$?

echo

[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid

}

reload() {

echo -n "Reloadingprog: “

kill -HUP cat ${nginx_pid}

killproc $nginxd -HUP

RETVAL=$?

echo

}

See how we were called.

case “$1” in

start)

start

;;

stop)

stop

;;

reload)

reload

;;

restart)

stop

start

;;

status)

status $prog

RETVAL=$?

;;

*)

echo "Usage:prog {start|stop|restart|reload|status|help}”

exit 1

esac

exit $RETVAL

賦予nginx執行許可權:
[[email protected] nginx-1.7.0]# chmod 775 /etc/init.d/nginx

設定nginx開機啟動:
[[email protected] nginx-1.7.0]# chkconfig nginx on

啟動nginx:
[[email protected] nginx-1.7.0]# service nginx start

測試Nginx安裝和啟動狀態:

至此,Nginx安裝完畢,待安裝好PHP後再做對PHP的支援和指定自訂發布目錄設定。

建立web目錄:
[[email protected] nginx-1.7.0]# mkdir -p /home/data/web

未完待續!

CentOS6.6 32位 Minimal版本純編譯安裝Nginx Mysql PHP Memcached

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.