Minimalist memory usuage for asterisk vps

I went about setting up a optimized vps for memory that needed to fit into a 256 meg vm. The setup I have is very minimal in it’s self, 2 extensions + call recording.

Feel free to make suggestions, there seams to be some bash scripts in memory that are loaded with asterisk that don’t seam to be critical that could be optimized if needed.

I started with asterisk 2.02 and this is likely to work on asterisk 3.0 as well.

The end result is 124 megabytes of memory used after startup, with http / mysql still enabled. It is possible to trim the memory foot print smaller but that is not needed in this case.

Here is what I did, the services removed would require you to configure them so removing them or disabling them should have no effect. Switching sshd to xinetd is likely not needed as memory foot print was all ready bellow the required 256 megs

find processes with most ram

ps xau | sort -k5 | less

see total ram used

free -m

remove audit

rpm -e audit amtu autofs

use google

rpm -e redhat-lsb man man-pages-overrides

no blue tooth on vps

rpm -e bluez-utils

acpid for power the power button

rpm -e acpid

x11 won’t be started again

rpm -e xorg-x11-xfs chkfontpath

nfs not needed

rpm -e nfs-utils nfs-utils-lib

no mouse needed in a vps

rpm -e gpm vim-enhanced
rpm -e coolkey pcsc-lite ccid ifd-egate
rpm -e avahi

assuming you are in a vps you don’t need to monitor diskhealth

rpm -e smartmontools

#strip symbols from files

strip /usr/bin/*
strip /usr/sbin/*
echo drop database test | mysql

do yum updates manually

service yum-updatesd stop
chkconfig --levels 2345 yum-updatesd off
chkconfig --del yum-updatesd

most people are not going to have a iscsi configuration

service iscsid stop
chkconfig --levels 2345 iscsid off
chkconfig --del iscsid

service iscsi stop
chkconfig --levels 2345 iscsi off
chkconfig --del iscsi

hal used for power management, has dependancies so just shutting down

service haldaemon stop
chkconfig --levels 2345 haldaemon off
chkconfig --del haldaemon



service acpid stop
chkconfig --levels 2345 iscsid off
chkconfig --del iscsid

configurations

network - set your ip to a static ip so that dhclient does not use

2k of memory

#remove mingetty all expect the first one
1:2345:respawn:/sbin/mingetty tty1

mysql

This cuts mysql usage all most in half as it does not use innodb

add to /etc/init.d/mysqld
–skip-innodb --default-storage-engine=myisam
and if mysql is upgraded

–default_tmp_storage_engine=myisam \

add to my.cnf

bulk_insert_buffer_size=4M

apache /etc/httpd/conf/httpd.conf
This will reduce some of your apache memory foot print but
this is intended if you are having very few hits to your freepbx
admin page

StartServers 1 MinSpareServers 1 MaxSpareServers 5 ServerLimit 50 MaxClients 50 MaxRequestsPerChild 4000

disabled these modules
#LoadModule auth_digest_module modules/mod_auth_digest.so
#LoadModule authn_file_module modules/mod_authn_file.so
#LoadModule authn_alias_module modules/mod_authn_alias.so
#LoadModule authn_anon_module modules/mod_authn_anon.so
#LoadModule authn_dbm_module modules/mod_authn_dbm.so
#LoadModule authn_default_module modules/mod_authn_default.so
#LoadModule authz_user_module modules/mod_authz_user.so
#LoadModule authz_owner_module modules/mod_authz_owner.so
#LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
#LoadModule authz_dbm_module modules/mod_authz_dbm.so
#LoadModule authz_default_module modules/mod_authz_default.so
#LoadModule ldap_module modules/mod_ldap.so
#LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
#LoadModule include_module modules/mod_include.so
#LoadModule logio_module modules/mod_logio.so
#LoadModule env_module modules/mod_env.so
#LoadModule ext_filter_module modules/mod_ext_filter.so
#LoadModule expires_module modules/mod_expires.so
#LoadModule usertrack_module modules/mod_usertrack.so
#LoadModule dav_module modules/mod_dav.so
#LoadModule status_module modules/mod_status.so
#LoadModule dav_fs_module modules/mod_dav_fs.so
#LoadModule userdir_module modules/mod_userdir.so
#LoadModule proxy_module modules/mod_proxy.so
#LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
#LoadModule proxy_http_module modules/mod_proxy_http.so
#LoadModule proxy_connect_module modules/mod_proxy_connect.so
#LoadModule file_cache_module modules/mod_file_cache.so
#LoadModule mem_cache_module modules/mod_mem_cache.so
#LoadModule version_module modules/mod_version.so
#LoadModule cern_meta_module modules/mod_cern_meta.so
#LoadModule asis_module modules/mod_asis.so

risky, you could could your self knocked off the vps for this

I started a second sshd as a backup

/usr/sbin/sshd -p 2222

Then create
/etc/xinetd.d/ssh
— contents —
service ssh
{
socket_type = stream
protocol = tcp
wait = no
port = 22
user = root
server = /usr/sbin/sshd
server_args = -i
disable = no
}

restart xientd and check for config errors in /var/log

#/etc/init.d/xinetd restart

disable sshd

service sshd stop
chkconfig --levels 2345 sshd off
chkconfig --del sshd

that seams to kill the backup sshd as well, start it

/usr/sbin/sshd -p 2222

login on backup ssh with ssh user@host -p 2222

logout of current sshd

#on backup sshd kill old sshd
kill fuser 22/tcp

restart xinet

/etc/init.d/xinetd restart

#sshd should be there an port 22 again
#telnet localhost 22

kill old server

kill fuser 2222/tcp

#now sshd will only take up ram when you are logged in by ssh

if you have access to console you will see no sshd, so 10000

less memory used

ps xau | grep ssh

more reductions ?

sendmail could be configured for xinetd as well

could reduce it more here
voip-info.org/wiki/view/Asterisk+Slimming