From 756e878bc14ba874833761b7839c08cae2e5f9c6 Mon Sep 17 00:00:00 2001 From: Eliezer Croitoru Date: Thu, 21 Nov 2024 01:30:10 +0200 Subject: [PATCH] Added self signed certificate for rocky linux and rocky config. Also added mariadb-latest install --- .gitignore | 4 ++ Makefile | 25 ++++++++ gen-self-signed-cert.sh | 8 +++ install-latest-mariadb-rocky.sh | 13 ++++ prepare-gitea-db.sql | 6 ++ rocky-nginx.conf | 106 ++++++++++++++++++++++++++++++++ 6 files changed, 162 insertions(+) create mode 100644 .gitignore create mode 100755 gen-self-signed-cert.sh create mode 100755 install-latest-mariadb-rocky.sh create mode 100644 prepare-gitea-db.sql create mode 100644 rocky-nginx.conf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..88056fe --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +cert.pem +key.pem +gitea-linux-amd64 +mariadb_repo_setup diff --git a/Makefile b/Makefile index c6054b2..76c06fb 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,9 @@ install-dependencies-rocky: dnf -y install mariadb-server git --version +install-latest-mariadb-rocky: + bash install-latest-mariadb-rocky.sh + enable-mariadb: systemctl daemon-reload systemctl enable mariadb @@ -23,6 +26,9 @@ enable-mariadb: start-mariadb: systemctl start mariadb +prepare-db: + mysql < prepare-gitea-db.sql + enable-nginx: systemctl daemon-reload systemctl enable nginx @@ -30,6 +36,18 @@ enable-nginx: start-nginx: systemctl start nginx +stop-nginx: + systemctl stop nginx + +restart-nginx: stop-nginx start-nginx + +enable-gitea: + systemctl daemon-reload + systemctl enable gitea + +start-gitea: + systemctl start gitea + create-user-debian: adduser --system --shell /bin/bash --gecos 'Git Version Control' \ --group --disabled-password --home /home/git git @@ -93,4 +111,11 @@ install-nginx-debian: install-nginx-rocky: dnf -y install nginx +create-nginx-ssl-dir: + mkdir -pv /etc/ssl/nginx +generate-self-signed-certificate: + bash gen-self-signed-cert.sh + +install-nginx-conf-rocky: + cp -vf rocky-nginx.conf /etc/nginx/nginx.conf diff --git a/gen-self-signed-cert.sh b/gen-self-signed-cert.sh new file mode 100755 index 0000000..f1d6724 --- /dev/null +++ b/gen-self-signed-cert.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +openssl req -newkey rsa:4096 -nodes -keyout \ + key.pem -x509 -sha256 -days 3650 -subj "/C=IL/ST=CE/L=Center/O=NgTech LTD/OU=IT/CN=gitea.ngtech.home" \ + -addext "subjectAltName = DNS:*.ngtech.home, DNS:localhost, DNS:127.0.0.1" -out cert.pem + +cp -vf key.pem /etc/ssl/nginx/key.pem +cp -vf cert.pem /etc/ssl/nginx/cert.pem diff --git a/install-latest-mariadb-rocky.sh b/install-latest-mariadb-rocky.sh new file mode 100755 index 0000000..b40c352 --- /dev/null +++ b/install-latest-mariadb-rocky.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +set -e +set -x + +wget "https://r.mariadb.com/downloads/mariadb_repo_setup" -O "mariadb_repo_setup" +bash mariadb_repo_setup + +dnf remove mariadb-gssapi-server -y +dnf install MariaDB-server -y + +set +e +set +x diff --git a/prepare-gitea-db.sql b/prepare-gitea-db.sql new file mode 100644 index 0000000..42ffbc6 --- /dev/null +++ b/prepare-gitea-db.sql @@ -0,0 +1,6 @@ +CREATE DATABASE giteadb CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_bin'; +CREATE USER 'gitea'@'%' IDENTIFIED BY 'gitea'; +GRANT ALL PRIVILEGES ON giteadb.* TO 'gitea'; +FLUSH PRIVILEGES; + + diff --git a/rocky-nginx.conf b/rocky-nginx.conf new file mode 100644 index 0000000..dd0c531 --- /dev/null +++ b/rocky-nginx.conf @@ -0,0 +1,106 @@ +# For more information on configuration, see: +# * Official English Documentation: http://nginx.org/en/docs/ +# * Official Russian Documentation: http://nginx.org/ru/docs/ + +user nginx; +worker_processes auto; +error_log /var/log/nginx/error.log; +pid /run/nginx.pid; + +# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic. +include /usr/share/nginx/modules/*.conf; + +events { + worker_connections 1024; +} + +http { + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 4096; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + # Load modular configuration files from the /etc/nginx/conf.d directory. + # See http://nginx.org/en/docs/ngx_core_module.html#include + # for more information. + include /etc/nginx/conf.d/*.conf; + + server { + listen 80; + listen [::]:80; + server_name _; + root /usr/share/nginx/html; + + location / { + client_max_body_size 8192M; + proxy_pass http://localhost:3000; + proxy_set_header Connection $http_connection; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + # Load configuration files for the default server block. + include /etc/nginx/default.d/*.conf; + + error_page 404 /404.html; + location = /404.html { + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + } + } + +# Settings for a TLS enabled server. +# + server { + listen 443 ssl http2; + listen [::]:443 ssl http2; + server_name _; + root /usr/share/nginx/html; + + ssl_certificate "/etc/ssl/nginx/cert.pem"; + ssl_certificate_key "/etc/ssl/nginx/key.pem"; + ssl_session_cache shared:SSL:1m; + ssl_session_timeout 10m; + ssl_ciphers PROFILE=SYSTEM; + ssl_prefer_server_ciphers on; + + location / { + client_max_body_size 8192M; + proxy_pass http://localhost:3000; + proxy_set_header Connection $http_connection; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } +# +# # Load configuration files for the default server block. + include /etc/nginx/default.d/*.conf; +# + error_page 404 /404.html; + location = /40x.html { + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + } + } + +} +