Skip to content

Instantly share code, notes, and snippets.

@luanvuhlu
Last active November 21, 2024 10:10
Show Gist options
  • Save luanvuhlu/0b7cec314d5d4a3b0c8f977745e8dd9e to your computer and use it in GitHub Desktop.
Save luanvuhlu/0b7cec314d5d4a3b0c8f977745e8dd9e to your computer and use it in GitHub Desktop.
Install Spring Boot Application in Centos
$ yum update
# Add new user and setup ssh
$ adduser luan
$ passwd luan
$ usermod –aG wheel luan
# or
$ visudo
# Add the line and save
UserName ALL=(ALL) ALL
# Copy client's public key to the server
$ ssh-copy-id username@remote_host
$ vi /etc/ssh/sshd_config
# Disable Password login (Optional)
# Change 'PasswordAuthentication' to 'no'
$ systemctl restart sshd
# Install dedpendencies
$ yum install sshpass rsync
# Install Java
$ yum install java-1.8.0-openjdk
$ java -version
$ update-alternatives --config java
$ vi .bash_profile
# Add line
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.322.b06-1.el7_9.x86_64/jre/bin/java
# Install Redis
$ yum install epel-release
$ yum install redis
# Start redis on boot
$ systemctl enable redis
$ redis-cli ping
$ vi /etc/redis.conf
# Change bind 127.0.0.1: add server's public/private ip
$ systemctl restart redis.service
$ firewall-cmd --permanent --new-zone=redis
$ firewall-cmd --permanent --zone=redis --add-port=6379/tcp
$ firewall-cmd --permanent --zone=redis --add-source=client_server_IP
$ firewall-cmd --reload
# https://www.linode.com/docs/guides/how-to-deploy-spring-boot-applications-nginx-ubuntu-16-04/
# https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-centos-7
$ yum install epel-release
$ yum install nginx
$ systemctl start nginx
$ systemctl status nginx
$ firewall-cmd --permanent --zone=public --add-service=http
$ firewall-cmd --permanent --zone=public --add-service=https
$ firewall-cmd --reload
$ systemctl enable nginx
# https://phoenixnap.com/kb/how-to-install-nginx-on-centos-7
$ vi /etc/nginx/conf.d/<any name>.conf
# Add these lines below:
server {
listen 80;
location / {
proxy_pass http://localhost:8080;
}
}
$ service nginx restart
$ service nginx status
# Install MySQL 8.0
$ curl -sSLO https://dev.mysql.com/get/mysql80-community-release-el7-5.noarch.rpm
$ md5sum mysql80-community-release-el7-5.noarch.rpm
$ rpm -ivh mysql80-community-release-el7-5.noarch.rpm
$ yum install mysql-server
$ systemctl start mysqld
$ grep 'temporary password' /var/log/mysqld.log
$ mysql_secure_installation
# Use pasword like this S99vmOYUT$py
$ mysqladmin -u root -p version
$ mysql -u root -p
# CREATE USER 'luan'@'%' IDENTIFIED BY 'i@Btu5QmlsJU';
# GRANT ALL PRIVILEGES ON *.* TO 'luan'@'%';
# FLUSH PRIVILEGES;
$ java -jar simple-spring-boot-0.0.1-SNAPSHOT.jar \
--spring.datasource.username=luan \
--spring.datasource.password=i@Btu5QmlsJU \
--server.port=8080
# https://docs.spring.io/spring-boot/docs/current/reference/html/deployment.html#deployment.installing.nix-services.init-d
$ vi /etc/systemd/system/myapp.service
$ systemctl daemon-reload
$ service myapp start
$ service myapp status
$ journalctl -u myapp
$ curl localhost
[Unit]
Description=A Spring Boot application
After=syslog.target
[Service]
User=luan
ExecStart=/usr/bin/java -Dserver.port=8080 -Dspring.datasource.username=luan -Dspring.datasource.password=i@Btu5QmlsJU -jar /home/luan/simple-spring-boot-0.0.1-SNAPSHOT.ja
r
[Install]
WantedBy=multi-user.target
$ yum remove mysql mysql-server mysql-client
$ rm -rf /var/lib/mysql
$ rpm -qa | grep mysql
# Remove all dependecies: yum remove <package name>
$ rpm -e --nodeps mysql80-community-release
$ yum localinstall https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
$ yum install mysql-server
$ systemctl start mysqld
$ grep 'temporary password' /var/log/mysqld.log |tail -1
$ mysql_secure_installation
# Use pasword like this S99vmOYUT$py
$ mysqladmin -u root -p version
$ mysql -u root -p
# CREATE USER 'luan'@'%' IDENTIFIED BY 'i@Btu5QmlsJU';
# GRANT ALL PRIVILEGES ON *.* TO 'luan'@'%';
# FLUSH PRIVILEGES;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment