標籤:
Nginx安裝配置
安裝nginx
系統內容:CentOS-6.3
軟體:nginx-1.7.9.tar.gz
安裝方式:源碼編譯安裝
安裝位置:/usr/local/nginx
安裝前提
在安裝nginx前,需要確保系統安裝了g++、gcc、openssl-devel、pcre-devel和zlib-devel軟體。安裝必須軟體:
[[email protected] /]#yum install gcc-c++[[email protected] /]#yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel
檢查系統安裝的Nginx:
[[email protected] /]# find -name nginx./nginx./nginx/sbin/nginx./nginx-1.7.9/objs/nginx
卸載原有的Nginx
[[email protected] /]# yum remove nginx
安裝
將安裝包檔案上傳到/usr/local/soft中執行以下操作:
[[email protected] ~]# su root[[email protected] ~]# cd /usr/local[[email protected] local]# mkdir soft[[email protected] local]# cd soft[[email protected] soft]#wget http://nginx.org/download/nginx-1.7.9.tar.gz
解壓縮
[[email protected] soft]# tar -zxv -f nginx-1.7.9.tar.gz[[email protected] soft]#lsnginx-1.7.9 nginx-1.7.9.tar.gz[root@webServer soft]# mv nginx-1.7.9 /usr/local/nginx[root@webServer soft]# rm -rf nginx-1.7.9.tar.gz
編譯安裝
[[email protected] nginx]#./configure --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/nginx.conf[root@webServer nginx]# make&&make install
安裝完成後 目錄有如下檔案:
[[email protected] nginx]# ls
auto fastcgi.conf koi-win mime.types.default scgi_paramsCHANGES fastcgi.conf.default LICENSE nginx.conf scgi_params.defaultCHANGES.ru fastcgi_params logs nginx.conf.default srcconf fastcgi_params.default Makefile objs uwsgi_paramsconfigure html man README uwsgi_params.defaultcontrib koi-utf mime.types sbin win-utf
配置
#修改防火牆配置: [[email protected] nginx]# vi + /etc/sysconfig/iptables#添加配置項 -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT#重啟防火牆 [[email protected] nginx]# service iptables restart
啟動nginx
#方法1[[email protected] nginx]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf#方法2[[email protected] nginx]# cd /usr/local/nginx/sbin[[email protected] sbin]# ./nginx
停止nginx
#查詢nginx主進程號 [[email protected] nginx]# ps -ef | grep nginx#停止進程 [[email protected] nginx]#kill -QUIT 主進程號 #快速停止 [[email protected] nginx]#kill -TERM 主進程號 #強制停止 [[email protected] nginx]# pkill -9 nginx
重啟nginx
[[email protected] nginx]# /usr/local/nginx/sbin/nginx -s reload
測試是否安裝成功
#測試連接埠 [[email protected] nginx]#netstat –na|grep 80#瀏覽器中測試 http://127.0.0.1:80
MySql安裝配置
1.通過yum安裝
#直接安裝yum源中的mysql[[email protected] ~]#yum -y install mysql-server
2.修改mysql配置
#暫修改預設編碼[[email protected] ~]#vim /etc/my.cnf添加default-character-set = utf8/var/lib/mysql #mysql資料庫的資料庫檔案存放位置/var/log/mysqld.log #mysql資料庫的日誌輸出存放位置netstat -anp #命令來查看3306連接埠是否在監聽
3.設定mysql隨系統啟動
#設定MySQL服務隨系統啟動自啟動[[email protected] ~]#chkconfig mysqld on[[email protected] ~]#chkconfig --list mysqld 確保2--5為on的狀態就行,然後啟動MySQL服務[[email protected] ~]#/etc/rc.d/init.d/mysqld start
4.設定root密碼和使用者操作
#為root使用者佈建密碼[[email protected] ~]/usr/bin/mysqladmin -u root password ‘newPassword‘#用root使用者登入MySQL伺服器[[email protected] ~]#mysql -u root -p#查看使用者資訊mysql>select user,host,password from mysql.user;#建立對test資料庫有完全操作許可權的名為userA的使用者#格式:grant select on 資料庫名.* to 使用者名稱@登入主機 identified by "密匙";mysql>grant all privileges on test.* to [email protected] identified by ‘使用者密匙‘;#建立一個可以從任何地方串連伺服器的一個完全的超級使用者userMmysql>grant all privileges on *.* to [email protected]% identified by ‘密匙‘;#刪除root的遠程授權mysql>revoke all privileges on *.* from [email protected]"%";#刪除root的遠端使用者mysql>delete from user where user="root" and host="%";#重新整理 使以上操作生效mysql>flush privileges;#修改userA的密碼為NewPasswordmysql>set password for [email protected]=password(‘NewPassword‘);#刪除匿名使用者mysql>delete from mysql.user where user=‘‘;
5.資料庫常用sql
mysql>show databases; #查看系統中所有資料庫mysql>drop database test; #刪除名為test的資料庫,不提醒mysql>mysqladmin drop test; #刪除名為test的資料庫前,有提示mysql>show variables like ‘port‘; #mysql查看開啟的連接埠mysql>create database test; #建立名為test的資料庫mysql>use test; #串連到資料庫mysql>show tables; #查看資料庫中已存在的表mysql>alter table test rename test_study; #重新命名表test為test_studymysql>describe test; #表的詳細描述
6.CentOS系統中mysqldump
#備份資料庫[[email protected] ~]mysqldump -h yourhost vi -uroot -p dbname <dbname_backup.sql#恢複資料庫[[email protected] ~]mysqldump -h yourhost -uroot -p dbname < dbname_backup.sql#如果只想Dump建表指令,則命令如下: [[email protected] ~]mysqladmin -u root -p -d databasename > a.sql#如果只想Dump插入資料的sql命令,而不需要建表命令,則命令如下:[[email protected] ~]mysqladmin -u root -p -t databasename > a.sql#那麼只想要資料,而不想要什麼sql命令時,[[email protected] ~]mysqldump -T./ phptest driver#其中,只有指定了-T參數才可以輸出純文字檔案,表示輸出資料的目錄,./表示目前的目錄,即與mysqldump同一目錄。#如果不指定driver 表,則將卸出整個資料庫的資料。每個表會產生兩個檔案,一個為.sql檔案,包含建表執行。另一個為.txt檔案,只包含資料,且沒有sql指令。
PHP安裝配置
#擷取需安裝的PHP版本[[email protected] soft]#wget http://cn2.php.net/get/php-5.6.9.tar.gz#解壓[[email protected] soft]# tar -zxvf php-5.6.9.tar.gz#編譯安裝[[email protected] soft]# cd php-5.4.26[[email protected] php-5.4.26]# ./configure --prefix=/usr/local/php --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --enable-fpm --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2[[email protected] php-5.4.26]# make&&make install
[[email protected] php-5.4.26]# cd /usr/local/php[[email protected] php]# cp php.ini-production php.ini
伺服器架設篇-----CentOS架設WWW伺服器-Nginx+Mysql+PHP