Lxc

De WikiMar
Dreceres ràpides: navegació, cerca

CentOS

Add EPEL repository

http://www.tecmint.com/how-to-enable-epel-repository-for-rhel-centos-6-5/

## RHEL/CentOS 7 64-Bit ##
wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
rpm -ivh epel-release-7-5.noarch.rpm


Install LXC

yum install lxc lxc-templates

Other install

yum install bridge-utils 
yum install -y libvirt
systemctl start libvirtd
brctl show

bridge name bridge id STP enabled interfaces virbr0 8000.fea2866efadb yes veth7ATCJK


Config Autostart

vi /var/lib/lxc/centos1/config

The startup related values that are available are:

lxc.start.auto = 0 (disabled) or 1 (enabled)
lxc.start.delay = 0 (delay in second to wait after starting the container)
lxc.start.order = 0 (priority of the container, higher value means starts earlier)
lxc.group = group1,group2,group3,… (groups the container is a member of)


When running the following command this container will autostart

lxc-autostart

Enable the service to autostart on boot

systemctl enable lxc.service

Prevent excess journald activity

By default, lxc symlinks /dev/kmsg to /dev/console, this leads to journald running at 100% CPU usage all the time. To prevent the symlink, use:

vi /var/lib/lxc/centos1/config
lxc.kmsg = 0

More info: https://wiki.archlinux.org/index.php/Linux_Containers#Systemd_considerations_.28required.29

Image creation

lxc-create -n centos1 -t centos
lxc-start -n centos1

Login to Container: The root password is set in the lxc template.


Normal operations

Start

lxc-start -n centos1

Attach

lxc-attach -n centos1

Stop

To stop:

lxc-stop -n centos1 

To kill:

lxc-stop -n centos1 -k

LAMP installation

yum install httpd
systemctl enable httpd

only before Centos7:

sudo yum install mysql-server
sudo service mysqld start
sudo /usr/bin/mysql_secure_installation

On Centos7 install MariaDB: https://downloads.mariadb.org/mariadb/repositories/#mirror=host-europe&distro=CentOS&distro_release=centos7-amd64--centos7&version=10.1

Here is your custom MariaDB YUM repository entry for CentOS. Copy and paste it into a file under /etc/yum.repos.d/ (we suggest naming the file MariaDB.repo or something similar).

# MariaDB 10.1 CentOS repository list - created 2016-02-29 20:27 UTC
# http://mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

After the file is in place, install MariaDB with:

sudo yum install MariaDB-server MariaDB-client


sudo yum install php php-mysql
yum search php-
yum info  name of the module
yum install php-fpm
sudo chkconfig httpd on
sudo chkconfig mysqld on

more info:


Fix for Apache

https://www.marc.info/?l=lxc-users&m=142483647735314&w=2 I have trouble updating httpd in my containers. > containers, LXC 1.0.3 > >

>error: unpacking of archive failed on file /usr/bin/systemd-detect-virt:
> cpio: cap_set_file
>

Look for /usr/share/lxc/config/fedora.common.conf (or whatever it is on fedora, try "rpm -ql lxc"), then comment out this line

vi /usr/share/lxc/config/centos.common.conf
lxc.cap.drop = setfcap



Installed packets in the container for Apache + Php 5.5 + mariadb(mysql)

    command_line = --installroot /var/cache/lxc/centos/x86_64/7/partial -y --nogpgcheck --releasever=7 install yum initscripts passwd rsyslog vim-minimal openssh-server openssh-clients dhclient chkconfig rootfiles policycoreutils
    command_line = install MariaDB-server MariaDB-client
    command_line = install centos-release-scl
    command_line = install httpd mysql-server php php-pear php-xml php-mysql php-intl php-pecl-apc php-gd php-mbstring ImageMagick-perl
    command_line = install less
    command_line = install libtool httpd-devel
    command_line = install mariadb-server mariadb
    command_line = install mod_dav_svn subversion
    command_line = install nano
    command_line = install php php-mysql
    command_line = install php55 php55-php php55-php-gd php55-php-mbstring
    command_line = install php55-php-mysqlnd
    command_line = install sendmail sendmail-cf
    command_line = install vim
    command_line = install yum-cron
    command_line = install yum-utils
  • Install Named/Bind and copy /etc/named* and /var/named/*
  • Mediawiki: copy /usr/share/mediawiki/
  • install php55 and copy /etc/php*
  yum install centos-release-scl
  yum install php55 php55-php php55-php-gd php55-php-mbstring php55-php-mysqlnd
  • Edit backup /backup/mysql/mysql.sh
  • mod_ssl
yum install httpd-devel
  • mod subversion
yum install subversion mod_dav_svn
  • mod_CloudFare
yum install libtool git -y
git clone https://github.com/cloudflare/mod_cloudflare.git && cd mod_cloudflare
yum install httpd-devel
/usr/local/apache/bin/apxs -a -i -c mod_cloudflare.c
systemctl restart httpd && /usr/local/apache/bin/httpd -M|grep cloudflare
  • start and autostart all new services
systemctl enable mariadb
systemctl enable httpd
systemctl enable named

Other info

Migrate/convert existing full CentOS 6 server to LXC container: http://blog.a2o.si/2015/10/11/migrate-convert-existing-full-centos-6-server-to-lxc-container/

Linux, Apache, MySQL, PHP in an LXC Container: https://zyisrad.com/linux-apache-mysql-php-in-an-lxc-container/

Pacman roseta https://wiki.archlinux.org/index.php/Pacman/Rosetta

General info: "Linux, Apache, MySQL, PHP in an LXC Container" https://zyisrad.com/linux-apache-mysql-php-in-an-lxc-container/