這裏是給創業公司進行更換系統。由於平時用到的並不多,只有一臺服務器。
在遷移之前把應用,數據庫數據都下載下來,然後更換系統為centos7
1、首先是遷移數據庫。
安裝mysql5.7數據庫後,把數據導入進數據庫。由於linux數據嚴格區分大小寫,顧
#vim /etc/my.cnf
添加lower_case_table_names=1 到my.cnf中。
1.2、安裝tomcat,將應用放到tomcat中。
2.Nginx安裝
我使用的環境是64位 ubuntu 14.04。nginx依賴以下模塊:
l gzip模塊需要 zlib 庫
l rewrite模塊需要 pcre 庫
l ssl 功能需要openssl庫
2.1.安裝pcre
1. 獲取pcre編譯安裝包,在http://www.pcre.org/上可以獲取當前最新的版本
2. 解壓縮pcre-xx.tar.gz包。
3. 進入解壓縮目錄,執行./configure。
4. make & make install
1.2.安裝openssl
1. 獲取openssl編譯安裝包,在http://www.openssl.org/source/上可以獲取當前最新的版本。
2. 解壓縮openssl-xx.tar.gz包。
3. 進入解壓縮目錄,執行./config。
4. make & make install
2.3.安裝zlib
1. 獲取zlib編譯安裝包,在http://www.zlib.net/上可以獲取當前最新的版本。
2. 解壓縮openssl-xx.tar.gz包。
3. 進入解壓縮目錄,執行./configure。
4. make & make install
2.4.安裝nginx
1. 獲取nginx,在http://nginx.org/en/download.html上可以獲取當前最新的版本。
2. 解壓縮nginx-xx.tar.gz包。
3. 進入解壓縮目錄,執行./configure
4. make & make install
若安裝時找不到上述依賴模塊,使用--with-openssl=<openssl_dir>、--with-pcre=<pcre_dir>、--with-zlib=<zlib_dir>指定依賴的模塊目錄。如已安裝過,此處的路徑為安裝目錄;若未安裝,則此路徑為編譯安裝包路徑,nginx將執行模塊的默認編譯安裝。
啟動nginx之後,瀏覽器中輸入http://localhost可以驗證是否安裝啟動成功。
5、nginx的編譯安裝後的目錄在
/usr/local/nginx/
3、nginx整合tomcat
#vim /usr/local/nginx/conf/nginx.conf
添加圖片緩存
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 50m;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;
client_body_buffer_size 512k;
proxy_connect_timeout 5;
proxy_read_timeout 60;
proxy_send_timeout 5;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
proxy_temp_path /yundata/temp/images;
proxy_cache_path /yundata/cache/images levels=1:2 keys_zone=content:20m inactive=1d max_size=100m;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-Javascript text/css application/xml;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
配置tomcat,其中應用的端口為8080
#代理tomcat應用
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
access_log /var/log/nginx.log;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 15d;
}
location ~ .*\.(js|css)?$
{
expires 1d;
}
location / {
root html;
index index.html index.htm;
proxy_pass http://www.5ayzb.com:8080;
}
#代理php應用
server {
測試配置是否有問題通過下面命令
#/usr/local/nginx/sbin/nginx -t
看是否有錯誤信息。
輸入 netstat -tpnl 檢查下是否有服務正常
[root@localhost ~]# netstat -tpnl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:8005 0.0.0.0:* LISTEN 1504/java
tcp 0 0 0.0.0.0:8009 0.0.0.0:* LISTEN 1504/java
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 7913/nginx: master
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 1504/java
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 873/sshd
tcp6 0 0 :::3306 :::* LISTEN 889/mysqld
[root@localhost ~]#
4、安裝php5.6
安裝依賴
# yum install gcc gcc-c++ libxml2 libxml2-devel libjpeg-devel libpng-devel freetype-devel openssl-devel libcurl-devel libmcrypt-devel
#/configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --enable-pcntl --enable-mysqlnd --enable-opcache --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-shmop --enable-zip --enable-ftp --enable-soap --enable-xml --enable-mbstring --disable-rpath --disable-debug --disable-fileinfo --with-mysql --with-mysqli --with-pdo-mysql --with-pcre-regex --with-iconv --with-zlib --with-mcrypt --with-gd --with-openssl --with-mhash --with-xmlrpc --with-curl --with-imap-ssl
#make
。。。。。省略
#make intstall
[root@localhost php-5.6.26]# make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/
Installing PHP CLI binary: /usr/local/php/bin/
Installing PHP CLI man page: /usr/local/php/php/man/man1/
Installing PHP FPM binary: /usr/local/php/sbin/
Installing PHP FPM config: /usr/local/php/etc/
Installing PHP FPM man page: /usr/local/php/php/man/man8/
Installing PHP FPM status page: /usr/local/php/php/php/fpm/
Installing PHP CGI binary: /usr/local/php/bin/
Installing PHP CGI man page: /usr/local/php/php/man/man1/
Installing build environment: /usr/local/php/lib/php/build/
Installing header files: /usr/local/php/include/php/
Installing helper programs: /usr/local/php/bin/
program: phpize
program: php-config
Installing man pages: /usr/local/php/php/man/man1/
page: phpize.1
page: php-config.1
Installing PEAR environment: /usr/local/php/lib/php/
[PEAR] Archive_Tar - installed: 1.4.0
[PEAR] Console_Getopt - installed: 1.4.1
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util - installed: 1.3.0
[PEAR] PEAR - installed: 1.10.1
配置php
# cp php.ini-production /usr/local/php/etc/php.ini
# cp /usr/local/php/etc/php-fpm.conf.default php-fpm.conf
[root@localhost etc]# /usr/local/php/sbin/php-fpm -t
[17-Sep-2016 22:47:27] NOTICE: configuration file /usr/local/php/etc/php-fpm.conf test is successful
添加到
#cp /server/php-5.6.26/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
/server/php-5.6.26 這個是我的php的tar.xz 解壓的安裝包
添加到開機自啟
#chkconfig --add php-fpm
啟動PHP
#/etc/init.d/php-fpm start
5 nginx+php整合
5.1、修改php配置
#cd /usr/local/php/etc/
# vi php-fpm.conf
啟用如下幾行,即去掉前面的分號(;)
pid = run/php-fpm.pid
error_log = log/php-fpm.log
log_level = notice
listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
5.2、修改nginx
[root@localhost etc]# cd /usr/local/nginx/
[root@localhost nginx]# vim conf/nginx.conf
server
{
listen 80;
server_name bbs.5ayzb.com #二級域名(比如mial.baidu.com)
server_name ip;
index index.php index.html index.htm default.html default.htm default.php;
root /home/website/;#php應用的文件夾
location ~ \.php$ {
root /home/website;#php應用的文件夾
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location /status {
stub_status on;
access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
access_log off;
}
5.3、測試是否有問題
#/usr/local/nginx/sbin/nginx -t
6 最後結果
在瀏覽器輸入
www.5ayzb.com 就出現java的應用
輸入bbs.5ayzb.com 就是先php的應用。
到這裏php+nginx+tomcat的整合好了。80端口可以訪問兩個應用了。
參考:nginx安裝:http://www.cnblogs.com/skynet/p/4146083.html
nginx+php整合http://blog.chinaunix.net/uid-21374062-id-2951960.html
Tags: 數據庫數據 區分大小寫 windows 創業公司 服務器
文章來源: