miércoles, 3 de marzo de 2010

FreeBSD 8: Crear Jails.

Bien he estado viendo esto de las jails, que bonitas son, es una forma de virtualizar nativa. El handbook esta muy claro, nomas deseo aqui plasmar ciertas cosas que me ha sucedido.

Si por alguna razon ya que tenemos nuestro buildworld listo, y deseamos llevar a cabo el paso donde lo mandamos a el directorio de nuestro jail por ejemplo:

make installworld DESTDIR=$D

Pero si nuestro /tmp lo tenemos montado por seguridad con el parametro noexec, el comando anterior no funcionara y saldra con error.

Este es mi src.conf, quiero optmizarlo a el maximo para mis jails:

WITHOUT_APM="yes"
WITHOUT_ATM="yes"
WITHOUT_ASSERT_DEBUG="yes"
WITHOUT_AT="yes"
WITHOUT_AUTHPF="yes"
WITHOUT_BIND="yes"
WITHOUT_BLUETOOTH="yes"
WITHOUT_BOOT="yes"
WITHOUT_CALENDAR="yes"
WITHOUT_CDDL="yes"
WITHOUT_CVS="yes"
WITHOUT_DICT="yes"
WITHOUT_EXAMPLES="yes"
WITHOUT_FLOPPY="yes"
WITHOUT_FREEBSD_UPDATE="yes"
WITHOUT_GAMES="yes"
WITHOUT_GPIB="yes"
WITHOUT_GSSAPI="yes"
WITHOUT_INET6="yes"
WITHOUT_HTML="yes"
WITHOUT_IPFILTER="yes"
WITHOUT_IPFW="yes"
WITHOUT_IPX="yes"
WITHOUT_JAIL="yes"
WITHOUT_KERBEROS="yes"
WITHOUT_KVM="yes"
WITHOUT_LPR="yes"
WITHOUT_MAILWRAPPER="yes"
WITHOUT_MAN="yes"
WITHOUT_NDIS="yes"
WITHOUT_NIS="yes"
WITHOUT_PF="yes"
WITHOUT_PPP="yes"
WITHOUT_PMC="yes"
WITHOUT_PROFILE="yes"
WITHOUT_QUOTAS="yes"
WITHOUT_RCMDS="yes"
WITHOUT_RCS="yes"
WITHOUT_SENDMAIL="yes"
WITHOUT_SHAREDOCS="yes"
WITHOUT_SYSCONS="yes"
WITHOUT_SYSINSTALL="yes"
WITHOUT_TELNET="yes"
WITHOUT_USB="yes"
WITHOUT_WIRELESS="yes"
WITHOUT_WPA_SUPPLICANT_EAPOL="yes"

Hay muchas cosas aqui que se que no me sirven e investigando al respecto(googleando) de las que desconozco he llegado a este archivo, varios buildworld tronados, pero al fin tengo mi arhivo final.

Cuando estaba haciendo el buildworld, salio un error, desgraciadamente no alcance a plasmarlo aqui, pero este linea del src.conf me estaba causando el problema:

WITHOUT_INSTALLLIB="yes"

Enseguida me salio este otro error:

Error 2:===> usr.sbin/ifmcstat (all)

cc -O2 -pipe -DINET6 -DNDEBUG -std=gnu99 -fstack-protector -Wsystem-headers -Wall -Wno-format-y2k -Wno-uninitialized -Wno-pointer-sign -c /usr/src/usr.sbin/ifmcstat/ifmcstat.c
/usr/src/usr.sbin/ifmcstat/ifmcstat.c:170: warning: 'in6_ifinfo' used but never defined
cc -O2 -pipe -DINET6 -DNDEBUG -std=gnu99 -fstack-protector -Wsystem-headers -Wall -Wno-format-y2k -Wno-uninitialized -Wno-pointer-sign -c /usr/src/usr.sbin/ifmcstat/printb.c
cc -O2 -pipe -DINET6 -DNDEBUG -std=gnu99 -fstack-protector -Wsystem-headers -Wall -Wno-format-y2k -Wno-uninitialized -Wno-pointer-sign -o ifmcstat ifmcstat.o printb.o
ifmcstat.o(.text+0xb96): In function `main':
: undefined reference to `in6_ifinfo'
*** Error code 1

Stop in /usr/src/usr.sbin/ifmcstat.
*** Error code 1

Mismo error, aqui solo quitamos el WITHOUT_NCP=yes, vamos a regresarlo, necesitamos saber cual esta causando esto...

Stop in /usr/src/usr.sbin.
*** Error code 1

Stop in /usr/src.
*** Error code 1

Stop in /usr/src.
*** Error code 1

Stop in /usr/src.

Ya habia tenido este error antes, y no supe quien lo causo, pero ya por fin mi buildworld funciono y tengo mis jails listas.

