CentOS7 httpd MySQL PHP memcached SElinux

/omg

CentOS7 minimal

httpd
# yum install httpd
# systemctl start httpd.service
# systemctl enable httpd.service

firewalld
# firewall-cmd –zone=public –add-service=http –permanent
# firewall-cmd –zone=public –add-service=https –permanent
# firewall-cmd –reload

mariadb
# yum install mariadb-server mariadb
# systemctl start mariadb.service
# systemctl enable mariadb.service
# mysql_secure_installation

php
# yum install php php-mysql php-gd php-pear php-mbstring php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel
# chcon -R -t httpd_sys_content_t /home/sourcode/domains/sourcode.net/public_html
# systemctl restart httpd.service

memcached
# yum install php-pecl-memcached memcached
# vi /etc/httpd/conf.d/php.conf

#
# Apache specific PHP configuration options
# those can be override in each configured vhost
#
# php_value session.save_handler "files"
# php_value session.save_path "/var/lib/php/session"
php_value session.save_handler "memcached"
php_value session.save_path "127.0.0.1:11211"

# setsebool -P httpd_can_network_memcache 1
# getsebool httpd_can_network_memcache

# vi /etc/httpd/conf.d/sourcode.conf

</VirtualHost *:80>
ServerAdmin admin@sourcode.net
DocumentRoot "/home/sourcode/domains/sourcode.net/public_html"
<Directory "/home/sourcode/domains/sourcode.net/public_html">
Require all granted
</Directory> 
ServerName sourcode.net
ServerAlias www.sourcode.net
ErrorLog “/var/log/httpd/sourcode.net/error_log”
CustomLog “/var/log/httpd/sourcode.net/access_log” common
<VirtualHost>

# end

centos runlevel

ความต้องการ
อยากให้ CentOS ทำงานในแบบ text-mode โดยยังคง Desktop package ไว้อยุ่

วิธีทำ
แก้ไฟล์ /etc/inittab

# System initialization is started by /etc/init/rcS.conf
#
# Individual runlevels are started by /etc/init/rc.conf
#
# Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf
#
# Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf,
# with configuration in /etc/sysconfig/init.
#
# For information on how to write upstart event handlers, or how
# upstart works, see init(5), init(8), and initctl(8).
#
# Default runlevel. The runlevels used are:
# 0 – halt (Do NOT set initdefault to this)
# 1 – Single user mode
# 2 – Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 – Full multiuser mode
# 4 – unused
# 5 – X11
# 6 – reboot (Do NOT set initdefault to this)
#
id:5:initdefault:

เปลี่ยน id:5:initdefault:
เป็น id:3:initdefault:

mtop on CentOS

mtop เอาไว้ monitor การทำงานของ MySQL ครับ

ปล. สำหรับ 64bit server นะครับ

# get http://pkgs.repoforge.org/perl-Curses/perl-Curses-1.28-1.el5.rf.x86_64.rpm
# rpm -ivh perl-Curses-1.28-1.el5.rf.x86_64.rpm
# wget http://pkgs.repoforge.org/mtop/mtop-0.6.6-1.2.el5.rf.noarch.rpm
# rpm -ivh mtop-0.6.6-1.2.el5.rf.noarch.rpm
# mtop –dbuser=root -p

apache 2.4.1

# aptitude install libapr1-dev uuid-dev libaprutil1-dev libmysqlclient15-dev libpq-dev libsqlite3-dev rcconf build-essential -y
# wget http://mirrors.issp.co.th/apache//httpd/httpd-2.4.1.tar.gz
tar -xvf httpd-2.4.1.tar.gz
# cd httpd-2.4.1/
# ./configure
# make
# make install

## Script start|stop|restart

#!/bin/bash
# description: apache2 httpd 2.4.1 server
# Start the service httpd
start() {
/usr/local/apache2/bin/httpd &
echo “Up and running”
}
# Restart the service httpd
stop() {
killall httpd
echo “Killing httpd”
}
### main logic ###
case “$1″ in
start)
start
;;
stop)
stop
;;
*)
echo $”Usage: $0 {start|stop}”
exit 1
esac
exit 0

แต่..​ถ้าเป็น lenny หรือ centos5 จะเจอเหตุการณ์แบบนี้!!

configure: error: APR version 1.3.0 or later is required

แก้โดยการ
CentOS
yum remove apr-util-devel apr apr-util-mysql apr-docs apr-devel apr-util apr-util-docs
yum install expat
yum remove apr-util-devel apr apr-util-mysql apr-docs apr-devel apr-u

Debian
aptitude install build-essential

Debian/CentOS
cd /usr/src
wget http://mirrors.issp.co.th/apache//apr/apr-1.4.6.tar.gz
tar xzvf apr-1.4.2.tar.gz
cd apr-1.4.2
./configure –prefix=/usr/local/apr
make
make install

cd /usr/src
wget http://mirrors.issp.co.th/apache//apr/apr-util-1.4.1.tar.gz
tar xzvf apr-util-1.4.1.tar.gz
cd apr-util-1.4.1
./configure –prefix=/usr/local/apr-util –with-apr=/usr/local/apr
make
make install

cd /usr/src
wget http://mirrors.issp.co.th/apache//apr/apr-iconv-1.2.1.tar.gz
tar xzvf apr-iconv-1.2.1.tar.gz
cd apr-iconv-1.2.1
./configure –with-apr=/usr/local/apr
make
make install

cd /usr/src/
wget http://mirrors.issp.co.th/apache//httpd/httpd-2.4.1.tar.gz
tar xzvf httpd-2.4.1.tar.gz
cd httpd-2.4.1
./configure \
–prefix=/usr/local/apache2 \
–enable-mods-shared=all \
–enable-so \
–enable-rewrite \
–enable-cache \
–enable-file-cache \
–enable-mem-cache \
–enable-disk-cache \
–enable-static-support \
–enable-static-htpasswd \
–enable-static-htdigest \
–enable-static-rotatelogs \
–enable-static-logresolve \
–enable-static-htdbm \
–enable-static-ab \
–enable-static-checkgid \
–enable-cgid \
–with-apr=/usr/local/apr/ \
–with-apr-util=/usr/local/apr/ \
–enable-cgi \
–with-expat=builtin \
–enable-ssl \

# make
# make install

# nano /etc/init.d/httpd

#!/bin/bash
# description: apache2 httpd 2.4.1 server
# Start the service httpd
start() {
/usr/local/apache2/bin/httpd &
echo “Up and running”
}
# Restart the service httpd
stop() {
killall httpd
echo “Killing httpd”
}
### main logic ###
case “$1″ in
start)
start
;;
stop)
stop
;;
*)
echo $”Usage: $0 {start|stop}”
exit 1
esac
exit 0

# /etc/init.d/httpd start

source:
http://hi.baidu.com/taiyangx/blog/item/944c9c583f730797810a18d5.html
http://verahill.blogspot.com/2012/02/debian-testing-wheezy-64-building_23.html
http://www.debian-tutorials.com/mysql/how-to-install-apache2-4-php5-and-mysql-from-source-on-debian-linux

CentOS6 and DHCP server with vlan

โจทย์ไม่ยาก ไม่ง่าย … แค่ไม่เคยทำ

ความต้องการ

1. dhcp server บน CentOS6
2. แจก ip-address บน subnet ตามต้องการ
3. มี switch layer 2 เป็นตัวแยก vlan

ิวิธีทำ

1. สร้าง vlan id ใน switch ก่อน
ตัวอย่าง

2. ติดตั้ง dhcp server , vconfig

# yum install dhcp vconfig -y

3. load module 802.1q

# modprobe 8021q

check :

# lsmod | grep 8021q
8021q                  19587  0 
garp                    5901  1 8021q

4. สร้าง vlan interfaces

# cat /etc/sysconfig/network-scripts/ifcfg-eth0.2
DEVICE="eth0.2"
ONBOOT="yes"
BOOTPROTO=none
VLAN="yes"
IPADDR=10.156.3.2
NETMASK=255.255.255.0

# cat /etc/sysconfig/network-scripts/ifcfg-eth0.3
DEVICE="eth0.3"
ONBOOT="yes"
BOOTPROTO=none
VLAN="yes"
IPADDR=10.156.4.2
NETMASK=255.255.255.0

# cat /etc/sysconfig/network-scripts/ifcfg-eth0.4
DEVICE="eth0.4"
ONBOOT="yes"
BOOTPROTO=none
VLAN="yes"
IPADDR=10.156.5.2
NETMASK=255.255.255.0

# cat /etc/sysconfig/network-scripts/ifcfg-eth0.5
DEVICE="eth0.5"
ONBOOT="yes"
BOOTPROTO=none
VLAN="yes"
IPADDR=10.156.6.2
NETMASK=255.255.255.0

# cat /etc/sysconfig/network-scripts/ifcfg-eth0.6
DEVICE="eth0.6"
ONBOOT="yes"
BOOTPROTO=none
VLAN="yes"
IPADDR=10.156.7.2
NETMASK=255.255.255.0

