一個不寫博客的運維,不是一個好開發(fā)
在沾益等地區(qū),都構建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務理念,為客戶提供成都網(wǎng)站建設、網(wǎng)站制作 網(wǎng)站設計制作按需制作網(wǎng)站,公司網(wǎng)站建設,企業(yè)網(wǎng)站建設,成都品牌網(wǎng)站建設,營銷型網(wǎng)站,成都外貿(mào)網(wǎng)站建設公司,沾益網(wǎng)站建設費用合理。
1、安裝centos6.5操作系統(tǒng)
2、下載nginx,www.nginx.org
3、下載php,www.php.net
3.2、下載libmcrypt http://pan.baidu.com/s/1mhHxXzU
4、下載mariadb,downloads.mariadb.org
4.1、下載cmake(MySQL編譯工具) http://www.cmake.org/files/v2.8/cmake-2.8.8.tar.gz
5、關閉selinux
selinux三個狀態(tài),用getenforce命令查看,disable(關閉)permissive(寬松)enforcing(強迫)
setenforce 0,使其暫時變?yōu)閷捤赡J?/p>
vi /etc/selinux/config
屏蔽所有行,加上
SELINUX=disable
6、關閉防火墻
service iptables stop(臨時關閉)
chkconfig iptables off(使其下次重啟為關閉狀態(tài))
7、安裝編譯工具和庫文件
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
8、安裝cmake
tar zxvf cmake-2.8.8.tar.gz
cd cmake-2.8.8
./configure
make
make install
9、安裝mysql
groupadd mysql #添加mysql組
useradd -g mysql mysql -s /bin/false #創(chuàng)建用戶mysql并加入到mysql組,不允許mysql用戶直接登錄系統(tǒng)
mkdir -p /data/mysql #創(chuàng)建MySQL數(shù)據(jù)庫存放目錄
chown -R mysql:mysql /data/mysql #設置權限
mkdir -p /usr/local/mysql #創(chuàng)建安裝目錄
tar zxvf mysql-5.5.37.tar.gz
cd mysql-5.5.37
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc #指定安裝目錄,大家都懂;指定datadir,目前我還沒有發(fā)現(xiàn)其有什么意義,因為后面還要配置;指定/etc,會使mysql/bin下的一些腳本執(zhí)行的時候,讀取這個位置的my.cnf,但是啟動腳本貌似不會讀取,反正我是配置了my.cnf的datadir,但是啟動腳本還是報錯,在啟動腳本里配置了datadir就不報錯了
make #編譯
make install #安裝
cd /usr/local/mysql
cp ./support-files/my-huge.cnf /etc/my.cnf #拷貝配置文件(注意:/etc目錄下面默認有一個my.cnf,直接覆蓋即可)
vi /etc/my.cnf #編輯配置文件,在 [mysqld] 部分增加
datadir = /data/mysql #添加MySQL數(shù)據(jù)庫路徑(這里加路徑,是因為很多mysql的腳本會讀取這個文件,例如下一句執(zhí)行的腳本;不管這里加不加路徑,不會影響mysql啟動,因為啟動腳本里面都必須要加)
./scripts/mysql_install_db --user=mysql #生成mysql系統(tǒng)數(shù)據(jù)庫(生成三個系統(tǒng)數(shù)據(jù)庫,如果上一句沒有加路徑,這一句也沒有指定路徑,會生成到默認目錄./mysql/data)
cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld #把Mysql加入系統(tǒng)啟動
chmod 755 /etc/init.d/mysqld #增加執(zhí)行權限
chkconfig mysqld on #加入開機啟動(這一步會直接加入系統(tǒng)服務,再加入開機啟動;如果只想加入系統(tǒng)服務,可以用chkconfig --add mysqld)
vi /etc/rc.d/init.d/mysqld #編輯
basedir = /usr/local/mysql #MySQL程序安裝路徑
datadir = /data/mysql #MySQl數(shù)據(jù)庫存放目錄(這個是必須要加的,不管my.cnf里面加沒加)
service mysqld start #啟動
以下內(nèi)容可以先不做
vi /etc/profile #把mysql服務加入系統(tǒng)環(huán)境變量:在最后添加下面這一行,重啟系統(tǒng)后生效(可以不加)
export PATH=$PATH:/usr/local/mysql/bin
下面這兩行把myslq的庫文件鏈接到系統(tǒng)默認的位置,這樣你在編譯類似PHP等軟件時可以不用指定mysql的庫文件地址(可以不加)
ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
ln -s /usr/local/mysql/include/mysql /usr/include/mysql
shutdown -r now #需要重啟系統(tǒng),等待系統(tǒng)重新啟動之后繼續(xù)在終端命令行下面操作(可以先不重啟,操作指定腳本位置)
mysql_secure_installation #設置Mysql密碼(我一般用第二種,也可以先不修改)
根據(jù)提示按Y 回車輸入2次密碼
或者直接修改密碼/usr/local/mysql/bin/mysqladmin -u root -p password "123456" #修改密碼
service mysqld restart #重啟
10、安裝nginx
cd /usr/local/src
groupadd www
useradd -g www www -s /bin/false
tar zxvf nginx-1.5.13.tar.gz
cd nginx-1.5.13
./configure --prefix=/usr/local/nginx --without-http_memcached_module --user=www --group=www --with-http_stub_status_module --with-openssl=/usr/ --with-pcre=/usr/local/src/pcre-8.35
make
make install
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf #啟動nginx,也可以用下面的腳本,非必須
#設置nginx自啟動,加入以下腳本
vi /etc/init.d/nginx
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/run/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 $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
reload() {
echo -n $"Reloading $prog: "
#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
chmod 775 /etc/rc.d/init.d/nginx
chkconfig nginx on
/etc/rc.d/init.d/nginx restart
service nginx restart
11、安裝 libmcrypt
cd /usr/local/src
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make
nake install
11.2.安裝php
cd /usr/local/src
tar -zvxf php-5.5.10.tar.gz
cd php-5.5.10
mkdir -p /usr/local/php5
./configure --prefix=/usr/local/php5 --with-config-file-path=/usr/local/php5/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-gd --with-iconv --with-zlib --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-pear --with-gettext --enable-session --with-mcrypt --with-curl
make
make install
cp php.ini-production /usr/local/php5/etc/php.ini
rm -rf /etc/php.ini
ln -s /usr/local/php5/etc/php.ini /etc/php.ini
cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf
vi /usr/local/php5/etc/php-fpm.conf
user = www #設置php-fpm運行賬號為www
group = www #設置php-fpm運行組為www
pid = run/php-fpm.pid #取消前面的分號
cp /usr/local/src/php-5.5.10/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm#拷貝php-fpm到啟動目錄
chmod +x /etc/rc.d/init.d/php-fpm #添加執(zhí)行權限
chkconfig php-fpm on #設置開機啟動
vi /usr/local/php5/etc/php.ini #編輯配置文件
修改為:date.timezone = PRC #設置時區(qū)
12、配置nginx支持php
vi /usr/local/nginx/conf/nginx.conf #編輯配置文件,需做如下修改
user www www; #首行user去掉注釋,修改Nginx運行組為www www;必須與/usr/local/php5/etc/php-fpm.conf中的user,group配置相同,否則php運行出錯
index index.php index.html index.htm; #添加index.php
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#取消FastCGI server部分location的注釋,并要注意fastcgi_param行的參數(shù),改為
$document_root$fastcgi_script_name,或者使用絕對路徑
/etc/init.d/nginx restart #重啟nginx
13、測試
cd /usr/local/nginx/html/ #進入nginx默認網(wǎng)站根目錄
rm -rf /usr/local/nginx/html/* #刪除默認測試頁
vi index.php #編輯
phpinfo();
chown www.www /usr/local/nginx/html/ -R #設置目錄所有者
chmod 700 /usr/local/nginx/html/ -R #設置目錄權限
shutdown -r now #重啟系統(tǒng)
14、相關命令
service nginx restart #重啟nginx
service mysqld restart #重啟mysql
/usr/local/php5/sbin/php-fpm #啟動php-fpm
/etc/rc.d/init.d/php-fpm restart #重啟php-fpm
/etc/rc.d/init.d/php-fpm stop #停止php-fpm