Aun estoy esperando que alguien del foro de freebsd, vean my src.conf y comenten al respecto para ver si esta correcto, si puedo aun eliminar mas cosas y agregar algunas, si estoy siendo muy estricto con el, etc. En fin lo que necesito es el src.conf para todas mis jails.

Archivos en comun

Ahora vamos a ver tenemos un host y sus jails, las jails tiene la siguiente funcion:

jail1 --> apache+mysql
jail2 --> bind
jail3 -->spam
jail4 -->mail

El hosts tiene su archivo rc.conf para cada jail asi:

##############################################################
### Jail Configuration #######################################
##############################################################
jail_enable="YES" # Set to NO to disable starting of any jails
jail_list="jail1 jail2 jail3" # Space separated list of names of jails
jail1_set_hostname_allow="NO" # Allow root user in a jail to change its hostname
jail2_set_hostname_allow="NO"
jail3_set_hostname_allow="NO"
##############################################################
############### JAIL1 ######################
##############################################################
jail_jail1_rootdir="/jails/jail1" # Jail's root directory
jail_jail1_hostname="apache.example.com" # Jail's hostname
jail_jail1_interface="fxp0" # Jail's interface variable to c
jail_jail1_ip="192.168.50.2" # Jail's primary IPv4 and IPv6 a
jail_jail1_devfs_enable="YES" # mount devfs in the jail
jail1_sysvipc_allow="NO"
##############################################################
############### JAIL2 ######################
##############################################################
jail_jail2_rootdir="/jails/jail2" # Jail's root directory
jail_jail2_hostname="dns.example.com" # Jail's hostname
jail_jail2_interface="fxp0" # Jail's interface variable to c
jail_jail2_ip="192.168.50.3" # Jail's primary IPv4 and IPv6 a
jail_jail2_devfs_enable="YES" # mount devfs in the jail
jail2_sysvipc_allow="NO"
##############################################################
############### JAIL3 ######################
##############################################################
jail_jail3_rootdir="/jails/jails3" # Jail's root directory
jail_jail3_hostname="spam.example.com" # Jail's hostname
jail_jail3_interface="fxp0" # Jail's interface variable to c
jail_jail3_ip="192.168.50.4" # Jail's primary IPv4 and IPv6 a
jail_jail3_devfs_enable="YES" # mount devfs in the jail
jail3_sysvipc_allow="NO"

Con esto arrancan mis jails al reiniciar el equipo.

Bien ahora que archivos tienen en comun los jails:
rc.conf
hosts
resolv.conf
ports-supfile

rc.conf:

##############################################################
### Important initial Boot-time options ####################
##############################################################

cleanvar_enable="YES" # Clean the /var directory
root_rw_mount="YES" # Set to NO to inhibit remounting root read-write.
fsck_y_enable="YES" # Set to YES to do fsck -y if the initial preen fails.
fsck_y_flags="" # Additional flags for fsck -y
background_fsck="NO" # Attempt to run fsck in the background where possible
##############################################################
### Network configuration sub-section ######################
##############################################################
### Basic network and firewall/security options: ###
hostname="spam.example.com"
hostid_enable="YES" # Set host UUID.
hostid_file="/etc/hostid" # File with hostuuid.
icmp_log_redirect="NO" # Set to YES to log ICMP REDIRECT packets
network_interfaces="lo fxp0" # List of network interfaces (or "auto").
ifconfig_lo0="inet 127.0.0.1" # default loopback device configuration.
ifconfig_fxp0="inet 192.168.50.4 netmask 255.255.255.0"
inetd_enable="NO"

### Network daemon (miscellaneous) ###
syslogd_enable="YES" # Run syslog daemon (or NO).
syslogd_program="/usr/sbin/syslogd" # path to syslogd, if you want a different
syslogd_flags="-ss" # Flags to syslogd (if enabled).
# kerberos. Do not run the admin daemons on slave servers
#
kerberos5_server_enable="NO" # Run a kerberos 5 master server (or NO).

### Network daemon (NFS): All need rpcbind_enable="YES" ###
amd_enable="NO" # Run amd service with $amd_flags (or NO).

### SNMP daemon ###
# Be sure to understand the security implications of running SNMP v1/v2
# in your network.
bsnmpd_enable="NO" # Run the SNMP daemon (or NO).
bsnmpd_flags="" # Flags for bsnmpd.

### Network routing options: ###
defaultrouter="192.168.50.1" # Set to default gateway (or NO).

### Miscellaneous network options: ###
icmp_bmcastecho="NO" # respond to broadcast ping packets

### IPv6 options: ###
ipv6_enable="NO" # Set to YES to set up for IPv6.

##############################################################
### System console options #################################
##############################################################

