搭建一個開源項目9-安裝應用服務器Tomcat\NGIX\Docker

1、應用服務器Tomcat安裝與部署

  • apache-tomat-8.5.55.tar.gz放在\root目錄下面
  • /usr/local下建立tomcat文件夾,並進入,解壓安裝包到這個目錄
[root@localhost ~]# cd /usr/local
[root@localhost local]# mkdir tomcat
[root@localhost local]# cd tomcat
[root@localhost tomcat]# tar -zxvf /root/apache-tomcat-8.5.55.tar.gz -C ./
  • 啓動tomcat
[root@localhost tomcat]# cd apache-tomcat-8.5.55/
[root@localhost apache-tomcat-8.5.55]# cd bin
[root@localhost bin]# ./startup.sh
[root@localhost bin]# firewall-cmd --zone=public --add-port=8080/tcp --permanent
[root@localhost bin]# firewall-cmd --reload

9.1

  • windows瀏覽器訪問IP:8080便可
    9.2
  • 配置快捷操做和開機啓動
  • 建立一個文件夾,並賦予執行權限,編輯tomcat文件
[root@localhost bin]# cd /etc/rc.d/init.d/
[root@localhost init.d]# touch tomcat
[root@localhost init.d]# chmod +x tomcat
#!/bin/bash
#chkconfig:- 20 90
#description:tomcat
#processname:tomcat
TOMCAT_HOME=/usr/local/tomcat/apache-tomcat-8.5.55
case $1 in
        start) su root $TOMCAT_HOME/bin/startup.sh;;
        stop) su root $TOMCAT_HOME/bin/shutdown.sh;;
        *) echo "require start|stop";;

esac
  • 後續對於Tomcat的開啓和關閉只須要執行下面的命令便可
[root@localhost init.d]# service tomcat start
[root@localhost init.d]# service tomcat stop
  • 最後加入開機啓動項
[root@localhost tomcat]# chkconfig --add tomcat
[root@localhost tomcat]# chkconfig tomcat on

service命令用於對系統服務進行管理,好比啓動(start)、中止(stop)、重啓(restart)、查看狀態(status)等。
service命令自己是一個shell腳本,它在/etc/init.d/目錄查找指定的服務腳本,而後調用該服務腳原本完成任務。
service運行指定服務(稱之爲System V初始腳本)時,把大部分環境變量去掉了,只保留LANG和TERM兩個環境變量,而且把當前路徑置爲/,也就是說是在一個能夠預測的很是乾淨的環境中運行服務腳本。這種腳本保存在/etc/init.d目錄中,它至少要支持start和stop命令。
引自:http://www.javashuo.com/article/p-fprxscug-mn.htmlhtml

chkconfig命令用來更新(啓動或中止)和查詢系統服務的運行級信息。謹記chkconfig不是當即自動禁止或激活一個服務,它只是簡單的改變了符號鏈接。
使用語法:
chkconfig [--add][--del][--list][系統服務] 或 chkconfig [--level <等級代號>][系統服務][on/off/reset]
chkconfig 在沒有參數運行時,顯示用法。若是加上服務名,那麼就檢查這個服務是否在當前運行級啓動。若是在服務名後面指 定了on,off或者reset,那麼chkconfi 會改變指定服務的啓動信息。on和off分別指服務被啓動和中止,reset指重置服務的啓動信息,不管有問題的初始化腳本指定了什麼。on和off開 關,系統默認只對運行級3,4,5有效,可是reset能夠對全部運行級有效。
參數用法:
–add  增長所指定的系統服務,讓chkconfig指令得以管理它,並同時在系統啓動的敘述文件內增長相關數據。
–del  刪除所指定的系統服務,再也不由chkconfig指令管理,並同時在系統啓動的敘述文件內刪除相關數據
–level<等級代號>  指定讀系統服務要在哪個執行等級中開啓或關畢
等級0表示:表示關機
等級1表示:單用戶模式
等級2表示:無網絡鏈接的多用戶命令行模式
等級3表示:有網絡鏈接的多用戶命令行模式
等級4表示:不可用
等級5表示:帶圖形界面的多用戶模式
等級6表示:從新啓動
引自:http://www.ttlsa.com/linux-command/linux-chkconfig-1/java

