List of useful resources & commands i use to setup an ubuntu server
- Recent versions of Linux tend to use systemd (which uses the systemctl command), while older versions of Linux tend to use System V init (which uses the service command). If you are unsure which init system your platform uses, run the following command:
ps --no-headers -o comm 1
netstat -tulpn
dpkg-reconfigure tzdata # Update timezone interactively
service cron restart # need to restart cron service if you've updated timezones
timedatectl # Validate if set properly
- How To Install Nginx on Ubuntu 18.04
- Add Brotli support to Nginx on Ubuntu 18.04
- How To Set Up Password Authentication with Nginx on Ubuntu 14.04
- How To Secure Nginx with Let's Encrypt on Ubuntu 18.04
- Secure Nginx with Let's Encrypt on Ubuntu 18.04
Useful Commands
# To obtain a certificate
certbot --nginx -d weoneapp.com -d www.weoneapp.com
# To check renewal
certbot renew --dry-run
# To check all certificates
certbot certificates
# Certbot issues: once the certificate is auto renewed we also have to reload the nginx service.
sudo nano /etc/cron.d/certbot
0 */12 * * * root test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew --renew-hook "sudo systemctl reload nginx"
composer install --optimize-autoloader --no-dev
- How To Install WordPress with LEMP on Ubuntu 18.04
- Integrating AWS S3 & Cloudfront With Wordpress
- Install WordPress with Ubuntu 18.04, NGINX, MariaDB and PHP 7.4
- Setup Your Wordpress Site The Right Way
- Setting up an HTTPS site using Nodejs, AWS EC2, Nginx, Let's Encrypt, and Namecheap - Zeevo
- How To Set Up a Node.js App for Production on Ubuntu 18.04
# start & reload app with conf file
pm2 start ecosystem.config.js
pm2 reload ecosystem.config.js --update-env
# start & repload app without conf file
pm2 start app.js -i max --name example-api
pm2 reload app.js -i max --name example-api --update-env
# to auto start PM2 on System boot
pm2 startup
# to save the current running application state on system boot
pm2 save
# Install pm2-logrotate
pm2 install pm2-logrotate
Useful Commands
Mongo config file : /etc/mongod.conf
Mongo Logs : /var/log/mongodb
Mongo Data Dir : /var/lib/mongodb
sudo systemctl start mongod
systemctl status mongod
mongod --port 27017 --dbpath /var/lib/mongodb
# If (code=exited, status=14)
chown -R mongodb:mongodb /var/lib/mongodb
chown mongodb:mongodb /tmp/mongodb-27017.sock
# Create user
> use admin
> db.createUser({user: "weOadmin",pwd: passwordPrompt(),roles:[{role: "userAdminAnyDatabase", db: "admin" },"readWriteAnyDatabase"]})
> db.createUser({user:'weOapi', pwd: passwordPrompt(), roles:[{db:'movies', role:'readWrite'}]})
# Import a single collection
> mongoimport --db movies --collection beta_users_list beta_users_list.json --username weOapi --password secretPassword
# Import a full dump
> mongorestore dump/ -u=weOapi
# Take DB Backup
> mongodump -d movies -o back_11_aug -u weOapi -p 'secretPassword'
> cd back_11_aug && tar -cvzf movies.tar.gz weone/
Useful Commands
# Manage Service
systemctl status redis.service
systemctl start redis.service
systemctl stop redis.service
systemctl restart redis.service
# Update config
nano /etc/redis/redis.conf
# Use Password
redis-cli
auth <password>
# DEBUGGING - YOU SHOULD SEE autossh sending a request every ServerAliveInterval seconds.
AUTOSSH_DEBUG=1 autossh -M 0 -N [email protected] -o "ServerAliveInterval 10" -o "ServerAliveCountMax 3" -L 6666:localhost:3306 -vvv
ps aux | grep ssh # Check SSH process is running
ps aux | grep autossh # Check AutoSSH process is running
# Main command
autossh -f -M 0 -N [email protected] -o "ServerAliveInterval 10" -o "ServerAliveCountMax 3" -C -L 3306:localhost:3306
crontab -l # For listing
crontab -e # For editing
nano /etc/logrotate.d/cronjobs
/var/log/cron-*.log {
daily
missingok
rotate 10
compress
notifempty
size 3M
}
Welcoming more setup instructions, resources & commands.
That's all Folks. Enjoy.