CentOS7安裝openjdk、tomcat和mysql流程介紹
首先是前戲,推薦一個遠端工具Xshell和Xftp搭配使用,以下是Xshell的官網 http://www.netsarang.com/products/xsh_overview.html
1.openjdk
How to download and install prebuilt OpenJDK packages JDK 8 Debian, Ubuntu, etc. On the command line, type: $ sudo apt-get install openjdk-8-jre The openjdk-8-jre package contains just the Java Runtime Environment. If you want to develop Java programs then please install the openjdk-8-jdk package. Fedora, Oracle Linux, Red Hat Enterprise Linux, etc. On the command line, type: $ su -c “yum install java-1.8.0-openjdk” The java-1.8.0-openjdk package contains just the Java Runtime Environment. If you want to develop Java programs then install the java-1.8.0-openjdk-devel package.
以上說了不同系統的安裝方式,還指出命令只是安裝了JRE,如果你需要開發應用程式,還需要另外安裝(已經用加粗標識),想安裝其它版本詳情看openjdk官網介紹 http://openjdk.java.net/install/
[root@VM_207_229_centos ~]# java -version
openjdk version "1.8.0_71"
OpenJDK Runtime Environment (build 1.8.0_71-b15)
OpenJDK 64-Bit Server VM (build 25.71-b15, mixed mode)
- 1
- 2
- 3
- 4
2.tomcat
# cd /usr/local # wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.0.36/bin/apache-tomcat-8.0.36.tar.gz # tar xzf apache-tomcat-8.0.36.tar.gz # mv apache-tomcat-8.0.36 tomcat # ls apache-tomcat-8.0.36.tar.gz etc include lib64 logs sa share tomcat bin games lib libexec qcloud sbin src
- 1
- 2
- 3
- 4
- 5
- 6
- 7
個人習慣把tomcat放在/user/local下,下載後解壓,再更名為tomcat 想要其它版本的話……在以下地址找好路徑下載 https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/
修改配置檔案conf/server.xml改為監聽80埠,預設編碼utf-8,並開啟gzip壓縮
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" executor="tomcatThreadPool" URIEncoding="utf-8"
compression="on"
compressionMinSize="50" noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain" />
<!-- A "Connector" using the shared thread pool-->
- 1
- 2
- 3
- 4
- 5
- 6
- 7
啟動tomcat,在瀏覽器輸入ip地址訪問,看到tomcat小貓頁面就行了。CentOS7開放80埠,Centos 7使用firewalld代替了原來的iptables。
<!-- 啟動防火牆 -->
# systemctl start firewalld
<!-- 開啟80埠,出現success表明新增成功 -->
# firewall-cmd --zone=public --add-port=80/tcp --permanent
<!-- 重啟防火牆 -->
# systemctl restart firewalld.service
<!-- 檢查埠 -->
# firewall-cmd --permanent --zone=public --list-ports
<!-- 自啟動防火牆 -->
#systemctl enable firewalld
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
還有更改預設訪問地址,不想見到tomcat小貓(此步驟看個人需要)
<Engine name="Catalina" defaultHost="www.caihongwen.cn">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="www.caihongwen.cn" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context docBase="blog" path="" debug="0" reloadable="true"/>
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
請在意Host之間添加了一段程式碼
<Context docBase="blog" path="" debug="0" reloadable="true"/>
- 1
這個blog是放在webapps的專案war包名,通過ip或域名直接進入部落格,不會出現tomcat小貓管理頁面,第一次啟動tomcat稍慢,新增加的war包需要重啟一次才能起效。還有一個要點是對外開啟80埠。
3.mysql
使用RPM包進行安裝,這種安裝程序會自動完成系統的相關配置,比較方便。 另外有.tar.gz的壓縮檔案安裝方式,推薦一個部落格的介紹。 http://blog.csdn.net/superchanon/article/details/8546254/
解除安裝原有MySQL或者Mariadb安裝程式 1、CentOs7版本預設情況下安裝了mariadb-libs,必須先解除安裝才可以繼續安裝MySql。 a) 查詢以前是否安裝mariadb-libs
# rpm -qa | grep -i mariadb-libs
- 1
b)解除安裝已經安裝的mariadb-libs
# yum remove mariadb-libs-5.5.44-2.el7.centos.x86_64
- 1
2、查詢以前是否安裝MySQL
# rpm -qa | grep -i mysql
- 1
有的話,也刪除
安裝MySQL
# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
# rpm -ivh mysql-community-release-el7-5.noarch.rpm
# yum install mysql-community-server
- 1
- 2
- 3
成功安裝之後重啟mysql服務
# service mysqld restart
- 1
初次安裝mysql是root賬戶是沒有密碼的,設定密碼的方法
# mysql -uroot
mysql> set password for 'root'@'localhost' = password('mypasswd');
- 1
- 2
遠端授權連線mysql
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mypasswd' WITH GRANT OPTION;
FLUSH PRIVILEGES;
- 1
- 2
修改mysql預設編碼
# vim /etc/my.cnf
- 1
作出以下修改
[client]
default-character-set=utf8
[mysqld]
character_set_server=utf8
- 1
- 2
- 3
- 4
然後重啟mysql
# service mysqld restart
# mysql -uroot -p
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 | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
mysql> show variables like 'collation%';
+----------------------+-----------------+
| Variable_name | Value |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database | utf8_general_ci |
| collation_server | utf8_general_ci |
+----------------------+-----------------+
3 rows in set (0.00 sec)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
安裝mysql-jdbc驅動
# yum install mysql-connector-java
- 1
完工!!!
遠端連線mysql,如果連線不上的話,可能是沒開放3306埠。 最後,分享一個mysql遠端管理神器navicat,你懂的 http://pan.baidu.com/s/1mh87vGc