nginx編譯安裝步驟 ①. 檢查軟體安裝的系統環境 cat /etc/redhat-release uname -r ②. 安裝nginx的依賴包(pcre-devel openssl-devel) 假設不進行安裝 yum install -y pcre-devel openssl-devel ③ ...
nginx編譯安裝步驟
①. 檢查軟體安裝的系統環境
cat /etc/redhat-release
uname -r
②. 安裝nginx的依賴包(pcre-devel openssl-devel)---假設不進行安裝
yum install -y pcre-devel openssl-devel
③. 下載nginx軟體---1.10.2 複製鏈接地址(統一位置進行下載)
mkdir -p /home/oldboy/tools
cd /home/oldboy/tools
wget -q http://nginx.org/download/nginx-1.10.3.tar.gz
說明:軟體很小,用心查看一下
④. 編譯安裝軟體步驟
a. 解壓要編譯安裝的軟體(解壓軟體---配置(./configure)---做菜(編譯 make)---上菜(安裝 make install))
tar xf nginx-1.10.2.tar.gz
ps -ef |grep sshd
id www #查看用戶
uid=666(www) gid=666(www) groups=666(www)
userdel -r www #刪除虛擬用戶
useradd www -s /sbin.nologin -M #創建虛擬用戶
id www
cd nginx-1.10.2
ls (裡面的內容就是源代碼(config readme安裝說明)---預設編譯會安裝到/usr/local目錄)
useradd -s /sbin/nologin -M www <--- 創建web服務程式www用戶
./configure --prefix=/application/nginx-1.10.2 --user=www --group=www --with-http_stub_status_module --with-http_ssl_module #配置文件
echo $?
(編譯參數說明後續補充說明)
make 編譯
echo $?
make install 編譯安裝
軟體編譯過程中,利用返回值,判斷操作是否正確
echo $?
cd /application/
ln -s /application/nginx-1.10.2 /application/nginx <--- 安裝完成一個軟體要做一個軟鏈接
b. 啟動nginx軟體程式進行測試
/application/nginx/sbin/nginx
lsof -i:80
netstat -lntup|grep 80 查看80埠
瀏覽器訪問 10.0.0.8:80
至此軟體安裝完畢:
04:
③. nginx軟體使用過程中疑難雜症(參考教案說明)
· Nginx啟動的疑難雜症彙總
④. nginx軟體排查問題三部曲說明
a 在客戶端上ping伺服器端IP,檢查鏈路是否通暢
b 在客戶端上telnet伺服器端IP、埠,檢查鏈路訪問是否通暢
c 在客戶端上wget檢測模擬頁面訪問是否正常
## nginx命令說明
# nginx 啟動方法
[root@web01 application]# /application/nginx/sbin/nginx
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
[root@web01 application]#
# nginx 停止方法
[root@web01 application]# /application/nginx/sbin/nginx -s stop
[root@web01 application]# ps -ef|grep nginx
root 4283 1773 0 21:52 pts/0 00:00:00 grep --color=auto nginx
[root@web01 application]# netstat -lntup|grep 80
[root@web01 application]# /application/nginx/sbin/nginx
[root@web01 application]#
# nginx 重啟方法(平滑)
[root@web01 application]# /application/nginx/sbin/nginx -s reload
# nginx 配置文件語法檢查
[root@web01 application]# /application/nginx/sbin/nginx -t
nginx: the configuration file /application/nginx-1.10.3/conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.10.3/conf/nginx.conf test is successful
mysql軟體
mysql軟體下載地址信息: www.mysql.com mirrors.sohu.com
mysql軟體下載完畢後,查看mysql解壓後目錄文件大小
講解安裝mysql步驟
1) 下載解壓mysql二進位軟體包
tar xf mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz
#解壓資料庫壓縮包
2) 添加mysql程式運行時的管理用戶
useradd -s /sbin/nologin -M mysql
#創建虛擬用戶
3) 將mysql解壓後的程式包搬家到程式目錄下,併進行重命名
mkdir -p /application/
#創建程式目錄
mv /server/tools/mysql-5.6.34-*-x86_64 /application/mysql-5.6.34
#將程式搬遷
4) 為mysql服務程式創建軟鏈接
ln -s /application/mysql-5.6.34/ /application/mysql
#創建軟連接
5) 讓mysql用戶管理 /application/mysql/
chown -R mysql.mysql /application/mysql/data
## 用虛擬用戶管理
6) 初始化資料庫
#1. 確認軟體安裝在哪裡
#2. 確認數據存放在哪裡
#3. 確認MySQL使用的用戶誰?
/application/mysql/scripts/mysql_install_db --basedir=/application/mysql --datadir=/application/mysql/data --user=mysql
==================================================================================================
下麵是解釋
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
mysql啟動腳本 預設放在support-files/mysql.server
記得給MySQL設置個密碼
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
創建密碼的代碼
/application/mysql/bin/mysqladmin -u root password 'new-password'
遠程創建密碼
/application/mysql/bin/mysqladmin -u root -h web01 password 'new-password'
==================================================================================================
7) 複製啟動腳本 授權
cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
8) 修改啟動腳本 和 mysql命令中的路徑
sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe /etc/init.d/mysqld
#將預設的東西改為自己的 將後面兩個配置文件的全部都`修改
9) 複製預設的配置文件
\cp /application/mysql/support-files/my-default.cnf /etc/my.cnf #複製
/etc/init.d/mysqld start #啟動
至此,mysql資料庫安裝與啟動完成;可以檢測進程和服務埠,確認mysql服務是否啟動正確
講解管理mysql資料庫
1) 進入與退出mysql資料庫方法:
/application/mysql/bin/mysql
=============================================
擴展知識:登錄資料庫命令簡化方法
echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile
source /etc/profile
which mysql
=============================================
退出資料庫時,儘量不要用ctrl+c進行退出mysql 用ctrl+d進行退出
2) 設置mysql服務開機自啟動
####11.加入開機自啟動
chkconfig --add mysqld
chkconfig mysqld on
3) 設置mysql資料庫登錄用戶名與密碼
####12.給MySQL root用戶設置密碼
/application/mysql/bin/mysqladmin -u root password 'oldboy123'
mysql -u root -p oldboy123
初級 添加刪除系列
#創建資料庫
create database wordpress;
#刪除資料庫
drop database wordpress;
#############################################################################################################
02:LNMP PHP軟體安裝
講解安裝PHP步驟
1) 解決PHP軟體的依賴關係
yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel -y
yum install freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel -y
rpm -qa zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel
#查看是否下載成功
libiconv軟體安裝--和字元集轉換相關的軟體
#mkdir -p /server/tools
cd /server/tools
#wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar zxf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make
make install
cd ../
和數據加密相關的三個軟體安裝
#wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
#更換源
yum -y install libmcrypt-devel mhash mcrypt
#查看是否安裝成功
rpm -qa libmcrypt-devel mhash mcrypt
2) 下載解壓PHP軟體
cd /server/tools/ #進入目錄
tar xf php-5.5.32.tar.gz #解壓壓縮包
cd php-5.5.32 #進入目錄
#下麵是配置文件
./configure \
--prefix=/application/php-5.5.32 \
--with-mysql=/application/mysql/ \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir=/usr/local/libiconv \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--with-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-soap \
--enable-short-tags \
--enable-static \
--with-xsl \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-ftp \
--enable-opcache=no
#Generating files
#configure: creating ./config.status
#creating main/internal_functions.c
#creating main/internal_functions_cli.c
#+--------------------------------------------------------------------+
#| License: |
#| This software is subject to the PHP License, available in this |
#| distribution in the file LICENSE. By continuing this installation |
#| process, you are bound by the terms of this license agreement. |
#| If you do not agree with the terms of this license, you must abort |
#| the installation process at this point. |
#+--------------------------------------------------------------------+
#
#Thank you for using PHP.
make
make install <- 創建目錄,生成程式文件信息
瞭解FastCGI
3) PHP軟體程式創建軟鏈接
ln -s /application/php-5.5.32/ /application/php
4) 配置php解析文件/配置php-fpm配置文件
#上邊是開發用的 下麵是運維用的
cd /server/tools/php-5.5.32
cp php.ini-production /application/php/lib/php.ini
php.ini-production 與 php.ini-development 文件區別關係對比
擴展:文件比較命令 diff zdiff vimdiff windows上的文件比較
cd /application/php/etc/
cp php-fpm.conf.default php-fpm.conf
5) 啟動php-fpm程式
/application/php/sbin/php-fpm
)6檢查
lsof -i :9000 <--- 確認php 9000埠是否正確啟動
ps -ef|grep php-fpm
03:wordpress博客站點部署配置
1) 修改nginx配置文件,使nginx程式與php程式建立聯繫
vim extra/blog.conf
server {
listen 80;
server_name blog.etiantian.org;
location / {
root html/blog;
index index.php index.html index.htm; <-- 需要註意編輯修改預設首頁文件 index
}
location ~* .*\.(php|php5)?$ { #主要添加下麵這行
root html/blog;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
說明:利用nginx的location區塊實現動態請求與靜態請求的分別處理
實例
[root@web01 extra]# pwd
/application/nginx/conf/extra
[root@web01 extra]# cat blog.conf
server {
listen 80;
server_name blog.etiantian.org;
location / {
root html/blog;
index index.php index.html index.htm;
}
location ~* .*\.(php|php5)?$ {
root html/blog;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
2) 編輯nginx與php連通性測試文件,併進行測試
echo '<?php phpinfo(); ?>' >/application/nginx/html/blog/test_info.php #創建測試文件
測試站點
curl http://blog.etiantian.org/index.html <-- 靜態請求站點文件信息測試
curl http://blog.etiantian.org/test_info.php <-- 動態請求站點文件信息測試
說明:當php服務停止時,9000埠信息消失,即停止PHP錯誤報502錯誤
linux系統測試完畢後,建議利用瀏覽器進行最終測試,測試效果更明顯些
3) 編輯php與mysql連通性測試文件,併進行測試
a. 創建資料庫
mysql -u root -p oldboy123; #進入資料庫
show databases; <--- 查看當前資料庫信息
create database wordpress;
實例
mysql> mysql -uroot -poldboy123;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql -uroot -poldboy123' at line 1
mysql> create database wordpress;
Query OK, 1 row affected (0.53 sec)
b. 添加用戶信息
grant all on wordpress.* to 'wordpress'@'localhost' indentified by 'oldboy123';
grant all on wordpress.* to 'wordpress'@'172.16.1.%' indentified by 'oldboy123';
flush privileges;
drop user wordpress@'172.16.1.8'; <--- 刪除用戶信息
select user,host from mysql.user; <--- 查看用戶信息
mysql -uwordpress -p123456 <--- 測試創建的用戶連接
show databases; <--- 查看當前資料庫信息
實例
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| wordpress |
+--------------------+
5 rows in set (0.33 sec)
mysql> grant all on wordpress.* to 'wordpress'@'10.0.0.%' identified by 'oldboy123';
Query OK, 0 rows affected (0.47 sec)
mysql> select user,host from mysql.user;
+-----------+-----------+
| user | host |
+-----------+-----------+
| wordpress | 10.0.0.% |
| root | 127.0.0.1 |
| root | ::1 |
| | localhost |
| root | localhost |
| | web01 |
| root | web01 |
+-----------+-----------+
7 rows in set (0.00 sec)
c. 測試php與資料庫連通性
vim test_mysql.php
<?php
//$link_id=mysql_connect('主機名','用戶','密碼');
//mysql -u用戶 -p密碼 -h 主機
$link_id=mysql_connect('localhost','wordpress','oldboy123') or mysql_error();
if($link_id){
echo "mysql successful by oldboy !\n";
}else{
echo mysql_error();
}
?>
curl blog.etiantian.org/test_mysql.php <-- 測試php與資料庫的連通性
4) 下載部署wordpress博客程式(https://cn.wordpress.org/ 英文官網:https://www.wordpress.org/ )
wget https://cn.wordpress.org/wordpress-4.5.1-zh_CN.tar.gz
tar xf wordpress-4.5.1-zh_CN.tar.gz
mv wordpress/* /application/nginx/html/blog/
chown -R www.www /application/nginx/html/blog/
註意:確認hosts文件進行瞭解析
瀏覽器頁面進行wordpress部署
vim wp-config.php 可以修改wordpress上的資料庫連接參數信息
04:wordpress博客站點資料庫遷移
遷移資料庫:利用資料庫備份命令
1) 備份資料庫資料庫信息
mysqldump -uroot -poldboy123 --all-databases >/tmp/bak.sql
ll /tmp/bak.sql -h
scp /tmp/bak.sql 172.16.1.51:/tmp/
2) 恢複數據庫資料庫信息
##db01
mysql -uroot -poldboy123 </tmp/bak.sql
###db01添加新的用戶
grant all on wordpress.* to wordpress@'172.16.1.0/255.255.255.0' identified by 'oldboy123';
flush privileges;
mysql -uwordpress -poldboy123 -h 172.16.1.51
3) 資料庫遷移完畢,修改網站連接資料庫的配置文件
mysql -uwordpress -poldboy123 -h 172.16.1.51 <-- 修改配置文件之前,先測試網站web伺服器與遷移後的資料庫連通性
vim wp-config.php <-- 修改wordpress上的資料庫連接參數信息
/** MySQL主機 */
define('DB_HOST','172.16.1.51') <-- 修改連接的主機信息,將localhost修改為172.16.1.51
說明:web伺服器資料庫此時可以關閉了
05. 進行數據遷移到NFS共用伺服器
01:先將原有目錄中數據移出
cd /application/nginx/html/blog/wp-content/uploads
mkdir /tmp/wordpress_backup -p
mv ./* /tmp/wordpress_backup/
02:NFS伺服器上配置創建共用目錄
vim /etc/exports
/data 172.16.1.0/24(rw,sync,all_squash)
showmount -e 172.16.1.31
mount -t nfs 172.16.1.31:/data /mnt/
showmount -e 172.16.1.31
mount -t nfs 172.16.1.31:/data/ ./uploads/
mv /tmp/wordpress_backup/* ./