工作,学习,生活,这里将会有一些记录. 备用域名:http://meisw.51099.com 注册 | 登陆
浏览模式: 标准 | 列表2013年09月的文章

linux安全优化

cd /dev
dd if=/dev/zero of=tmpmnt bs=1024 count=100000
/sbin/mke2fs /dev/tmpmnt
cp -R /tmp/ /tmp_backup
mount -o loop,rw,nosuid,noexec /dev/tmpmnt /tmp
chmod 0777 /tmp
cp -R /tmp_backup/* /tmp/

# 修改/etc/fstab 添加下面的条目使其在引导时仍然有效
/dev/tmpmnt /tmp ext2 loop,rw,nosuid,noexec 0 0


mv /var/tmp /var/tmpbak
ln -s /tmp /var/tmp

chattr +i /etc/passwd*
chattr +i /etc/shadow*
chattr +i /etc/rc.d/rc.local
chmod 700 /etc/rc.d/init.d/*


chmod 700 /usr/bin/gcc
chmod 700 /usr/bin/g++
chmod 700 /usr/bin/c++
chmod 700 /usr/bin/ld
chmod 700 /usr/bin/as
chmod 700 /usr/bin/perl


chmod 700 /bin/ping
chmod 700 /usr/bin/finger
chmod 700 /usr/bin/who
chmod 700 /usr/bin/w
chmod 700 /usr/bin/locate
chmod 700 /usr/bin/whereis
chmod 700 /sbin/ifconfig
chmod 700 /usr/bin/pico
chmod 700 /usr/bin/vi
chmod 700 /usr/bin/which
chmod 700 /usr/bin/gcc
chmod 700 /usr/bin/make
chmod 700 /bin/rpm

php.ini
disable_functions = "symlink,shell_exec,exec,proc_close,proc_open,popen,system,dl,passthru,escapeshellarg, escapeshellcmd"

Golang的跨平台编译程序

Golang支持交叉编译,也就是说你在32位平台的机器上开发,可以编译生成64位平台上的可执行程序。

交叉编译依赖下面几个环境变量:

$GOARCH    目标平台(编译后的目标平台)的处理器架构(386、amd64、arm)
$GOOS          目标平台(编译后的目标平台)的操作系统(darwin、freebsd、linux、windows)


各平台的GOOS和GOARCH参考 

OS                   ARCH                          OS version

linux                386 / amd64 / arm             >= Linux 2.6

darwin               386 / amd64                   OS X (Snow Leopard + Lion)

freebsd              386 / amd64                   >= FreeBSD 7

windows              386 / amd64                   >= Windows 2000


跨平台编译步骤:

一、了解目标平台架构:

下面几个命令有助于了解目标平台的架构:

[root@localhost ~]# uname -a
Linux localhost.localdomain 2.6.32-279.19.1.el6.x86_64 #1 SMP Wed Dec 19 07:05:20 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost ~]# uname -m
x86_64
[root@localhost ~]# arch
x86_64
[root@localhost ~]# file /bin/cat
/bin/cat: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped
[root@localhost ~]#

这里可以看到这个服务器的架构是 x86_64 这个架构亦称 amd64.

  • 6g是amd64的go编译器,它生成的是.6文件。
  • 386一般使用8g命令,它生成的一般是.8格式的文件。
  • 当然还有一个5g的命令是用于arm的cpu,

同理amd64用6l,386用8l,arm用5l的链接器

参考资料:

Linux下如何查看系统是32位还是64位的?
http://blog.csdn.net/whucs_b701/article/details/8543499

 

 

二、准备目标平台需要的包和工具文件

执行下面命令:

$ cd /usr/local/go/src
$ sudo CGO_ENABLED=0 GOOS=linux GOARCH=amd64 ./make.bash

这里 额外多一个环境变量 CGO_ENABLED 是因为 交叉编译不支持 CGO,我们这里禁用它。

这里并不是重新编译Go,因为安装Go的时候,只是编译了本地系统需要的东西;而需要跨平台交叉编译,需要在Go中增加对其他平台的支持。所以,有 ./make.bash 这么一个过程。

跨平台编译Go程序(交叉编译)

各平台的GOOS和GOARCH参考

OS ARCH OS version linux 386 / amd64 / arm >= Linux 2.6 darwin 386 / amd64 OS X (Snow Leopard + Lion) freebsd 386 / amd64 >= FreeBSD 7 windows 386 / amd64 >= Windows 2000

$ cd /usr/local/go/src $ sudo CGO_ENABLED=0 GOOS=linux GOARCH=amd64 ./make.bash

这里并不是重新编译Go,因为安装Go的时候,只是编译了本地系统需要的东西;而需要跨平台交叉编译,需要在Go中增加对其他平台的支持。所以,有 ./make.bash 这么一个过程。

 

(1)首先进入go/src 源码所在目录,执行如下命令创建目标平台所需的包和工具文件。

$ cd /usr/local/go/src 
$ CGO_ENABLED=0 GOOS=linux GOARCH=amd64 ./make.bash

如果是 Windows 则修改 GOOS 即可。 
$ CGO_ENABLED=0 GOOS=windows GOARCH=amd64 ./make.bash

(2) 现在可以编译 Linux 和 Windows 平台所需的执行文件了。

$ CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build 
$ CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build

不过该方式暂时不支持 CGO。

http://solovyov.net/en/2012/03/09/cross-compiling-go/

以上假定是64位架构,32位,修改GOARCH为386

说明: 
这里并不是重新编译Go,因为安装Go的时候,只是编译了本地系统需要的东西;而需要跨平台交叉编译,需要在Go中增加对其他平台的支持。所以,有 ./make.bash 这么一个过程

交叉编译问题补充:

首先,建议安装Go语言通过源码安装,否则可能没有make.bash或make.bat程序。

之所以需要执行上面的这些步骤,是因为安装Go语言时,一些工具和平台相关的代码并没有生成,执行上面的步骤,并不是重新安装Go语言,而是生成交叉编译(目标平台)需要的工具和文件。这些只是在第一次交叉编译的时候做。之后就不需要了。

为了更快的编译,可以

    ./make.bash --no-clean