Difference between revisions of "ESXi, CentOS, Ubuntu, Docker"

From Rhomicom Wiki
Jump to navigation Jump to search
 
(45 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
== Useful Commands==
 
== Useful Commands==
 +
<syntaxhighlight lang="bash" line="1">
 +
</syntaxhighlight>
 +
<syntaxhighlight lang="bash" line="1">
 +
hostnamectl set-hostname "aws-webmin.rhomicom.com"
 +
nano /etc/hosts
 +
 +
kill SIGNAL PID
 +
kill -9 2117
 +
 +
sudo netstat -tulpn | grep LISTEN
 +
sudo ss -tulpn | grep LISTEN
 +
fuser -k 25/tcp
 +
fuser -k 80/tcp
 +
fuser -k 443/tcp
 +
su - zimbra -c "zmcontrol start"
 +
systemctl stop named
 +
systemctl disable named
 +
su - zimbra -c "zmcontrol restart"
 +
 +
nc mail.rhomicom.com 25
 +
nc mail.rhomicom.com 587
 +
telnet mail.rhomicom.com 25
 +
telnet mail.rhomicom.com 587
 +
 +
lsblk -o name,rota
 +
fdisk -l
 +
du -s -B1 -h -c --apparent-size *
 +
du -csh *
 +
</syntaxhighlight>
 
  adduser rhouser
 
  adduser rhouser
 
     passwd rhouser
 
     passwd rhouser
 
     usermod -aG wheel rhouser
 
     usermod -aG wheel rhouser
 
   su - rhouser
 
   su - rhouser
 +
 +
userdel rhouser
 +
userdel -r rhouser  #del home dir
  
 
  chkconfig --add httpd
 
  chkconfig --add httpd
Line 15: Line 47:
 
   yum install epel-release
 
   yum install epel-release
 
   dnf --enablerepo=epel -y install sshpass
 
   dnf --enablerepo=epel -y install sshpass
== Docker Commands==
+
 
 +
  #Compress
 +
  tar -czvf zimbkp23Aug2021.tar.gz /opt/zimbra
 +
  #Extract/Deflate
 +
  tar -xzvf zimbkp23Aug2021.tar.gz
 +
  #Download
 +
  rsync -avH [[/cdn-cgi/l/email-protection|[email protected]]]:/home/user/ --progress --human-readable /home/user/Downloads/
 +
  #UPLOAD#
 +
  rsync -avH /home/richard/Downloads/ --progress --human-readable [[/cdn-cgi/l/email-protection|[email protected]]]:/home/user/
 +
  rsync -avHP /home/a_bkps.tar.gz --progress --human-readable -e "ssh -i some-key.pem" [[/cdn-cgi/l/email-protection|[email protected]]]:/home/user/
 +
 
 +
== Extend Linux Partition ==
 +
<syntaxhighlight lang="bash" line="1">
 +
df -hT
 +
sudo lsblk
 +
sudo growpart /dev/nvme0n1 1
 +
sudo lsblk
 +
df -hT
 +
sudo xfs_growfs -d /
 +
df -hT
 +
df -h
 +
</syntaxhighlight>
 +
==Docker Commands==
 
<syntaxhighlight lang="docker" line="1">
 
<syntaxhighlight lang="docker" line="1">
 
docker ps
 
docker ps
 +
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id #GET CONTAINER IP ADDRESS)
 
docker inspect -f  "{{ .Config.Env }}" <container_id>  
 
docker inspect -f  "{{ .Config.Env }}" <container_id>  
 
docker commit --change "ENV DEBUG=true" <container_id> rhomicom/testimage:v1.0
 
docker commit --change "ENV DEBUG=true" <container_id> rhomicom/testimage:v1.0
 
docker inspect -f "{{ .Config.Env }}" <container_id>
 
docker inspect -f "{{ .Config.Env }}" <container_id>
 
docker push rhomicom/testimage:v1.0
 
docker push rhomicom/testimage:v1.0
 +
 +
docker build -t rhomicom/alpine_nodejs:v1.0 .
 +
docker build -t tacms/php_nginx_lara:v1.0 .
 +
 +
docker exec -it tacms-mysql sh -c "cd /home/node/app/ && npm install -g npm && npm install --production=false --legacy-peer-deps && npm run build && exit"
 +
 +
# When you have your docker-compose file setup you can run a few Docker commands to build and run your containers:
 +
docker-compose build <service-name>
 +
docker-compose up <service-name>
 +
 
</syntaxhighlight>
 
</syntaxhighlight>
 
<code>sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine</code>
 
<code>sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine</code>
Line 28: Line 93:
 
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
 
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
 
sudo yum install docker-ce docker-ce-cli containerd.io
 
sudo yum install docker-ce docker-ce-cli containerd.io
sudo systemctl start docker
+
sudo systemctl start docker && sudo systemctl enable docker
 
sudo docker run hello-world
 
sudo docker run hello-world
 +
 +
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
 +
sudo chmod +x /usr/local/bin/docker-compose
 +
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
 +
docker-compose --version
 +
</syntaxhighlight>
 +
 +
==Docker Swarm==
 +
<syntaxhighlight lang="docker" line="1">
 +
docker system info
 +
docker swarm init
 +
docker swarm join #Join existing Swarm Cluster
 +
nano bb-stack.yaml
 +
  version: '3.7'
 +
  services:
 +
    bb-app:
 +
      image: bulletinboard:1.0
 +
      ports:
 +
        - "8000:8080"
 +
docker stack deploy -c bb-stack.yaml demo #Deploy Apps to swarm
 +
docker stack rm demo # Tear everything down
 +
 +
docker service create --name registry --publish published=5000,target=5000 registry:2 #Start Swarm Registry Image
 +
 +
docker-compose up
 +
docker-compose ps -a
 +
docker-compose down --volumes
 +
docker-compose push
 +
docker stack deploy --compose-file docker-compose.yml mystackname
 +
docker stack services mystackname
 +
docker service rm registry
 +
docker swarm leave --force
 +
 +
 +
Command Description
 +
docker stack deploy #Deploy a new stack or update an existing stack
 +
docker stack ls #List stacks
 +
docker stack ps #List the tasks in the stack
 +
docker stack rm #Remove one or more stacks
 +
docker stack services #List the services in the stack
 +
 +
Command Description
 +
docker service create #Create a new service
 +
docker service inspect #Display detailed information on one or more services
 +
docker service logs #Fetch the logs of a service or task
 +
docker service ls #List services
 +
docker service ps #List the tasks of one or more services
 +
docker service rm #Remove one or more services
 +
docker service rollback #Revert changes to a service’s configuration
 +
docker service scale #Scale one or multiple replicated services
 +
docker service update #Update a service
 +
</syntaxhighlight>
 +
 +
==BackupPC==
 +
<syntaxhighlight lang="docker" line="1">
 +
dnf update
 +
dnf install epel-release
 +
dnf info backuppc
 +
dnf config-manager –set-enabled PowerTools
 +
dnf install -y backuppc
 +
 +
nano /etc/BackupPC/config.pl
 +
nano /etc/httpd/conf.d/BackupPC.conf
 +
htpasswd -c /etc/BackupPC/.backuppc bkpadmin
 +
chmod 666 /etc/BackupPC/.backuppc
 +
 +
yum -y install which openssh openssh-server openssh-clients openssl-libs nano rsync unzip net-tools NetworkManager-tui sysstat perl-core libaio nmap-ncat libstdc++.so.6 wget tar
 +
dnf --enablerepo=epel -y install sshpass
 +
 +
nano /etc/httpd/conf/httpd.conf
 +
mv /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.d/welcome.conf.old
 +
sed -i 's/Options Indexes FollowSymLinks/Options -Indexes +FollowSymLinks/' /etc/httpd/conf/httpd.conf
 +
httpd -t
 +
systemctl enable --now httpd
 +
systemctl enable --now backuppc
 +
systemctl status backuppc
 +
sudo -u backuppc /usr/share/BackupPC/bin/BackupPC_serverMesg status info
 +
sudo -u backuppc /usr/share/BackupPC/bin/BackupPC_serverMesg status hosts
 +
sudo -u backuppc /usr/share/BackupPC/bin/BackupPC_serverMesg status jobs
 +
firewall-cmd --add-service={http,https} --permanent
 +
 +
systemctl restart httpd
 +
systecmctl restart backuppc
 +
systemctl status backuppc
 +
htpasswd -c /etc/BackupPC/.backuppc bkpadmin
 +
nano /etc/httpd/conf.d/BackupPC.conf
 +
 +
</syntaxhighlight>
 +
==Linux Rescue Mode==
 +
<syntaxhighlight lang="docker" line="1">
 +
mkdir -p /media/sda
 +
mount -o exec,barrier=0 /dev/sda /media/sda
 +
mount -o remount,exec,barrier=0 /dev/sda /media/sda
 +
cd /media/sda
 +
mount -t proc proc proc/
 +
mount -t sysfs sys sys/
 +
mount -o bind /dev dev/
 +
mount -t devpts pts dev/pts/
 +
chroot /media/sda /bin/bash
 +
 +
#NB if /etc/shadow or /etc/passwd files are edited manually, you might need to disable SELINUX or restore their SELINUX settings
 +
</syntaxhighlight>
 +
==CentOS Networking==
 +
<syntaxhighlight lang="shell" line="1">
 +
nano /etc/sysconfig/network
 +
 +
HOSTNAME=mail.bhandari.com
 +
nano /etc/sysconfig/network-scripts/ifcfg-eth0
 +
-----------------------------------------------------------------------
 +
DEVICE="eth0"
 +
IPADDR=192.168.1.221
 +
NETMASK=255.255.255.0
 +
HWADDR="00:16:D4:39:5B:6F"
 +
NM_CONTROLLED="yes"
 +
ONBOOT="yes"
 +
-----------------------------------------------------------------------
 +
#Restart Network Services..
 +
service network restart
 +
</syntaxhighlight>
 +
 +
 +
==Amazon Linux 2==
 +
<syntaxhighlight lang="shell" line="1">
 +
amazon-linux-extras install -y nginx1
 +
yum install -y mod_ssl
 +
amazon-linux-extras install -y epel
 +
sudo systemctl start nginx
 +
sudo systemctl enable nginx
 +
yum -y install git which openssh openssh-server openssh-clients openssl-libs nano rsync unzip net-tools NetworkManager-tui sysstat perl-core libaio nmap-ncat libstdc++.so.6 wget tar
 +
 +
sudo yum update -y
 +
sudo amazon-linux-extras install docker
 +
sudo service docker start
 +
sudo systemctl enable docker
 +
 +
sudo usermod -a -G docker ec2-user
 +
 +
sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) -o /usr/bin/docker-compose
 +
