LXC and LXD linux container

What’s LXC?
– API to communicate with with LXD(Linux container)

What’s LXD?
– It’s like VM for Linux containers

  • Install lxc and dependency
yum -y install epel-release

yum -y install libvirt lxc lxc-templates libcap-devel libcgroup busybox wget bridge-utils lxc-extra

systemctl start libvirtd
systemctl enable libvirtd
  • Check everything is working?
[root@lxc01~]# lxc-checkconfig
Kernel configuration not found at /proc/config.gz; searching...
Kernel configuration found at /boot/config-3.10.0-862.el7.x86_64
--- Namespaces ---
Namespaces: enabled
Utsname namespace: enabled
Ipc namespace: enabled
Pid namespace: enabled
User namespace: enabled
newuidmap is not installed
newgidmap is not installed
Network namespace: enabled
Multiple /dev/pts instances: enabled

--- Control groups ---
Cgroup: enabled
Cgroup clone_children flag: enabled
Cgroup device: enabled
Cgroup sched: enabled
Cgroup cpu account: enabled
Cgroup memory controller: enabled
Cgroup cpuset: enabled

--- Misc ---
Veth pair device: enabled
Macvlan: enabled
Vlan: enabled
Bridges: enabled
Advanced netfilter: enabled
CONFIG_NF_NAT_IPV4: enabled
CONFIG_NF_NAT_IPV6: enabled
CONFIG_IP_NF_TARGET_MASQUERADE: enabled
CONFIG_IP6_NF_TARGET_MASQUERADE: enabled
CONFIG_NETFILTER_XT_TARGET_CHECKSUM: enabled

--- Checkpoint/Restore ---
checkpoint restore: enabled
CONFIG_FHANDLE: enabled
CONFIG_EVENTFD: enabled
CONFIG_EPOLL: enabled
CONFIG_UNIX_DIAG: enabled
CONFIG_INET_DIAG: enabled
CONFIG_PACKET_DIAG: enabled
CONFIG_NETLINK_DIAG: enabled
File capabilities: enabled

Note : Before booting a new kernel, you can check its configuration
usage : CONFIG=/path/to/config /usr/bin/lxc-checkconfig

  • Create container with centos template
lxc-create -n centos7container -t centos

It will pull the centos container image from the internet and will use the centos template from /usr/share/lxc/templates/

  • Start the lxd container
lxc-start -n centos7container -d
  • List container and running
[root@lxc01 ~]# lxc-ls
centos7container

[root@lxc01  ~]# lxc-ls --active
centos7container
  • Attach to running container
lxc-attach -n centos7container
  • Stop and delete lxc container
lxc-stop -n centos7container
lxc-destroy -n centos7container

Calling function from another groovy file into Jenkins pipeline

Jenkinsfile

pipeline
{
    agent any
    stages
    {
        stage('build')
        {
            steps
            {
                script
                {
                    //first.groovy path might change as per your need
                    def var1 = load "first.groovy"
                    var1.build("php build")
                }
                sh '''
                echo "build"
                '''
            }
        }
        
        stage('deploy')
        {
            steps
            {
                script
                {
                    def var2 = load "first.groovy"
                    var2.build("php deploy")
                }
                    sh '''
                    echo "deploy"
                    '''
            }
        }
        
        
    }
}

first.groovy

def build(String arg1) {
        sh """
        echo "from build function : ${arg1}"
        """
}

def deploy(String arg2) {
        sh """
        echo "from deploy function : ${arg2}"
        """
}

return this

Output:

Running on Jenkins in /var/lib/jenkins/workspace/initedit/ss
[Pipeline] {
[Pipeline] stage
[Pipeline] { (build)
[Pipeline] script
[Pipeline] {
[Pipeline] load
[Pipeline] { (first.groovy)
[Pipeline] }
[Pipeline] // load
[Pipeline] sh
+ echo 'from build function : php build'
from build function : php build
[Pipeline] }
[Pipeline] // script
[Pipeline] sh
+ echo build
build
...........

Run cs 1.6 server with docker

  1. Install docker – https://docs.docker.com/install/linux/docker-ce/debian/
docker run -d -p 26900:26900/udp -p 27020:27020/udp -p 27015:27015/udp -p 27015:27015 -e ADMIN_STEAM=0:1:1234566 --name cs cs16ds/server:latest

github : https://github.com/JimTouz/counter-strike-docker

For interactive docker terminal change the entry point:

docker run it --entrypoint /bin/bash --name cs cs16ds/server:latest

install cs16 in linux ubuntu16

mkdir cs
cd cs
wget https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz
tar xvfz steamcmd_linux.tar.gz
sudo apt-get install lib32gcc1
./steamcmd.sh
login anonymous
force_install_dir ./cs16/
app_update 90 validate (run till you get fully installed message)
exit
cd cs16server​
./hlds_run -console -game cstrike +port 27015 +de_dust2 +maxplayers 32 -pingboost 1

Install addons:
amxmodx dproto metamod

https://wiki.alliedmods.net/Installing_AMX_Mod_X_Manually

Note: path for metamod.so should not be absolute.

http://www.amxmod.net/doc/amxmod_2010.1/en/amxusers.html


Prometheus monitoring tool

# Install Prometheus https://prometheus.io/download/

wget https://github.com/prometheus/prometheus/releases/download/v2.13.1/prometheus-2.13.1.linux-amd64.tar.gz

tar -xf prometheus-2.13.1.linux-amd64.tar.gz

mv prometheus-2.13.1.linux-amd64 /etc/prometheus

nano /etc/systemd/system/prometheus.service

[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target

[Service]
User=root
Group=root
Type=simple
ExecStart=/usr/local/bin/prometheus \
–config.file /etc/prometheus/prometheus.yml \
–storage.tsdb.path /var/lib/prometheus/ \
–web.console.templates=/etc/prometheus/consoles \
–web.console.libraries=/etc/prometheus/console_libraries

[Install]
WantedBy=multi-user.target

cd /etc/prometheus
cp prometheus promtool tsdb /usr/local/bin/

systemctl daemon-reload
systemctl enable prometheus
systemctl start prometheus

Prometheus port : 9090

# Install node_exporter

wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz

tar -xf node_exporter-0.18.1.linux-amd64.tar.gz

cp node_exporter-0.18.1.linux-amd64 /node_exporter /usr/local/bin/

nano /etc/systemd/system/node_exporter.service

[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target

[Service]
User=root
Group=root
Type=simple
ExecStart=/usr/local/bin/node_exporter

[Install]
WantedBy=multi-user.target

systemctl daemon-reload
systemctl start node_exporter
systemctl status node_exporter
systemctl enable node_exporter

# add node_exporter to prometheus.yml

systemctl restart prometheus

Gitlab backup and restore

Note : gitlab should be same version.

Manual backup:

/etc/gitlab/gitlab-secrets.json

/etc/gitlab/gitlab.rb

 

Generate backup:

gitlab-rake gitlab:backup:create

 

Restore backup:

You have run sudo gitlab-ctl reconfigure at least once.
GitLab is running. If not, start it using sudo gitlab-ctl start.

gitlab-ctl stop unicorn

gitlab-ctl stop sidekiq

gitlab-rake gitlab:backup:restore BACKUP=335565885_2019_05_20.6

restore /etc/gitlab/gitlab-secrets.json and /etc/gitlab/gitlab.rb