---
# System prepended metadata

title: FCM

---

# FCM

## install tomcat

```bash
cd /opt/

mkdir tomcat

tar -zxvf apache-tomcat-8.5.57.tar.gz -C /opt/tomcat/ --strip-components=1

rm apache-tomcat-8.5.57.tar.gz
```

### 設定檔案權限

```bash
cd /opt/tomcat

chgrp -R tomcat conf
chmod g+rwx conf
chmod g+r conf/*
chown -R tomcat logs/ temp/ webapps/ work/

chgrp -R tomcat bin
chgrp -R tomcat lib
chmod g+rwx bin
chmod g+r bin/*
```

### 設定 Systemd 啟動指令稿

```bash
vim /etc/systemd/system/tomcat.service
```

```properties
[Unit]
Description=Apache Tomcat 8
After=syslog.target network.target

[Service]
User=tomcat
Group=tomcat
Type=forking
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
Restart=on-failure

Environment='CATALINA_OPTS=-Xms512M -Xmx8192M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'

[Install]
WantedBy=multi-user.target
```

### 重新載入 systemd

`systemctl daemon-reload`

將 Tomcat 伺服器設定為開機自動啟動：

### tomcat jndi setting

edit conf/context.xml

`vim /opt/tomcat/conf/context.xml`

```xml
  <Resource name="jdbc/DevDB" auth="Container"
    driverClassName="com.sybase.jdbc3.jdbc.SybDriver"
    factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
    type="javax.sql.DataSource" 
    maxActive="20" maxIdle="10" 
    url="jdbc:sybase:Tds:10.2.3.227:8000/SMS"
    username="sa" 
    password="1qaz2wsx" 
    />
```

### 放置lib

資料庫連線要使用的driver或其他 ap sever 上要使用的 lib，要放置到 `/opt/tomcat/lib/`

```bash
cp /opt/jconn3.jar /opt/tomcat/lib/
```

### 設定開機自動啟動 Tomcat

`systemctl enable tomcat`

### 立即啟動 Tomcat

`systemctl start tomcat`

### 停止 Tomcat

`systemctl stop tomcat`

### 取消開機自動啟動

`systemctl disable tomcat`