2、安裝web服務器NGINX

1.將安裝包nginx-1.17.10.tar.gz放在\root下面

  • /usr/local/下建立nginx文件夾並進入解壓
[root@localhost ~]# cd /usr/local
[root@localhost local]# mkdir nginx
[root@localhost local]# cd nginx/
[root@localhost nginx]# tar zxvf /root/nginx-1.17.10.tar.gz  -C ./
[root@localhost nginx]# cd nginx-1.17.10/
[root@localhost nginx-1.17.10]# yum -y install pcre-devel^C
  • 預先安裝額外的依賴
[root@localhost nginx-1.17.10]# yum -y install pcre-devel
[root@localhost nginx-1.17.10]# yum -y install openssl openssl-devel
  • 編譯安裝NGINX
[root@localhost nginx-1.17.10]# ./configure
[root@localhost nginx-1.17.10]# make && make install
  • 安裝後,Nginx可執行文件位置位於
/usr/local/nginx/sbin/ngix
  • 啓動和關閉ngix,以及修改了配置想要從新加載Ngix
[root@localhost nginx-1.17.10]# /usr/local/nginx/sbin/nginx 
[root@localhost nginx-1.17.10]# /usr/local/nginx/sbin/nginx -s stop
[root@localhost nginx-1.17.10]# /usr/local/nginx/sbin/nginx -s reload
  • 注意其配置文件位於/usr/local/nginx/conf/nginx.conf
  • 打開端口防火牆以後,登陸http:192.168.1.9:80便可
    9.3

3、安裝DOCKER

  • 直接安裝docker,並啓動和查看安裝結果
[root@localhost nginx-1.17.10]# yum install -y docker
[root@localhost nginx-1.17.10]# systemctl start docker.service
[root@localhost nginx-1.17.10]# docker version

9.4

  • 設置開啓啓動以及配置DOCKER鏡像下下載加速
[root@localhost nginx-1.17.10]# systemctl enable docker.service
[root@localhost nginx-1.17.10]# docker pull mysql

9.5

  • 從圖上咱們能夠看到下載速度很慢,因而咱們手動配置鏡像加速源,提高獲取docker鏡像速度
[root@localhost nginx-1.17.10]# vim /etc/docker/daemon.json
{
        "registry-mirrors":["http://hub-mirror.c.163.com"]
}
  • 這裏使用了網易的加速源,也可使用阿里雲、DaoCloud等資源,配置完成後,從新加載配置文件,重啓docker
[root@localhost nginx-1.17.10]# systemctl daemon-reload
[root@localhost nginx-1.17.10]# systemctl restart docker.service
  • 這樣就配置好了

systemctl 提供了一組子命令來管理單個的 unit,其命令格式爲:
systemctl [command] [unit]
command 主要有:
start:馬上啓動後面接的 unit。
stop:馬上關閉後面接的 unit。
restart:馬上關閉後啓動後面接的 unit,亦即執行 stop 再 start 的意思。
reload:不關閉 unit 的狀況下,從新載入配置文件,讓設置生效。
enable:設置下次開機時,後面接的 unit 會被啓動。
disable:設置下次開機時,後面接的 unit 不會被啓動。
status:目先後面接的這個 unit 的狀態,會列出有沒有正在執行、開機時是否啓動等信息。
is-active:目前有沒有正在運行中。
is-enable:開機時有沒有默認要啓用這個 unit。
kill :不要被 kill 這個名字嚇着了,它實際上是向運行 unit 的進程發送信號。
show:列出 unit 的配置。
mask:註銷 unit,註銷後你就沒法啓動這個 unit 了。
unmask:取消對 unit 的註銷。
引自:http://www.javashuo.com/article/p-ovpoctwv-m.htmlmysql

4、源碼:

相關文章
相關標籤/搜索