Buradaki yazıdan AWS EC2 ile nasıl Ubuntu sunucusu oluşturulacağını okuyabilirsiniz. Bu yazı o yazının devam niteliğindedir.
Sunucumuza bağlanmak için makinelerimizin listelendiği Instances ekranından Action ardından Connect seçeneklerini seçiyoruz.
Açılan pop-up’ta SSH ile sunucuya nasıl bağlantı kuracağımız gösteriliyor. Example kısmındaki komutu kopyalayarak daha önce key pair dosyasını indirdiğimiz dizinde bir terminal başlatıyoruz.
Bu terminalde kopyaladığımız komutu çalıştırıyoruz ve sunucumuza SSH bağlantısını kurmuş oluyoruz.
sudo apt update
sudo apt install git
git --version
Yukarıdaki komutlar ile terminal üzerinden git’i kuruyoruz ve kurulduğunu kontrol ediyoruz.
sudo apt install openjdk-11-jdk
java -version
Yukarıdaki komutlar ile Java’yı kuruyoruz ve versiyon kontrolü yapıyoruz. Ben OpenJDK ve Java 11 kullanıyorum. Siz istediğiniz jdk’yı kullanabilirsiniz.
sudo apt install maven
mvn --version
Yukarıdaki komutlar ile Maven’ı kuruyoruz ve versiyon kontrolü yapıyoruz.
Buradan Tomcat’in sitesine gidiyoruz ve “tar.gz” olan indirme linkini kopyalıyoruz. Ben Tomcat 8 indiriyorum siz isterseniz diğer sürümleri de kullanabilirsiniz.
sudo su -
cd /opt
sudo wget https://ftp.itu.edu.tr/Mirror/Apache/tomcat/tomcat-8/v8.5.64/bin/apache-tomcat-8.5.64.tar.gz
tar -xvzf /opt/apache-tomcat-8.5.64.tar.gz
Yukarıdaki komutları sırası ile çalıştırarak önce Tomcat’i indiriyoruz ve ardından kurulumu gerçekleştiriyoruz. “wget” ile indirdiğim link yerine siz kopyaladığınız linki yapıştırmalısınız çünkü link ve sürüm sürekli güncelleniyor. Bununla birlikte klasörün ismi de sürüm ismi ile aynı olacak şekilde güncellenmelidir.
mv apache-tomcat-8.5.64 tomcat
cd tomcat
cd bin
ls
Yukarıdaki komutları sırası ile uygulayarak önce “apache-tomcat-8.5.63” klasörünün adını “tomcat” olarak güncelliyoruz ve daha sonra Tomcat’i başlatıp durdurabileceğimiz dizine giderek “ls” komutu ile dosyaları listeliyoruz.
Yukarıda gördüğünüz dosyalardan “startup.sh” dosyasını çalıştırarak Tomcat’i başlatabilirsiniz veya “shutdown.sh” dosyasını çalıştırarak Tomcat’i durdurabilirsiniz. Tomcat’i başlatmadan önce bir kaç konfigürasyon yapalım.
cd ..
cd conf
vi tomcat-users.xml
Yukarıdaki komutları çalıştırarak “conf” dizinine gidiyoruz ve “tomcat-users.xml” dosyasını açıyoruz. Bu dosyada Tomcat’i kullanacak hesapları ve rolleri tanımlayabiliyoruz.
<?xml version="1.0" encoding="UTF-8"?> | |
<!-- | |
Licensed to the Apache Software Foundation (ASF) under one or more | |
contributor license agreements. See the NOTICE file distributed with | |
this work for additional information regarding copyright ownership. | |
The ASF licenses this file to You under the Apache License, Version 2.0 | |
(the "License"); you may not use this file except in compliance with | |
the License. You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 | |
Unless required by applicable law or agreed to in writing, software | |
distributed under the License is distributed on an "AS IS" BASIS, | |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
See the License for the specific language governing permissions and | |
limitations under the License. | |
--> | |
<tomcat-users xmlns="http://tomcat.apache.org/xml" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd" | |
version="1.0"> | |
<!-- | |
NOTE: By default, no user is included in the "manager-gui" role required | |
to operate the "/manager/html" web application. If you wish to use this app, | |
you must define such a user - the username and password are arbitrary. It is | |
strongly recommended that you do NOT use one of the users in the commented out | |
section below since they are intended for use with the examples web | |
application. | |
--> | |
<!-- | |
NOTE: The sample user and role entries below are intended for use with the | |
examples web application. They are wrapped in a comment and thus are ignored | |
when reading this file. If you wish to configure these users for use with the | |
examples web application, do not forget to remove the <!.. ..> that surrounds | |
them. You will also need to set the passwords to something appropriate. | |
--> | |
<role rolename="manager-gui"/> | |
<role rolename="manager-script"/> | |
<user username="jenkins" password="123" roles="manager-script"/> | |
<user username="berkay" password="123" roles="manager-gui,manager-script"/> | |
</tomcat-users> |
“tomcat-users.xml” dosyasının içeriğini yukarıdaki gibi güncelliyoruz.
“manager-gui” rolü kullanıcıya Tomcat arayüzünün yönetim ekranına giriş yetkisi verir. “manager-script” rolü ise kullanıcıya Tomcat üzerinde işlem yapabilme yetkisini verir.
Ben burada iki farklı kullanıcı oluşturdum. Birini sadece Jenkins üzerinde Tomcat’i çalıştırmak için kullanacağım, diğerini ise genel olarak Tomcat üzerindeki işlemlerim için kullanıyor olacağım. Jenkins kurulumunu sonraki yazılarda anlatacağım.
Burada “vi” metin editörünü kullanmayı bilmiyorsanız farklı bir editör kullanabilirsiniz veya internetten çok kolay bir şekilde nasıl kullanılacağını öğrenebilirsiniz.
find / -name context.xml
Tomcat arayüzündeki yönetim ekranına erişmek için bir kaç değişiklik yapmamız gerekiyor. Yukarıdaki komut ile “context.xml” dosyalarını sunucumuzda arıyoruz.
vi /opt/tomcat/webapps/host-manager/META-INF/context.xml
Öncelikle yukarıdaki komut ile “host-manager” dizini altındaki “context.xml” dosyasını açıyoruz.
<?xml version="1.0" encoding="UTF-8"?> | |
<!-- | |
Licensed to the Apache Software Foundation (ASF) under one or more | |
contributor license agreements. See the NOTICE file distributed with | |
this work for additional information regarding copyright ownership. | |
The ASF licenses this file to You under the Apache License, Version 2.0 | |
(the "License"); you may not use this file except in compliance with | |
the License. You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 | |
Unless required by applicable law or agreed to in writing, software | |
distributed under the License is distributed on an "AS IS" BASIS, | |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
See the License for the specific language governing permissions and | |
limitations under the License. | |
--> | |
<Context antiResourceLocking="false" privileged="true" > | |
<CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor" | |
sameSiteCookies="strict" /> | |
<!-- <Valve className="org.apache.catalina.valves.RemoteAddrValve" | |
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> --> | |
<Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/> | |
</Context> |
Dosyayı yukarıdaki gibi düzenleyip kaydediyoruz. Remote olarak Tomcat’in yönetim arayüzüne giriş yapabilmek için “Valve” kısmını yorum satırı haline getirdik.
vi /opt/tomcat/webapps/manager/META-INF/context.xml
<?xml version="1.0" encoding="UTF-8"?> | |
<!-- | |
Licensed to the Apache Software Foundation (ASF) under one or more | |
contributor license agreements. See the NOTICE file distributed with | |
this work for additional information regarding copyright ownership. | |
The ASF licenses this file to You under the Apache License, Version 2.0 | |
(the "License"); you may not use this file except in compliance with | |
the License. You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 | |
Unless required by applicable law or agreed to in writing, software | |
distributed under the License is distributed on an "AS IS" BASIS, | |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
See the License for the specific language governing permissions and | |
limitations under the License. | |
--> | |
<Context antiResourceLocking="false" privileged="true" > | |
<CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor" | |
sameSiteCookies="strict" /> | |
<!-- <Valve className="org.apache.catalina.valves.RemoteAddrValve" | |
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> --> | |
<Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/> | |
</Context> |
Yukarıdaki komut ile “manager” dizini altındaki “context.xml” dosyasını açarak aynı şekilde düzenliyoruz.
cd ..
cd bin
ls
Yukarıdaki komutlar ile “bin” dizinine gidiyoruz.
./startup.sh
Yukarıdaki komut ile “bin” dizinindeyken Tomcat’i başlatabiliriz.
./shutdown.sh
Yukarıdaki komut ile “bin” dizinindeyken açık olan Tomcat’i durdurabiliriz.
“startup.sh” dosyasını çalıştırdığımızda yukarıdaki gibi Tomcat’in başlatıldığını görebiliriz. Şimdi sunucumuzun “8080” portunu remote olarak erişebilecek şekilde ayarlayalım.
AWS konsolda sunucumuzun “Security Groups” kısmındaki linke tıklıyoruz.
Açılan sayfada “Inbound” kısmını açıyoruz. Burada “Edit” seçeneğini seçiyoruz.
Yukarıdaki gibi “8080” ve “8081” port’ları için kurallar ekliyoruz. “8080” port’unu Tomcat, “8081” port’unu bir sonraki bölümde kuracağımız Jenkins için ekliyoruz. Eklediğimiz kurallar, sunucuya herhangi bir IP ile bu port’lar üzerinden erişilmesine izin veriyor.
AWS konsolda sunucumuz seçiliyken “IPv4 Public IP” alanındaki IP’yi kopyalıyoruz. “8080” port’unu ekleyerek tarayıcımızda açıyoruz.
Tomcat arayüzünün yukarıdaki gibi açıldığını görebiliriz. “Manager App” seçeneğini seçerek yönetim ekranına gidiyoruz. Buradan tarayıcı bizden kullanıcı adı ve parola girmemizi isteyecek. “tomcat-users.xml” dosyasına eklediğimiz genel işlemleri yapacağımız kullanıcı bilgilerini buraya giriyoruz.
Karşımıza Tomcat yönetim ekranı çıkacak. Bu ekran ile Tomcat üzerine uygulamamızı deploy edebiliriz.
No comments:
Post a Comment