部署項目到Linux服務器步驟

2.3.2.服務器規劃




項目                      服務器數量                       虛擬機         ip
----------------------------------------------------------------------------------------------------------------------
Mysql                   2                               1               134
Solr                    7                               1               154
Redis                   6                               1               153
圖片服務器               2                               1               133
Nginx                   2                               1               141
註冊中心                    3                               1               167
Activemq                2                               1               168
                    服務器端口               工具端口
e3-manager            8080                   8080
e3-content            8081                   8083
e3-search             8082                   8084                           
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  1           135
e3-sso                8080                   8087
e3-cat                8081                   8089
e3-order              8082                   8091
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  1           136
e3-manager-web        8080                   8081
e3-portal-web         8081                   8082
e3-search-web         8082                   8085
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  1           137
e3-item-web           8080                   8086
e3-sso-web            8081                   8088
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  1           138
e3-cart-web           8080                   8090
e3-order-web          8081                   8092
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  1           139

2.3.3.域名規劃
序號  工程名 域名
1   e3-manager-web      manager.e3mall.cn
2   e3-portal-web       www.e3mall.cn
3   e3-search-web       search.e3mall.cn
4   e3-item-web         item.e3mall.cn
5   e3-sso-web          sso.e3mall.cn
6   e3-cart-web         cart.e3mall.cn
7   e3-order-web        order.e3mall.cn

一:首先部署好Mysql Solr Redis 圖片服務器 Nginx 註冊中心 Activemq 等服務器

二:把taotaotomcat 服務器部署到135,136,137,138,139這三個服務器上,並且打開端口8080,8081,8082
其中135,服務器記得打開dubbo中的20880,20881,20882這三個端口,
136,服務器記得打開dubbo中的20884,20885,20886這三個端口,具體情況具體操作
如果沒有打開這幾個端口,消費者就沒法消費這幾個服務,導致500異常

三:然後把這些服務分別使用maven跟Tomcat熱部署到服務器
第一步:需要修改tomcat的conf/tomcat-users.xml配置文件。添加用戶名、密碼、權限。

    <role rolename="manager-gui" />
        <role rolename="manager-script" />
    <user username="tomcat" password="tomcat" roles="manager-gui, manager-script"/>
第二步:重新啓動tomcat。
使用maven的tomcat插件實現熱部署:
第一步:配置tomcat插件,需要修改工程的pom文件。
<build>
        <plugins>
            <!-- 配置Tomcat插件 -->
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <configuration>
                    <port>8081</port>
                    <path>/</path>
                    <url>http://192.168.25.135:8080/manager/text</url>
                    <username>tomcat</username>
                    <password>tomcat</password>
                </configuration>        
            </plugin>
        </plugins>
    </build>
第二步:使用maven命令進行部署。
tomcat7:deploy
tomcat7:redeploy
部署的路徑是“/”會把系統部署到webapps/ROOT目錄下。
部署工程跳過測試:
clean tomcat7:redeploy -DskipTests

四: 這個時候雖然可以使用ip地址的方式訪問服務器,但是會發現Cookie有關的服務都會失效,
此時就需要反向代理的配置,因爲使用Cookie必須要識別有www.e3mall.cn這種地址形式纔會形成Cookie
切記要把web項目下面的所有內容全部改爲域名的形式,這樣纔會事Cookie生效!

五: 反向代理的配置,
測試時使用域名訪問網站,需要修改host文件。所有的域名應該指向反向代理服務器。
配置hosts文件:

    192.168.25.128 manager.e3mall.cn
    192.168.25.128 www.e3mall.cn
    192.168.25.128 search.e3mall.cn
    192.168.25.128 item.e3mall.cn
    192.168.25.128 sso.e3mall.cn
    192.168.25.128 cart.e3mall.cn
    192.168.25.128 order.e3mall.cn

六:配置nginx中cof下面的nginx.conf文件


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    upstream manager.e3mall.cn {
    server 192.168.25.137:8080;
    }
    upstream www.e3mall.cn {
    server 192.168.25.137:8081;
    }
    upstream search.e3mall.cn {
    server 192.168.25.137:8082;
    }
    upstream item.e3mall.cn {
    server 192.168.25.138:8080;
    }
    upstream sso.e3mall.cn {
    server 192.168.25.138:8081;
    }
    upstream cart.e3mall.cn {
    server 192.168.25.139:8080;
    }
    upstream order.e3mall.cn {
    server 192.168.25.139:8081;
    }

   server {
        listen       80;
        server_name  manager.e3mall.cn;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass   http://manager.e3mall.cn;
            index  index.html index.htm;
        }
    }
    server {
        listen       80;
        server_name  www.e3mall.cn;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass   http://www.e3mall.cn;
            index  index.html index.htm;
        }
    }
    server {
        listen       80;
        server_name  search.e3mall.cn;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass   http://search.e3mall.cn;
            index  index.html index.htm;
        }
    }
    server {
        listen       80;
        server_name  item.e3mall.cn;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass   http://item.e3mall.cn;
            index  index.html index.htm;
        }
    }
    server {
        listen       80;
        server_name  sso.e3mall.cn;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass   http://sso.e3mall.cn;
            index  index.html index.htm;
        }
    }
    server {
        listen       80;
        server_name  cart.e3mall.cn;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass   http://cart.e3mall.cn;
            index  index.html index.htm;
        }
    }
    server {
        listen       80;
        server_name  order.e3mall.cn;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass   http://order.e3mall.cn;
            index  index.html index.htm;
        }
    }
}

七:此時項目基本配置完成,剩下的就是把項目裏面的所有ip地址都改爲域名,記得改resources中的配置文件也要改爲域名的形式!
比如:e3-order-web中的conf/resource.properties文件中的SSO_URL=http://sso.e3mall.cn

此時就大功告成了,項目完美的跑起來吧!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章