LoginSignup
25
35

More than 5 years have passed since last update.

CentOS7にTomcat8を構築する方法

Last updated at Posted at 2017-01-13

インストール

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
      
25
35
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
25
35