阿里雲服務器CentOS7配置Java Web項目運行環境(MySql,Tomcat,Jre)

此教程基於阿里雲服務器,安裝好系統之後的操作。

1.MySql的配置。

推薦使用阿里雲的集成配置工具“Linux一鍵安裝web環境 ”,我使用的版本是sh-1.4.5。

(下載地址http://download.csdn.net/detail/sagitarioo/9829445

使用Xftp工具將sh-1.4.5拷貝至root目錄下。


[root@iZ28e920mwrZ ~]# ls

mysql  sh-1.4.5

[root@iZ28e920mwrZ ~]#chmod -R 777 sh-1.4.5

[root@iZ28e920mwrZ ~]#cd sh-1.4.5

[root@iZ28e920mwrZ ~]#./install.sh

選擇(nginx)輸入1回車,

選擇php版本(最大的數字版本最新),

選擇Mysql的版本,

按Y確認繼續,

等待安裝完成。

出現以下文字時安裝完成,

---------- make dir ok ----------
---------- env ok ----------
---------- mysql-5.6.21 ok ----------
---------- nginx-1.4.4 ok ----------
---------- php-5.5.7 ok ----------
---------- php extension ok ----------
---------- vsftpd-3.0.2  ok ----------
---------- phpwind-8.7 ok ----------
---------- phpmyadmin-4.1.8 ok ----------
---------- web init ok ----------
---------- rc init ok ----------
---------- mysql init ok ----------

此時輸入以下命令
[root@iZ28e920mwrZ sh-1.4.5]# netstat -tunpl
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:9000             0.0.0.0:*                 LISTEN      22890/php-fpm: mast 
tcp        0             0       0.0.0.0:80                    0.0.0.0:*                 LISTEN      22915/nginx: master 
tcp        0             0       0.0.0.0:21                    0.0.0.0:*                 LISTEN      22928/vsftpd        
tcp        0             0       0.0.0.0:22                    0.0.0.0:*                 LISTEN      852/sshd            
tcp6      0             0        :::3306                         :::*                         LISTEN      13552/mysqld        
udp       0             0       115.28.220.200:123     0.0.0.0:*                  471/ntpd            
udp       0             0       10.144.255.85:123       0.0.0.0:*                                   471/ntpd            
udp       0             0       127.0.0.1:123               0.0.0.0:*                                   471/ntpd            
udp       0             0       0.0.0.0:123                   0.0.0.0:*                                   471/ntpd            
udp6     0             0        :::123                            :::*                                           471/ntpd          


到這裏mysql就安裝好了。

查看初始密碼:

[root@iZ28e920mwrZ sh-1.4.5]# cat account.log
##########################################################################

# thank you for using aliyun virtual machine

##########################################################################
FTP:
account:www
password:密碼
MySQL:
account:root
password:密碼

嘗試進入mysql

[root@iZ28e920mwrZ ~]# mysql -uroot -p
-bash: mysql: command not found

此時可能會出現如上錯誤。按下面步驟配置:

[root@iZ28e920mwrZ ~]# find / -name mysql

/home/mysql
/run/lock/subsys/mysql
/usr/lib64/mysql
/usr/share/mysql
/root/sh-1.4.5/php-5.5.7/travis/ext/mysql
/root/sh-1.4.5/php-5.5.7/ext/mysql
/root/sh-1.4.5/mysql
/alidata/server/mysql-5.6.21/bin/mysql
/alidata/server/mysql-5.6.21/include/mysql
/alidata/server/mysql-5.6.21/data/mysql
/alidata/server/mysql
/alidata/log/mysql
/var/spool/mail/mysql
[root@iZ28e920mwrZ ~]# ln -s /alidata/server/mysql-5.6.21/bin/mysql /usr/bin/mysql

此時即可進入mysql。

[root@iZ28e920mwrZ ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.6.21-log MySQL Community Server (GPL)
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

修改初始密碼。

mysql> use mysql;
Database changed
mysql> update user set password=password("新密碼") where user='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit;
Bye

到這裏mysql即配置完畢。

如果要使用可視化工具如:Navicat for MySql連接數據庫,還需要如下操作:

mysql>grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option; 

Query OK, 0 rows affected (0.00 sec)

mysql>flush privileges;
Query OK, 0 rows affected (0.00 sec)

輸入ip,賬號,密碼即可建立連接。

2.配置Jre

[root@iZ28e920mwrZ ~]# yum list java-1.8*
Loaded plugins: langpacks
Available Packages
java-1.8.0-openjdk.i686                                         1:1.8.0.131-2.b11.el7_3                    updates
java-1.8.0-openjdk.x86_64                                       1:1.8.0.131-2.b11.el7_3                    updates
java-1.8.0-openjdk-accessibility.x86_64                         1:1.8.0.131-2.b11.el7_3                    updates
java-1.8.0-openjdk-accessibility-debug.x86_64                   1:1.8.0.131-2.b11.el7_3                    updates
java-1.8.0-openjdk-debug.i686                                   1:1.8.0.131-2.b11.el7_3                    updates
java-1.8.0-openjdk-debug.x86_64                                 1:1.8.0.131-2.b11.el7_3                    updates
java-1.8.0-openjdk-demo.x86_64                                  1:1.8.0.131-2.b11.el7_3                    updates
java-1.8.0-openjdk-demo-debug.x86_64                            1:1.8.0.131-2.b11.el7_3                    updates
java-1.8.0-openjdk-devel.i686                                   1:1.8.0.131-2.b11.el7_3                    updates
java-1.8.0-openjdk-devel.x86_64                                 1:1.8.0.131-2.b11.el7_3                    updates
java-1.8.0-openjdk-devel-debug.i686                             1:1.8.0.131-2.b11.el7_3                    updates
java-1.8.0-openjdk-devel-debug.x86_64                           1:1.8.0.131-2.b11.el7_3                    updates
java-1.8.0-openjdk-headless.i686                                1:1.8.0.131-2.b11.el7_3                    updates
java-1.8.0-openjdk-headless.x86_64                              1:1.8.0.131-2.b11.el7_3                    updates
java-1.8.0-openjdk-headless-debug.i686                          1:1.8.0.131-2.b11.el7_3                    updates
java-1.8.0-openjdk-headless-debug.x86_64                        1:1.8.0.131-2.b11.el7_3                    updates
java-1.8.0-openjdk-javadoc.noarch                               1:1.8.0.131-2.b11.el7_3                    updates
java-1.8.0-openjdk-javadoc-debug.noarch                         1:1.8.0.131-2.b11.el7_3                    updates
java-1.8.0-openjdk-javadoc-zip.noarch                           1:1.8.0.131-2.b11.el7_3                    updates
java-1.8.0-openjdk-javadoc-zip-debug.noarch                     1:1.8.0.131-2.b11.el7_3                    updates
java-1.8.0-openjdk-src.x86_64                                   1:1.8.0.131-2.b11.el7_3                    updates
java-1.8.0-openjdk-src-debug.x86_64                             1:1.8.0.131-2.b11.el7_3                    updates

[root@iZ28e920mwrZ ~]# yum install java-1.8.0-openjdk* 


Transaction Summary
==================================================================================================================
Install  16 Packages (+31 Dependent packages)
Upgrade              (  9 Dependent packages)

Total download size: 301 M
Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.

等待自動安裝完成,環境變量什麼已自動配置好,無需其他設置。

3.Tomcat配置

建議自行下載到電腦解壓,然後傳到服務器你想放置的目錄下。

地址https://mirrors.cnnic.cn/apache/tomcat/中可選擇tomcat版本

我選的最新版https://mirrors.cnnic.cn/apache/tomcat/tomcat-8/v8.0.43/bin/apache-tomcat-8.0.43.tar.gz

我把tomcat文件夾放在了usr/local/中。

[root@iZ28e920mwrZ ~]# cd ..
[root@iZ28e920mwrZ /]# cd usr/local/apache-tomcat-8.0.43/bin

[root@iZ28e920mwrZ bin]# chmod u+x *.sh
[root@iZ28e920mwrZ bin]# ./startup.sh
Using CATALINA_BASE:   /usr/local/apache-tomcat-8.0.43
Using CATALINA_HOME:   /usr/local/apache-tomcat-8.0.43
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-8.0.43/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/apache-tomcat-8.0.43/bin/bootstrap.jar:/usr/local/apache-tomcat-8.0.43/bin/tomcat-juli.jar
Tomcat started.


公網ip:8080測試一下tomcat.

到這裏,Mysql,jre,tomcat均配置完畢。


Mysql的字符編碼可能存在問題。

mysql> show variables like 'character%';
+--------------------------+----------------------------------------------+
| Variable_name                    | Value                                   |
+--------------------------+----------------------------------------------+
| character_set_client           | utf8                                      |
| character_set_connection  | utf8                                      |
| character_set_database     | latin1                                   |
| character_set_filesystem    | binary                                  |
| character_set_results         | utf8                                      |
| character_set_server          | latin1                                   |
| character_set_system         | utf8                                      |
| character_sets_dir              | /alidata/server/mysql-5.6.21/share/charsets/ |
+--------------------------+----------------------------------------------+
8 rows in set (0.00 sec)

打開/alidata/server/mysql-5.6.21/my.cnf文件,添加如下圖紅框中內容:


mysql> show variables like 'character%';
+--------------------------+----------------------------------------------+
| Variable_name                    | Value                                   |
+--------------------------+----------------------------------------------+
| character_set_client           | utf8                                      |
| character_set_connection  | utf8                                      |
| character_set_database    | utf8                                       |
| character_set_filesystem   | binary                                   |
| character_set_results        | utf8                                       |
| character_set_server         | utf8                                       |
| character_set_system        | utf8                                       |
| character_sets_dir              | /alidata/server/mysql-5.6.21/share/charsets/ |
+--------------------------+----------------------------------------------+
8 rows in set (0.01 sec)
mysql> exit;
Bye


將Ecplise中的工程打包成.war格式文件,放到tomcat目錄webapps下。公網Ip+端口號+項目名稱,即可訪問。

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