sudo chmod +x /usr/bin/docker-compose
 +
docker-compose version
 +
 +
 +
iptables-save > IPtablesbackup.txt
 +
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
 +
sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT
 +
sudo iptables -L
 +
service iptables save
 +
iptables-restore < IPtablesbackup.txt
 +
 +
 +
sudo amazon-linux-extras install epel -y
 +
sudo systemctl stop nginx
 +
sudo yum install yum-utils
 +
sudo yum install -y certbot python-certbot-nginx python-certbot-apache
 +
sudo yum remove -y python-certbot-apache
 +
sudo certbot certonly --standalone --debug -d api.example.org
 +
 +
docker pull rhomicom/rho-erp-base:v1.1
 +
docker pull adminer
 +
docker pull mysql:5.7
 +
 +
sudo service docker restart
 +
 +
docker build -t rhomicom/rho-php-base:v1.0 .
 +
mkdir -p /etc/ssl/certs/
 +
mkdir -p /etc/ssl/private
 +
openssl req -newkey rsa:4096 -nodes -keyout /etc/ssl/private/srvr.key -x509 -days 365 -out /etc/ssl/certs/srvr.crt -subj "/C=GH/ST=Greater Accra/L=Accra/O=Rhomicom Demo/OU=IT/CN=*.rhomicom.com/[email protected]"
 +
 