keyboard="" # keyboard device to use (default /dev/kbd0).
keymap="NO" # keymap in /usr/share/syscons/keymaps/* (or NO).
keyrate="fast" # keyboard rate to: slow, normal, fast (or NO).
keybell="NO" # See kbdcontrol(1) for options. Use "off" to disable.
keychange="NO" # function keys default values (or NO).
cursor="destructive" # cursor type {normal|blink|destructive} (or NO
scrnmap="NO" # screen map in /usr/share/syscons/scrnmaps/* (or NO).
blanktime="NO" # blank time (in seconds) or "NO" to turn it off.
saver="NO" # screen saver: Uses /boot/kernel/${saver}_saver.ko
moused_enable="NO" # Run the mouse daemon.

##############################################################
### Mail Transfer Agent (MTA) options ######################
##############################################################

mta_start_script="/etc/rc.sendmail"
# Script to start your chosen MTA, called by /etc/rc.
# Settings for /etc/rc.sendmail and /etc/rc.d/sendmail:
sendmail_enable="NONE" # Run the sendmail inbound daemon (YES/NO).

##############################################################
### Miscellaneous administrative options ###################
##############################################################

auditd_enable="NO" # Run the audit daemon.
auditd_program="/usr/sbin/auditd" # Path to the audit daemon.
auditd_flags="" # Which options to pass to the audit daemon.
cron_enable="YES" # Run the periodic job daemon.
cron_program="/usr/sbin/cron" # Which cron executable to run (if enabled).
cron_dst="YES" # Handle DST transitions intelligently (YES/NO)
cron_flags="" # Which options to pass to the cron daemon.
quota_enable="NO" # turn on quotas on startup (or NO).
check_quotas="NO" # Check quotas on startup (or NO).
quotaon_flags="-a" # Turn quotas on for all file systems (if enabled)
quotaoff_flags="-a" # Turn quotas off for all file systems at shutdown
quotacheck_flags="-a" # Check all file system quotas (if enabled)

# Emulation/compatibility services provided by /etc/rc.d/abi
kern_securelevel_enable="NO" # kernel security level (see security(7))
kern_securelevel="-1" # range: -1..3 ; `-1' is the most insecure
update_motd="NO" # update version info in /etc/motd (or NO)
dmesg_enable="NO" # Save dmesg(8) to /var/run/dmesg.boot
newsyslog_enable="YES" # Run newsyslog at startup.
newsyslog_flags="-CN" # Newsyslog flags to create marked files
mixer_enable="NO" # Run the sound mixer.
sshd_enable="YES" # Enable sshd
sshd_program="/usr/sbin/sshd" # path to sshd, if you want a different one.
sshd_flags="-4" # Additional flags for sshd.
rcpbind_enable="NO"
clear_tmp_enable="YES"

Marque en negritas las partes que cambian de jail a jail lo demas todo por default, la unica manera de accesar a las jails es por el mismo host o via ssh.

hosts:
aqui ya saben que tiene que llevar correcto?
resolv.conf:
nuestro dns
ports-supfile:
datos para actualizar los ports.

Paquetes Necesarios

Que paquetes necesito yo en mis jails:

screeen
cvsup-without-gui
portupgrade

Son los necesito como minimo para cada jail.

Archivo de Host

Aqui tengo el archivo que uso para el hosts, si lo observan ahi opciones que se deseo tenga el hosts, como PF, ZFS, entre ellas.

Este es:

WITHOUT_APM="yes"
WITHOUT_ATM="yes"
WITHOUT_ASSERT_DEBUG="yes"
WITHOUT_AT="yes"
WITHOUT_BIND="yes"
WITHOUT_BLUETOOTH="yes"
WITHOUT_BOOT="yes"
WITHOUT_CALENDAR="yes"
WITHOUT_CVS="yes"
WITHOUT_DICT="yes"
WITHOUT_EXAMPLES="yes"
WITHOUT_FLOPPY="yes"
WITHOUT_FREEBSD_UPDATE="yes"
WITHOUT_GAMES="yes"
WITHOUT_GPIB="yes"
WITHOUT_GSSAPI="yes"
WITHOUT_INET6="yes"
WITHOUT_HTML="yes"
WITHOUT_IPFILTER="yes"
WITHOUT_IPFW="yes"
WITHOUT_IPX="yes"
WITHOUT_KERBEROS="yes"
WITHOUT_KVM="yes"
WITHOUT_LPR="yes"
WITHOUT_MAILWRAPPER="yes"
WITHOUT_MAN="yes"
WITHOUT_NDIS="yes"
WITHOUT_NIS="yes"
WITHOUT_PPP="yes"
WITHOUT_PMC="yes"
WITHOUT_PROFILE="yes"
WITHOUT_QUOTAS="yes"
WITHOUT_RCMDS="yes"
WITHOUT_RCS="yes"
WITHOUT_SENDMAIL="yes"
WITHOUT_SHAREDOCS="yes"
WITHOUT_SYSCONS="yes"
WITHOUT_SYSINSTALL="yes"
WITHOUT_TELNET="yes"
WITHOUT_WIRELESS="yes"
WITHOUT_WPA_SUPPLICANT_EAPOL="yes"

Con este quiero trabajar.

No hay comentarios: