35
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

posted at

updated at

CentOS7にTomcat8を構築する方法

インストール

yum-fastestmirrorインストール

  • yum-fastermirrorインストール

    terminal
    yum -y install yum-fastestmirror
    

jdkインストール

  • jdkインストール

    terminal
    yum -y install java-1.8.0-openjdk-devel
    
  • 確認

    terminal
    java -version
    
    openjdk version "1.8.0_111"
    OpenJDK Runtime Environment (build 1.8.0_111-b15)
    OpenJDK 64-Bit Server VM (build 25.111-b15, mixed mode)
    
  • パスを通す

    terminal
    echo "export JAVA_HOME=$(readlink -e $(which java)|sed 's:/bin/java::')" >  /etc/profile.d/java.sh
    echo "PATH=\$PATH:\$JAVA_HOME/bin"                                       >> /etc/profile.d/java.sh
    source /etc/profile.d/java.sh
    

tomcat取得&配置

  • tomcatユーザー作成

    terminal
    useradd -s /sbin/nologin tomcat
    
  • tomcatダウンロード

    terminal
    mkdir -p /usr/local/src/tomcat
    cd /usr/local/src/tomcat
    curl -OL http://ftp.yz.yamagata-u.ac.jp/pub/network/apache/tomcat/tomcat-8/v8.5.9/bin/apache-tomcat-8.5.9.tar.gz
    
  • tar.gz展開&配置

    terminal
    tar zxvf apache-tomcat-8.5.9.tar.gz
    mv apache-tomcat-8.5.9 /opt/
    chown -R tomcat. /opt/apache-tomcat-8.5.9
    
  • 今後発生するVupによるパス差分をシンボリックリンクで吸収しておく

    terminal
    ln -s /opt/apache-tomcat-8.5.9 /opt/tomcat
    
  • パスを通す

    terminal
    echo 'export CATALINA_HOME=/opt/tomcat'  >  /etc/profile.d/tomcat.sh
    source /etc/profile.d/tomcat.sh
    

初期設定 & 起動

  • サービス定義ファイルを作成

    terminal
    vi /etc/systemd/system/tomcat.service
    
    /etc/systemd/system/tomcat.service
    [Unit]
    Description=Apache Tomcat 8
    After=syslog.target network.target
    
    [Service]
    User=tomcat
    Group=tomcat
    Type=oneshot
    PIDFile=/opt/tomcat/tomcat.pid
    RemainAfterExit=yes
    
    ExecStart=/opt/tomcat/bin/startup.sh
    ExecStop=/opt/tomcat/bin/shutdown.sh
    ExecReStart=/opt/tomcat/bin/shutdown.sh;/opt/tomcat/bin/startup.sh
    
    [Install]
    WantedBy=multi-user.target
    
  • 権限付与

    terminal
    chmod 755 /etc/systemd/system/tomcat.service
    
  • 起動

    terminal
    systemctl start tomcat
    

確認

  • ブラウザで「http://ipaddress:8080」アクセス

    • Apache Tomcat/8.5.9 の画面が表示されればOK。

    Kobito.fBsd5c.png

  • つながらないとき…

    • firewallなどで止められているかも…

      terminal
      service firewalld stop
      
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
35
Help us understand the problem. What are the problem?