</syntaxhighlight>
 
</syntaxhighlight>

Latest revision as of 13:17, 9 December 2023

Useful Commands

hostnamectl set-hostname "aws-webmin.rhomicom.com"
nano /etc/hosts

kill SIGNAL PID
kill -9 2117

sudo netstat -tulpn | grep LISTEN
sudo ss -tulpn | grep LISTEN
fuser -k 25/tcp
fuser -k 80/tcp
fuser -k 443/tcp
su - zimbra -c "zmcontrol start"
systemctl stop named
systemctl disable named
su - zimbra -c "zmcontrol restart"

nc mail.rhomicom.com 25
nc mail.rhomicom.com 587
telnet mail.rhomicom.com 25
telnet mail.rhomicom.com 587

lsblk -o name,rota
fdisk -l
du -s -B1 -h -c --apparent-size *
du -csh *
adduser rhouser
   passwd rhouser
   usermod -aG wheel rhouser
  su - rhouser
userdel rhouser
userdel -r rhouser  #del home dir
chkconfig --add httpd
chkconfig httpd on
chkconfig httpd off
chkconfig --del httpd
 yum -y install which openssh openssh-server openssh-clients openssl-libs nano rsync unzip net-tools NetworkManager-tui sysstat perl-core libaio nmap-ncat libstdc++.so.6 wget tar 
 yum install epel-release
 dnf --enablerepo=epel -y install sshpass
 
 #Compress
 tar -czvf zimbkp23Aug2021.tar.gz /opt/zimbra
 #Extract/Deflate
 tar -xzvf zimbkp23Aug2021.tar.gz
 #Download
 rsync -avH [email protected]:/home/user/ --progress --human-readable /home/user/Downloads/
 #UPLOAD#
 rsync -avH /home/richard/Downloads/ --progress --human-readable [email protected]:/home/user/
 rsync -avHP /home/a_bkps.tar.gz --progress --human-readable -e "ssh -i some-key.pem" [email protected]:/home/user/