# cat /etc/sysconfig/network-scripts/ifcfg-eth0.7
DEVICE="eth0.7"
ONBOOT="yes"
BOOTPROTO=none
VLAN="yes"
IPADDR=10.156.9.2
NETMASK=255.255.255.0

# cat /etc/sysconfig/network-scripts/ifcfg-eth0.8
DEVICE="eth0.8"
ONBOOT="yes"
BOOTPROTO=none
VLAN="yes"
IPADDR=10.156.11.2
NETMASK=255.255.255.0

# cat /etc/sysconfig/network-scripts/ifcfg-eth0.9
DEVICE="eth0.9"
ONBOOT="yes"
BOOTPROTO=none
VLAN="yes"
IPADDR=10.156.13.2
NETMASK=255.255.255.0

5. สร้าง /etc/dhcp/dhcpd.conf

ddns-update-style interim;
ignore client-updates;

authoritative;

subnet 10.156.3.0 netmask 255.255.255.0 {
 option routers      10.156.3.1;                                
 option subnet-mask  255.255.255.0;
 option domain-name-servers 208.67.222.222,8.8.8.8;
 option time-offset  -18000; # Eastern Standard Time
 range dynamic-bootp 10.156.3.21 10.156.3.200;                  
 default-lease-time 21600;
 max-lease-time 43200;
}
subnet 10.156.4.0 netmask 255.255.255.0 {
 option routers      10.156.4.1;                                
 option subnet-mask  255.255.255.0;
 option domain-name-servers 208.67.222.222,8.8.8.8;
 option time-offset  -18000; # Eastern Standard Time
 range dynamic-bootp 10.156.4.21 10.156.4.200;                  
 default-lease-time 21600;
 max-lease-time 43200;
}
subnet 10.156.5.0 netmask 255.255.255.0 {
 option routers      10.156.5.1;                                
 option subnet-mask  255.255.255.0;
 option domain-name-servers 208.67.222.222,8.8.8.8;
 option time-offset  -18000; # Eastern Standard Time
 range dynamic-bootp 10.156.5.21 10.156.5.200;                  
 default-lease-time 21600;
 max-lease-time 43200;
}
subnet 10.156.6.0 netmask 255.255.255.0 {
 option routers      10.156.6.1;                                
 option subnet-mask  255.255.255.0;
 option domain-name-servers 208.67.222.222,8.8.8.8;
 option time-offset  -18000; # Eastern Standard Time
 range dynamic-bootp 10.156.6.21 10.156.6.200;                  
 default-lease-time 21600;
 max-lease-time 43200;
}
subnet 10.156.7.0 netmask 255.255.255.0 {
 option routers      10.156.7.1;                                
 option subnet-mask  255.255.255.0;
 option domain-name-servers 208.67.222.222,8.8.8.8;
 option time-offset  -18000; # Eastern Standard Time
 range dynamic-bootp 10.156.7.21 10.156.7.200;                  
 default-lease-time 21600;
 max-lease-time 43200;
}
subnet 10.156.9.0 netmask 255.255.255.0 {
 option routers      10.156.9.1;                                
 option subnet-mask  255.255.255.0;
 option domain-name-servers 208.67.222.222,8.8.8.8;
 option time-offset  -18000; # Eastern Standard Time
 range dynamic-bootp 10.156.9.21 10.156.9.200;                  
 default-lease-time 21600;
 max-lease-time 43200;
}
subnet 10.156.11.0 netmask 255.255.255.0 {
 option routers      10.156.11.1;                               
 option subnet-mask  255.255.255.0;
 option domain-name-servers 208.67.222.222,8.8.8.8;
 option time-offset  -18000; # Eastern Standard Time
 range dynamic-bootp 10.156.11.21 10.156.11.200;                
 default-lease-time 21600;
 max-lease-time 43200;
}
subnet 10.156.13.0 netmask 255.255.255.0 {
 option routers      10.156.13.1;                               
 option subnet-mask  255.255.255.0;
 option domain-name-servers 208.67.222.222,8.8.8.8;
 option time-offset  -18000; # Eastern Standard Time
 range dynamic-bootp 10.156.13.21 10.156.13.200;                
 default-lease-time 21600;
 max-lease-time 43200;
}

ปล. ปรับได้ตามความเหมาะสม

6. แก้ไข /etc/sysconfig/dhcpd

DHCPDARGS=eth0.2
DHCPDARGS=eth0.3
DHCPDARGS=eth0.4
DHCPDARGS=eth0.5
DHCPDARGS=eth0.6
DHCPDARGS=eth0.7
DHCPDARGS=eth0.8
DHCPDARGS=eth0.9

ปล. ปรับได้ตามความเหมาะสม

7. start ซะ!

# service dhcpd start