Linux¶
- All the cloud and DevOps tools are made to run on Linux
- Ubuntu is based on the Debian architecture
- CentOS is based on the Red Hat Enterprise Linux (RHEL) architecture
User Accounts¶
- Root user has unlimited access to the system
- Root user needs to grant a normal user root previlege by making an entry in the
/etc/sudoers
file. The normal user can then escalate their previlege by prefixing their command withsudo
Important Commands¶
echo $SHELL
- get shell typemkdir -p user/abdur/add
- make directory hierarchycat > file.txt
- add contents to a filewhoami
- get user infoid
- get user's id and groupsu <username>
- switch usersudo su -
- switch to root userssh <username>@192.168.1.1
- ssh as a user into a systemwget <file-url> -O file.txt
- download a file
Package Managers¶
- Package managers download the necessary dependencies when installing packages in Linux
- CentOS uses Yum, an RPM (RedHat Package Manager) based package manager
- Commands
yum install ansible
- install a packageyum repolist
- list the repositoriesyum list
- list installed packagesyum list <package-name>
- search for a package in the list of installed packagesyum remove <package-name>
- remove a packageyum --show-duplicates list <package-name>
- list all the installed versions of a packageyum install ansible-2.4.2.0
- install a specific version of a package
Services¶
- Services in Linux help us configure software to run in the background and ensure that they run automatically even if the servers are rebooted. Eg. Docker
- If there are multiple interdependent services, they should follow the order of startup.
systemctl
command is used to managesystemd
services- Commands - might need to use sudo
systemctl start httpd
- start an service (HTTPD)systemctl stop httpd
- stop a running servicesystemctl status httpd
- check the status of a servicesystemctl enable httpd
- configure the service to start at startupsystemctl disable httpd
- configure the service to not start at startupsystemctl daemon-reload
- reload the systemd
Configure an application as a Service¶
- Let's assume a Python server app that runs at port 5000 and prints "Hello World"
- We want to configure this app as a service
- Create a new file
my_app.service
in the/etc/systemd/system
directory and paste the following in it systemctl daemon-reload
- reload the systemd to let it know that a new service has been configuredsystemctl start my_app
- start your app as a service- To configure the service to run when the system boots up, add the following to the service file
- To add description
- To restart the application if it crashes
- To run scripts before and after running the app
Docker as a Service¶
- Once Docker is installed, the Docker daemon runs as a background process that listens for docker commands
- Docker installation creates a service file with the following contents
Last updated: 2022-09-22