Extend Linux Partition

df -hT
sudo lsblk
sudo growpart /dev/nvme0n1 1
sudo lsblk
df -hT
sudo xfs_growfs -d /
df -hT
df -h

Docker Commands

docker ps
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id #GET CONTAINER IP ADDRESS)
docker inspect -f  "{{ .Config.Env }}" <container_id> 
docker commit --change "ENV DEBUG=true" <container_id> rhomicom/testimage:v1.0
docker inspect -f "{{ .Config.Env }}" <container_id>
docker push rhomicom/testimage:v1.0

docker build -t rhomicom/alpine_nodejs:v1.0 .
docker build -t tacms/php_nginx_lara:v1.0 .

docker exec -it tacms-mysql sh -c "cd /home/node/app/ && npm install -g npm && npm install --production=false --legacy-peer-deps && npm run build && exit"

# When you have your docker-compose file setup you can run a few Docker commands to build and run your containers:
docker-compose build <service-name>
docker-compose up <service-name>

sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine

sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install docker-ce docker-ce-cli containerd.io
sudo systemctl start docker && sudo systemctl enable docker
sudo docker run hello-world

sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
docker-compose --version

Docker Swarm

docker system info
docker swarm init
docker swarm join #Join existing Swarm Cluster
nano bb-stack.yaml
  version: '3.7'
  services:
    bb-app:
      image: bulletinboard:1.0
      ports:
        - "8000:8080"
docker stack deploy -c bb-stack.yaml demo #Deploy Apps to swarm
docker stack rm demo # Tear everything down

docker service create --name registry --publish published=5000,target=5000 registry:2 #Start Swarm Registry Image

docker-compose up
docker-compose ps -a
docker-compose down --volumes
docker-compose push
docker stack deploy --compose-file docker-compose.yml mystackname
docker stack services mystackname
docker service rm registry
docker swarm leave --force


Command	Description
docker stack deploy #Deploy a new stack or update an existing stack
docker stack ls #List stacks
docker stack ps	#List the tasks in the stack
docker stack rm	#Remove one or more stacks
docker stack services	#List the services in the stack

Command	Description
docker service create	#Create a new service
docker service inspect	#Display detailed information on one or more services
docker service logs	#Fetch the logs of a service or task
docker service ls	#List services
docker service ps	#List the tasks of one or more services
docker service rm	#Remove one or more services
docker service rollback	#Revert changes to a service’s configuration
docker service scale	#Scale one or multiple replicated services
docker service update	#Update a service

BackupPC

dnf update
dnf install epel-release
dnf info backuppc
dnf config-manager –set-enabled PowerTools
dnf install -y backuppc

nano /etc/BackupPC/config.pl
nano /etc/httpd/conf.d/BackupPC.conf
htpasswd -c /etc/BackupPC/.backuppc bkpadmin
chmod 666 /etc/BackupPC/.backuppc

yum -y install which openssh openssh-server openssh-clients openssl-libs nano rsync unzip net-tools NetworkManager-tui sysstat perl-core libaio nmap-ncat libstdc++.so.6 wget tar
dnf --enablerepo=epel -y install sshpass

nano /etc/httpd/conf/httpd.conf
mv /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.d/welcome.conf.old
sed -i 's/Options Indexes FollowSymLinks/Options -Indexes +FollowSymLinks/' /etc/httpd/conf/httpd.conf
httpd -t
systemctl enable --now httpd
systemctl enable --now backuppc
systemctl status backuppc
sudo -u backuppc /usr/share/BackupPC/bin/BackupPC_serverMesg status info
sudo -u backuppc /usr/share/BackupPC/bin/BackupPC_serverMesg status hosts
sudo -u backuppc /usr/share/BackupPC/bin/BackupPC_serverMesg status jobs
firewall-cmd --add-service={http,https} --permanent

systemctl restart httpd
systecmctl restart backuppc
systemctl status backuppc
htpasswd -c /etc/BackupPC/.backuppc bkpadmin
nano /etc/httpd/conf.d/BackupPC.conf

Linux Rescue Mode

mkdir -p /media/sda
mount -o exec,barrier=0 /dev/sda /media/sda
mount -o remount,exec,barrier=0 /dev/sda /media/sda
cd /media/sda
mount -t proc proc proc/
mount -t sysfs sys sys/
mount -o bind /dev dev/
mount -t devpts pts dev/pts/
chroot /media/sda /bin/bash

#NB if /etc/shadow or /etc/passwd files are edited manually, you might need to disable SELINUX or restore their SELINUX settings

CentOS Networking

nano /etc/sysconfig/network

HOSTNAME=mail.bhandari.com
nano /etc/sysconfig/network-scripts/ifcfg-eth0
-----------------------------------------------------------------------
DEVICE="eth0"
IPADDR=192.168.1.221
NETMASK=255.255.255.0
HWADDR="00:16:D4:39:5B:6F"
NM_CONTROLLED="yes"
ONBOOT="yes"
-----------------------------------------------------------------------
#Restart Network Services..
service network restart


Amazon Linux 2

amazon-linux-extras install -y nginx1
yum install -y mod_ssl
amazon-linux-extras install -y epel
sudo systemctl start nginx
 sudo systemctl enable nginx
 yum -y install git which openssh openssh-server openssh-clients openssl-libs nano rsync unzip net-tools NetworkManager-tui sysstat perl-core libaio nmap-ncat libstdc++.so.6 wget tar
 
 sudo yum update -y
 sudo amazon-linux-extras install docker
 sudo service docker start
 sudo systemctl enable docker
 
 sudo usermod -a -G docker ec2-user
 
 sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) -o /usr/bin/docker-compose
 sudo chmod +x /usr/bin/docker-compose
 docker-compose version


iptables-save > IPtablesbackup.txt
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT
sudo iptables -L
service iptables save
iptables-restore < IPtablesbackup.txt 


sudo amazon-linux-extras install epel -y
sudo systemctl stop nginx
sudo yum install yum-utils
sudo yum install -y certbot python-certbot-nginx python-certbot-apache
sudo yum remove -y python-certbot-apache
sudo certbot certonly --standalone --debug -d api.example.org

docker pull rhomicom/rho-erp-base:v1.1
docker pull adminer
docker pull mysql:5.7

sudo service docker restart

docker build -t rhomicom/rho-php-base:v1.0 .
mkdir -p /etc/ssl/certs/
mkdir -p /etc/ssl/private
openssl req -newkey rsa:4096 -nodes -keyout /etc/ssl/private/srvr.key -x509 -days 365 -out /etc/ssl/certs/srvr.crt -subj "/C=GH/ST=Greater Accra/L=Accra/O=Rhomicom Demo/OU=IT/CN=*.rhomicom.com/[email protected]"