查看CentOS自帶JDK是否已安裝javascript
1
|
[root@
test
~]
# yum list installed |grep java
|
如有自帶安裝的JDK,應以下操做進行卸載CentOS系統自帶Java環境php
1
2
3
4
5
6
7
8
9
10
|
[root@
test
~]
# java -version
java version
"1.7.0_181"
OpenJDK Runtime Environment (rhel-2.6.14.8.el6_9-x86_64 u181-b00)
OpenJDK 64-Bit Server VM (build 24.181-b00, mixed mode)
[root@
test
~]
# yum -y remove java-1.7.0-openjdk*
[root@
test
~]
# yum -y remove tzdata-java.noarch
[root@
test
~]
# java --version
-
bash
:
/usr/bin/java
: No such
file
or directory
|
查看yum庫中的Java安裝包css
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
[root@
test
~]
# yum -y list java*
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos.ustc.edu.cn
* extras: centos.ustc.edu.cn
* updates: centos.ustc.edu.cn
base | 3.7 kB 00:00
extras | 3.4 kB 00:00
updates | 3.4 kB 00:00
Available Packages
java-1.5.0-gcj.x86_64 1.5.0.0-29.1.el6 base
java-1.5.0-gcj-devel.x86_64 1.5.0.0-29.1.el6 base
java-1.5.0-gcj-javadoc.x86_64 1.5.0.0-29.1.el6 base
java-1.5.0-gcj-src.x86_64 1.5.0.0-29.1.el6 base
java-1.6.0-openjdk.x86_64 1:1.6.0.40-1.13.12.6.el6_8 updates
java-1.6.0-openjdk-demo.x86_64 1:1.6.0.40-1.13.12.6.el6_8 updates
java-1.6.0-openjdk-devel.x86_64 1:1.6.0.40-1.13.12.6.el6_8 updates
java-1.6.0-openjdk-javadoc.x86_64 1:1.6.0.40-1.13.12.6.el6_8 updates
java-1.6.0-openjdk-src.x86_64 1:1.6.0.40-1.13.12.6.el6_8 updates
java-1.7.0-openjdk.x86_64 1:1.7.0.111-2.6.7.2.el6_8 updates
java-1.7.0-openjdk-demo.x86_64 1:1.7.0.111-2.6.7.2.el6_8 updates
java-1.7.0-openjdk-devel.x86_64 1:1.7.0.111-2.6.7.2.el6_8 updates
java-1.7.0-openjdk-javadoc.noarch 1:1.7.0.111-2.6.7.2.el6_8 updates
java-1.7.0-openjdk-src.x86_64 1:1.7.0.111-2.6.7.2.el6_8 updates
java-1.8.0-openjdk.x86_64 1:1.8.0.101-3.b13.el6_8 updates
java-1.8.0-openjdk-debug.x86_64 1:1.8.0.101-3.b13.el6_8 updates
java-1.8.0-openjdk-demo.x86_64 1:1.8.0.101-3.b13.el6_8 updates
java-1.8.0-openjdk-demo-debug.x86_64 1:1.8.0.101-3.b13.el6_8 updates
java-1.8.0-openjdk-devel.x86_64 1:1.8.0.101-3.b13.el6_8 updates
java-1.8.0-openjdk-devel-debug.x86_64 1:1.8.0.101-3.b13.el6_8 updates
java-1.8.0-openjdk-headless.x86_64 1:1.8.0.101-3.b13.el6_8 updates
java-1.8.0-openjdk-headless-debug.x86_64 1:1.8.0.101-3.b13.el6_8 updates
java-1.8.0-openjdk-javadoc.noarch 1:1.8.0.101-3.b13.el6_8 updates
java-1.8.0-openjdk-javadoc-debug.noarch 1:1.8.0.101-3.b13.el6_8 updates
java-1.8.0-openjdk-src.x86_64 1:1.8.0.101-3.b13.el6_8 updates
java-1.8.0-openjdk-src-debug.x86_64 1:1.8.0.101-3.b13.el6_8 updates
java_cup.x86_64 1:0.10k-5.el6 base
java_cup-javadoc.x86_64 1:0.10k-5.el6 base
java_cup-manual.x86_64 1:0.10k-5.el6 base
javacc.x86_64 4.1-0.5.el6 base
javacc-demo.x86_64 4.1-0.5.el6 base
javacc-manual.x86_64 4.1-0.5.el6 base
javassist.noarch 3.9.0-6.el6 base
javassist-javadoc.noarch 3.9.0-6.el6 base
|
以yum庫中java-1.8.0爲例, "*"表示將java-1.8.0的全部相關Java程序都安裝上html
1
|
[root@
test
~]
# yum -y install java-1.8.0-openjdk*
|
查看剛安裝的Java版本信息。
輸入:"java -version" 可查看Java版本
輸入:"javac" 可查看Java的編譯器命令用法java
1、環境搭建準備
一、先到tomcat官網https://tomcat.apache.org/查看下載路徑mysql
我下載的tomcat-9 如: nginx
http://mirrors.shu.edu.cn/apache/tomcat/tomcat-9/v9.0.16/bin/apache-tomcat-9.0.16.tar.gz
進入目錄:web
cd /usr/local/
wget下載安裝包:sql
wget http://mirrors.shu.edu.cn/apache/tomcat/tomcat-9/v9.0.16/bin/apache-tomcat-9.0.16.tar.gz
解壓:apache
tar -zxvf apache-tomcat-9.0.16.tar.gz
目錄說明:
bin --啓動命令目錄 conf --配置文件目錄 *重點 lib --庫文件目錄 logs --日誌文件目錄 *重點 temp --臨時緩存文件 webapps --web應用家目錄 *重點 work --工做緩存目錄
5. 啓動Tomcat:
./bin/startup.sh
6 關閉Tomcat:
./bin/shutdown.sh
7 開機啓動:
在/usr/lib/systemd/system目錄下增長tomcat9.service文件,內容以下:
[Unit] Description=Tomcat After=syslog.target network.target remote-fs.target nss-lookup.target [Service] Type=oneshot ExecStart=/usr/local/tomcat/bin/startup.sh ExecStop=/usr/local/tomcat/bin/shutdown.sh ExecReload=/bin/kill -s HUP $MAINPID RemainAfterExit=yes [Install] WantedBy=multi-user.target
退出並保存,執行systemctl enable tomcat使tomcat9隨開機啓動
systemctl enable tomcat9.service
另外命令
systemctl start tomcat9.service 啓動tomcat
systemctl stop tomcat9.service 關閉tomcat
systemctl restart tomcat9.service 重啓tomcat
固然啓動和結束tomcat也能夠到tomcat的安裝目錄的bin目錄下執行shutdown.sh startup.sh來完成
四、查看tomcat默認端口8080是否開啓
[root@localhost ~]# netstat -ntlp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd tcp 0 0 0.0.0.0:6000 0.0.0.0:* LISTEN 3832/X tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 3739/dnsmasq tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 3378/sshd tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 3380/cupsd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 3655/master tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 9873/sshd: root@pts tcp 0 0 127.0.0.1:6011 0.0.0.0:* LISTEN 6137/sshd: root@pts tcp 0 0 127.0.0.1:6012 0.0.0.0:* LISTEN 10234/sshd: root@pt tcp6 0 0 :::8009 :::* LISTEN 9804/java tcp6 0 0 :::3306 :::* LISTEN 7196/mysqld tcp6 0 0 :::111 :::* LISTEN 1/systemd tcp6 0 0 :::8080 :::* LISTEN 9804/java tcp6 0 0 :::6000 :::* LISTEN 3832/X tcp6 0 0 :::22 :::* LISTEN 3378/sshd tcp6 0 0 ::1:631 :::* LISTEN 3380/cupsd tcp6 0 0 ::1:25 :::* LISTEN 3655/master tcp6 0 0 ::1:6010 :::* LISTEN 9873/sshd: root@pts tcp6 0 0 ::1:6011 :::* LISTEN 6137/sshd: root@pts tcp6 0 0 ::1:6012 :::* LISTEN 10234/sshd: root@pt tcp6 0 0 127.0.0.1:8005 :::* LISTEN 9804/java
3、瀏覽器打開:http://192.168.0.8:8080 出現如下界面說明成功
centos7系統庫中默認是沒有nginx的rpm包的,因此咱們本身須要先更新下rpm依賴庫
1.)使用yum安裝nginx須要包括Nginx的庫,安裝Nginx的庫
#rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
2.使用下面命令安裝nginx
#yum install nginx
3.啓動nginx
#service nginx start 或者 #systemctl start nginx.service
4.中止nginx
nginx -s stop
5.從新加載nginx配置文件
nginx -s reload
6.nginx指定項目路徑 注:修改配置文件默認用戶名爲root
下載源:wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
安裝源:yum install nginx-release-centos-6-0.el6.ngx.noarch.rpm -y(注意-y參數)
安裝Nginx:yum install nginx
啓動Nginx服務:service nginx start
中止Nginx服務:service nginx stop
查看Nginx運行狀態:service nginx status
檢查Nginx配置文件:nginx -t
服務運行中從新加載配置:nginx -s reload
添加Nginx服務自啓動:chkconfig nginx on
修改Nginx所在主機的防火牆配置:vi /etc/sysconfig/iptables,將nginx使用的端口添加到容許列表中。
例如:-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT (表示容許80端口經過)
修改Tomcat所在主機的防火牆配置:vi /etc/sysconfig/iptables,將tomcat使用的端口添加到容許列表中。
例如:-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT (表示容許8080端口經過)
若是主機上有多個tomcat的話,則按此規則添加多條,修改對應的端口號便可。
保存後重啓防火牆:service iptables restart
Nginx啓動時默認加載配置文件/etc/nginx/nginx.conf,而nginx.conf裏會引用/etc/nginx/conf.d目錄裏的全部.conf文件。
所以能夠將本身定製的一些配置寫到單獨.conf文件裏,只要文件放在/etc/nginx/conf.d這個目錄裏便可,方便維護。
建立tomcats.conf:vi /etc/nginx/conf.d/tomcats.conf,內容以下:
upstream tomcats { ip_hash; server 192.168.0.251:8080; server 192.168.0.251:8081; server 192.168.0.251:8082; }
修改default.conf:vi /etc/nginx/conf.d/default.conf,修改以下:
#註釋原有的配置 #location / { # root /usr/share/nginx/html; # index index.html index.htm; #} #新增配置默認將請求轉發到tomcats.conf配置的upstream進行處理 location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://tomcats; #與tomcats.conf裏配置的upstream同名 }
保存後從新加載配置:nginx -s reload
修改default.conf:vi /etc/nginx/conf.d/default.conf,添加以下配置:
#全部js,css相關的靜態資源文件的請求由Nginx處理 location ~.*\.(js|css)$ { root /opt/static-resources; #指定文件路徑 expires 12h; #過時時間爲12小時 } #全部圖片等多媒體相關靜態資源文件的請求由Nginx處理 location ~.*\.(html|jpg|jpeg|png|bmp|gif|ico|mp3|mid|wma|mp4|swf|flv|rar|zip|txt|doc|ppt|xls|pdf)$ { root /opt/static-resources; #指定文件路徑 expires 7d; #過時時間爲7天 }
若是訪問Nginx時出現502 Bad Gateway錯誤,則多是Nginx主機上的SELinux限制了其使用http訪問權限引發的,輸入命令setsebool -P httpd_can_network_connect 1 開啓權限便可。
文件/etc/nginx/nginx.conf完整配置以下:
user nginx; worker_processes auto; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; worker_rlimit_nofile 100000; events { use epoll; multi_accept on; worker_connections 1024; } http { include /etc/nginx/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 /var/log/nginx/access.log main; sendfile on; server_tokens off; #tcp_nopush on; keepalive_timeout 65; gzip on; gzip_disable "msie6"; gzip_static on; gzip_proxied any; gzip_min_length 1000; gzip_comp_level 4; gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; include /etc/nginx/conf.d/*.conf; }
文件/etc/nginx/conf.d/default.conf完整配置以下:
server { listen 80; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/log/host.access.log main; #location / { # root /usr/share/nginx/html; # index index.html index.htm; #} location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://web_servers; } location ~.*\.(js|css)$ { root /opt/static-resources; expires 12h; } location ~.*\.(html|jpg|jpeg|png|bmp|gif|ico|mp3|mid|wma|mp4|swf|flv|rar|zip|txt|doc|ppt|xls|pdf)$ { root /opt/static-resources; expires 7d; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} }
注意:若是執行命令時沒有root權限,請在命令前面加上 sudo 執行。
bin --啓動命令目錄 conf --配置文件目錄 *重點 lib --庫文件目錄 logs --日誌文件目錄 *重點 temp --臨時緩存文件 webapps --web應用家目錄 *重點 work --工做緩存目錄