initial-server-setup
v1.2.0
Published
Tool to setup clean ubuntu 22.04 initially with docker and nginx under the hood via ansible playbooks
Downloads
52
Readme
Initial setup tool for ubuntu 18.04
remote servers based on ansible-playbook
.
To run this tool you have to take a look at the requirements below.
ℹ️ Successfully tested with Ubuntu 22.04. It has some strange things like using legacy repos, but it is what it is. This is not used by anyone except me anyway.
What does this tool do?
All this steps will be produced on your remote server in default configuration.
initial-server-setup setup --host 123.456.78.90
⚠️ Be careful: after this steps you will be able to login only with passed ssh keys (without password) with default
or root
users.
To add more ssh keys to login from your another control nodes you have to install those ssh keys before.
- Initial ubuntu server configuration:
- install curl for transferring data with urls;
- install vim text editor to edit text files;
- install ufw firewall to protect ports;
- install git version control to manage repositories.
- create new user
default
with sudo privileges and ability to login to remote server with your local public ssh key (~/.ssh/id_rsa.pub
); - disable remote root login with password with
PermitRootLogin prohibit-password
; - setup ufw tool to allow only ssh connections and some ports (
http:80
,https:443
,:8000
).
- Install and configure docker-ce toolbox and do post-installation steps:
- install docker to manage containers;
- configure crontab for
root
to rundocker system prune --all --force
every night to clean detached images and other docker stuff to free space after deployments. - add user
default
to docker administrators group; - pull hello nginx container nginxdemos/hello;
- run hello container on
:8001
port insidelocalhost
(the container isn't published to the internet yet on this step).
- Install and configure nginx:
- install nginx to manage web servers;
- configure nginx with default configuration;
- add default server to proxy all requests from public
:8000
port to the nginx hello container.
- Install and configure certbot:
- install certbot to manage ssl certificates.
As the result you will get configured web server with nginx layer to manage web servers and with docker to run containers inside remote machine.
Also you have to be able to see the result of nginxdemos/hello container on your-domain.com:8000
.
And you will be able to login to your remote server with ssh <default|root>@<remote-server-ip|remote-server-domain>
.
Which requirements does this tool have?
Server node requirements
Server node is a node where you want to configure the environment.
Control node requirements
Control node is a node from what you are going to run setup tool.
- ssh tool with ssh copy id to install your public ssh key inside the remote server;
- generated ssh keys to connect to your remote server;
- node.js 10 to run this tool from console (you can use nvm);
- ansible to run playbooks inside the remote server.
How to install this tool?
npm i -g initial-server-setup
How to use this tool?
Basic configuration uses root
user to login into remote server and ~/.ssh/id_rsa.pub
to install ssh key inside remote server.
Also this tool creates user default
to login into remote server with ~/.ssh/id_rsa.pub
key.
initial-server-setup setup --host 123.456.78.90
Options to configure the tool
You can define the following options and full command will be like.
initial-server-setup setup --host 123.456.78.90 --root-user root --root-key ~/.ssh/id_rsa.pub --target-user default --target-key ~/.ssh/id_rsa.pub
Option | Default | Required | Description
--- | --- | --- | ---
host
| | +
| Remote server ip
or domain
.
root-user
| root
| -
| Remote sudo
user to login into clean server.
root-key
| ~/.ssh/id_rsa.pub
| -
| Remote sudo
user key to install inside remote server.
target-user
| default
| -
| Remote admin
user to create with sudo
privileges.
target-key
| ~/.ssh/id_rsa.pub
| -
| Remote admin
user key to install inside remote server.
Existed commands in the tool
You can use any command separately and every command has it own --help
.
initial-server-setup setup-docker --help
Command | Description
--- | ---
setup
[options] | General command to run all setup-*
commands.
setup-key
[options] | Install local public key to remote host.
setup-ubuntu
[options] | Do initial ubuntu setup.
setup-docker
[options] | Do docker-ce setup and run hello
container.
setup-nginx
[options] | Do nginx setup and run hello
server for the hello
container.
setup-certbot
[options] | Do certbot installation with nginx
module.
Install additional ssh keys to remote server
Copy and paste your ssh public key from another control node to what you want to give access via the following command (do not forget to use -f
flag).
ssh-copy-id -f -i ~/.ssh/different-key.pub <remote-server-ip|remote-server-domain>