XYBRCODE

RANDOM BITS

Search Results

Ubuntu 16.04, Wildfly 10, Mysql Setup Script

2016-01-01

UPDATE: Working on a version for Google Compute Engine ->https://goo.gl/BwqkBw

DO NOT USE FOR PRODUCTION : Firewall is disabled along with Wildfly IP filters

Runwget -q -O - https://goo.gl/NGfDVv > install.sh && chmod +x install.sh && ./install.shas root to run it

#!/bin/bash
#wget -q -O - https://goo.gl/NGfDVv > install.sh
#chmod +x install.sh
#./install.sh

echo "
****************************************
* Java Application Server Setup Script *
****************************************"

#check for root
USER=$(id -u)
if [ $USER -ne "0" ]; then
  echo "Must be root" && exit;
fi

#Collect Password
echo "Enter a password to be used throughout this setup:"
read passw

#Disable Firewall
ufw disable

#Port Forwarding
iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-port 8443
iptables-save > /etc/iptables.rules
cat <<EOT >> /etc/network/if-pre-up.d/iptablesload
#!/bin/sh
iptables-restore < /etc/iptables.rules
exit 0
EOT
chmod +x /etc/network/if-pre-up.d/iptablesload

#Open SSH
sed -i -e 's,without-password,yes,g' /etc/ssh/sshd_config

#Setup Dependencies 
apt-get update && apt-get --assume-yes upgrade
apt-get --assume-yes install openjdk-8-jdk-headless unzip mysql-server

#Cofig MySQL
sed -i -e 's,bind-address,#bind-address,g' /etc/mysql/mysql.conf.d/mysqld.cnf
echo "Enter MySQL root password at prompt"
mysql -D mysql -u root -p -e "UPDATE user SET host='%' WHERE user='root';"
service mysql restart

#Setup WildFly User
adduser --gecos "" --no-create-home --disabled-password --disabled-login wildfly

#Download and Install Wildfly
cd /srv
wget http://download.jboss.org/wildfly/10.0.0.Final/wildfly-10.0.0.Final.tar.gz
tar -xvzf wildfly-10.0.0.Final.tar.gz
ln -s wildfly-10.0.0.Final wildfly
rm wildfly-10.0.0.Final.tar.gz
cp /srv/wildfly/docs/contrib/scripts/init.d/wildfly-init-debian.sh /etc/init.d/wildfly
update-rc.d wildfly defaults
cp /srv/wildfly/docs/contrib/scripts/init.d/wildfly.conf /etc/default/wildfly

#Download and Install MySQL Driver
wget http://cdn.mysql.com//Downloads/Connector-J/mysql-connector-java-5.1.39.zip
unzip mysql-connector-java-5.1.39.zip
rm mysql-connector-java-5.1.39.zip
mkdir -p /srv/wildfly/modules/system/layers/base/com/mysql/main
mv mysql-connector-java-5.1.39/mysql-connector-java-5.1.39-bin.jar /srv/wildfly/modules/system/layers/base/com/mysql/main/.
ln -s /srv/wildfly/modules/system/layers/base/com/mysql/main/mysql-connector-java-5.1.39-bin.jar /srv/wildfly/modules/system/layers/base/com/mysql/main/mysql-connector-java-bin.jar
rm -r mysql-connector-java-5.1.39
cat <<EOT >> /srv/wildfly/modules/system/layers/base/com/mysql/main/module.xml
<?xml version="1.0" ?>

<module xmlns="urn:jboss:module:1.3" name="com.mysql">
    <resources>
        <resource-root path="mysql-connector-java-bin.jar"/>
    </resources>
    <dependencies>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/>
    </dependencies>
</module>
EOT

#Fix Permissions
chown -R wildfly:wildfly wildfly*

#Generate keystore
keytool -genkeypair \
        -alias serverkey \
        -keyalg RSA \
        -keysize 2048 \
        -validity 3650 \
        -keystore /srv/wildfly/standalone/configuration/server.keystore \
        -keypass $passw \
        -storepass $passw \
        -dname "CN=LocalAdministrator,O=LocalDomain,C=US"
        
#Download Wildfly Password tool
wget https://dl.dropboxusercontent.com/u/356692/xybrcode/software/wpc.jar


#Config Wildfly
perl -i -pe 's/\<drivers\>/\<drivers\>
    \<driver name="mysql" module="com.mysql"\>
        \<driver-class\>com.mysql.jdbc.Driver\<\/driver-class\>
    \<\/driver\>/g' /srv/wildfly/standalone/configuration/standalone.xml
    
        
sed -i -e 's,<http-listener name="default" socket-binding="http" redirect-socket="https"/>,<http-listener name="default" socket-binding="http"/>\n\t\t<https-listener name="https-server" security-realm="ManagementRealm" socket-binding="https"/>,g' /srv/wildfly/standalone/configuration/standalone.xml
sed -i -e "s,<security-realm name=\"ManagementRealm\">,<security-realm name=\"ManagementRealm\">\n\t\t<server-identities>\n\t\t\t<ssl>\n\t\t\t\t<keystore path=\"server.keystore\" relative-to=\"jboss.server.config.dir\" keystore-password=\"$passw\" alias=\"serverkey\" key-password=\"$passw\"/>\n\t\t\t</ssl>\n\t\t</server-identities>,g" /srv/wildfly/standalone/configuration/standalone.xml
    
sed -i -e 's,<inet-address value="${jboss.bind.address.management:127.0.0.1}"/>,<any-address/>,g' /srv/wildfly/standalone/configuration/standalone.xml
sed -i -e 's,<inet-address value="${jboss.bind.address:127.0.0.1}"/>,<any-address/>,g' /srv/wildfly/standalone/configuration/standalone.xml
sed -i -e '/default-bindings/ d' /srv/wildfly/standalone/configuration/standalone.xml

sed -i -e 's,# JBOSS_HOME,JBOSS_HOME,g' /etc/default/wildfly
sed -i -e 's,/opt/wildfly,/srv/wildfly,g' /etc/default/wildfly

echo ""

echo "Adding user admin with password '$passw'"
java -jar wpc admin $passw >> /srv/wildfly/standalone/configuration/mgmt-users.properties

rm wpc.jar

#wait for service
echo -n "Starting Wildfly..."
service wildfly start

while true
do
if [[ -z $(pgrep java) ]]
then
    echo -n "." && sleep 1
else
    echo "PID : $(pgrep java)"
    break
fi
done

echo "Done. Please reboot."