结尾工作 系统清理

为了最大限度避免不必要的麻烦,这里首先简单的删除一些无用文件,存储随机数种子,然后重新启动,再使用临时工具链进行 strip 操作。

cd / &&
ln -sf /proc/mounts /etc/mtab &&
rm /bin/tmpinit /etc/{ld.so.cache,profile} ~/.bash* /tmp/* /usr{,/share}/{doc,info,man} &&
cp /www/bin/{bash,mount} / &&
echo 'kernel (hd0,0)/bzImage root=0802 rootfstype=xfs rw init=/bash panic=30' > /boot/menu.lst &&
dd if=/dev/urandom of=/var/random-seed  bs=8k count=1 &&
dd if=/dev/urandom of=/var/urandom-seed bs=8k count=1 &&
sync &&
umount -l /dev/sda{9,8,7,6,5,1} &&
# 此命令一般不会成功,不过你可以等待30秒(panic=30)后由内核自动重启。
shutdown -r -q now重启完毕,现在可以使用下面的命令进行 strip 操作。[提示]设置 lo 网络接口是为了在初始化 PostgreSQL 数据库后,启动数据库服务时可以使用 INET socket ,否则无法安装加密模块。设置 eth0 网络接口是为了便于使用SSH。

cd / &&
export PATH=/bin:/usr/bin HISTFILESIZE=0 &&
/mount -t proc    proc     /proc     &&
/mount -t tmpfs   shm      /dev/shm  &&
/mount -t devpts  devpts   /dev/pts  &&
/mount -t ext2  /dev/sda1  /boot &&
/mount -t xfs   /dev/sda5  /usr  &&
/mount -t xfs   /dev/sda6  /root &&
/mount -t xfs   /dev/sda7  /var  &&
/mount -t xfs   /dev/sda8  /www  &&
/mount -t xfs   /dev/sda9  /data  &&
/www/bin/mkdir -p -m 1777 /dev/shm/{tmp,run,pg_socket,php_session} &&
( /www/bin/strip --strip-all {,/root/*}/{,usr/}bin/*  {,/root/*}/usr/libexec/{*,*/*,*/*/*,*/*/*/*,*/*/*/*/*} ;
/www/bin/strip --strip-debug {,/root/*}/{,usr}/lib/{*,*/*,*/*/*,*/*/*/*,*/*/*/*/*} ;
rm -f /{bash,mount} /root/.bash* ) &&
sync  &&
ip -4 link set lo   txqueuelen  0       &&
ip -4 link set eth0 txqueuelen  4000    &&
ip -4 link set lo   mtu  16436          &&
ip -4 link set eth0 mtu  1500           &&
ip -4 addr add 127.0.0.1/8                               scope host    dev  lo   valid_lft forever preferred_lft forever  &&
ip -4 addr add 192.168.10.33/24 broadcast 192.168.10.255 scope global  dev eth0  valid_lft forever preferred_lft forever  &&
ip -4 link set lo   up                  &&
ip -4 link set eth0 up                  &&
ip -4 route add unicast default via 192.168.10.250 dev eth0 &&创建站点目录、安装 phpPgAdmin APC-monitor
更多有关 phpPgAdmin 的知识,可以参考《phpPgAdmin 中文文档》。

umount /www &&
mkfs.xfs -f -q  /dev/sda8   &&
mount -t xfs /dev/sda8 /www &&
mkdir -p /www/{oklaoshi/{htdocs,secret,www},phppgadmin,upload} &&
tar -xf /data/phpPgAdmin-4.2.tar.bz2 -C /data &&
tar -xf /data/APC-3.0.16.tgz         -C /data &&
mv /data/phpPgAdmin/*        /www/phppgadmin/ &&
mv /data/APC-3.0.16/apc.php  /www/phppgadmin/ &&
mv /data/config.inc.php /www/phppgadmin/conf/ &&
chown -R httpd: /www &&
chmod -R 1500   /www &&
find /www ! -type d ! -type l | xargs chmod 1400 &&
chmod 1700 /www/upload &&
sync &&
umount /www &&初始化 PostgreSQL 数据库集群
[提示]数据库的超级用户名是:pgsql,密码是:123

umount /data &&
mkfs.xfs -f -q  /dev/sda9  &&
mount -t xfs /dev/sda9 /data &&
chown pgsql: /data &&
chmod 1700   /data &&
su -c'echo 123 > /dev/shm/pass.txt &&
initdb -Atrust -D/data -EUTF-8 --locale=C -Upgsql --pwfile=/dev/shm/pass.txt &&
pg_ctl start -w -D/data -p/bin/postgres &&
psql -d template1 -f /usr/share/postgresql/contrib/pgcrypto.sql -Upgsql -1 &&
pg_ctl stop -D/data -msmart' -s/bin/bash pgsql &&
chown -R pgsql: /data &&
chmod -R og=- /data &&
rm -f /data/*.{conf,opts} /dev/shm/pass.txt && sync &&
umount /data &&配置 Bash
启动登陆(交互) shell 时会执行 /etc/profile 和 ~/.bash_profile 文件(后者的内容会覆盖前者),通常在其中定义环境变量。
启动非登录(非交互) shell 时会执行 /etc/bashrc 和 ~/.bashrc 文件(后者的内容会覆盖前者),通常在其中定义别名和函数。
习惯上一般要求 profile 额外执行 bashrc 的内容。
退出 shell 时会执行 /etc/bash_logout 和 ~/.bash_logout 文件。

umount /root &&
echo 'umask 077
export HISTFILESIZE=0 PATH=/bin:/usr/bin PS1="[\\u:\\w]"
export INPUTRC=/etc/inputrc TZ=UTC LC_ALL=zh_CN.UTF-8
. /etc/bashrc' > /etc/profile &&
echo "alias make='make -j1' mkdir='mkdir -p' patch='patch -p1 -i' mv='mv -f' cp='cp -af' rm='rm -fr' ls='ls -AFh' mount='mount -n' umount='umount -n'" > /etc/bashrc &&
echo 'umount -nl /usr' > /etc/bash_logout &&
echo 'mount -n -t xfs -o async,noatime,nodiratime,nodev,nosuid,ro  /dev/sda5  /usr' > /root/musr &&
chmod 1000 /root/musr && chown 0:0 /root/musr &&配置 Grub4dos
出于安全考虑,需要使用md5密码(这里是”123″)保护启动菜单。密码字符串可以使用宿主系统的 grub-md5-crypt 程序得到。[提示]因为simpleinit会在运行’bootprog’之前首先创建 /dev/initctl 这个FIFO,所以要先”rw”挂载根然后再在启动脚本里面remount成”ro”。

Grub 的一个重要作用是向内核传递引导参数,如果你想了解更多,可以参考《Linux内核引导参数精选》。

echo 'timeout 5
default=0
password --md5 $1$A6dtK$96kvTFeAhOiK524zH2U260
title miniLAPP
kernel (hd0,0)/bzImage root=0802 rootfstype=xfs rw panic=30 init=/bin/simpleinit
title miniLAPP (single mode)
lock
kernel (hd0,0)/bzImage root=0802 rootfstype=xfs rw panic=30 init=/bin/simpleinit single' > /boot/menu.lst &&


相关内容

    暂无相关文章