Ubuntu12.04 64bit最新环境安装教程

首发于:我是买家博客

作者:杨鑫奇

最近在公司搭建环境过程中收到各种的折磨,在这里整理了下,贴出来希望对大家有所帮助。文章有不足的地方请大家提醒我更正。

始终是超级小白鼠就来尝试下最新的包的安装,测试了好多次之后,终于安装成功的了,现在安装在本地的虚拟机上,安装通过,现在拿的是linode的虚拟机做测试。安装完成后记录步骤如下,大家如果不是用Lnmp之类的自动安装脚本,如果对于安装细节不是很明白,可以建议自己动手操作一边,明白现在所需要的相关的组件的安装过程,也能更深入的了解系统的各个部分。

操作系统版本:Ubuntu 12.04 64bit

使用root账号登陆系统,建立相关的目录

下载存放路径

/home/ubuntu/down

安装目录

/usr/local/php  #install php-5.4.3

/usr/local/mysql #install mysql5.5.25

/usr/local/openresty #ngx_openresty-1.0.15.9

/usr/local/redis #2.4.14

存储

/storage/redis

配置文件路径:

php配置

/usr/local/php/etc/php/php.ini

/usr/local/php/etc/php/php-fpm.ini

nginx配置

/usr/local/openresty/nginx/conf

项目部署的代码路径,分项目在整个目录下,这里其实有很多的混合的代码,咋个组织比较好呢?

/source/

/source/restybuddy

安装完系统之后,设置root权限

设置root账户

sudo passwd root #设置root的密码

su – root #切换到root正好

替换服务器最近的源

cp /etc/apt/sources.list /etc/apt/sources.list.bak

vim /etc/apt/sources.list

看属于哪个国家,替换最快的源,这样更新会更快些

更新服务器时间(这里有不同的时区可以自己更改)

rm -rf /etc/localtime

ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

修改系统时间

apt-get install -y ntpdate

ntpdate -u pool.ntp.org

date

升级系统组件

apt-get update

apt-get autoremove -y

apt-get -fy install

apt-get install -y build-essential gcc g++ make

for packages in build-essential gcc g++ make automake autoconf re2c wget cron bzip2 libzip-dev libc6-dev file rcconf flex vim nano bison m4 gawk less make cpp binutils diffutils unzip tar bzip2 libbz2-dev unrar p7zip libncurses5-dev libncurses5 libncurses5-dev libncurses5-dev libtool libevent-dev libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlibc openssl libsasl2-dev libxml2 libxml2-dev libltdl3-dev libltdl-dev libmcrypt-dev libmysqlclient15-dev zlib1g zlib1g-dev libbz2-1.0 libbz2-dev libglib2.0-0 libglib2.0-dev libpng3 libfreetype6 libfreetype6-dev libjpeg62 libjpeg62-dev libjpeg-dev libpng-dev libpng12-0 libpng12-dev curl libcurl3 libmhash2 libmhash-dev libpq-dev libpq5 gettext libncurses5-dev libcurl4-gnutls-dev libjpeg-dev libpng12-dev libxml2-dev zlib1g-dev libfreetype6 libfreetype6-dev libssl-dev libcurl3 libcurl4-openssl-dev libcurl4-gnutls-dev mcrypt libcap-dev;

do apt-get install -y $packages –force-yes;apt-get -fy install;apt-get -y autoremove; done

安装语言包

apt-get install language-pack-zh-hans language-pack-zh-hant

服务器支持中文,如果代码里面有中文,可以设置下,也可以不设置

export LC_ALL=”zh_CN.UTF-8″

如果是虚拟机上安装vitualbox tools

现在我们还要到客户机操作系统下,我的是ubuntu下,运行一个命令行控制 台,通过命令将虚拟光驱挂载进来。

mkdir /mnt/cdrom //创建cdrom目录

mount /dev/cdrom /mnt/cdrom //挂载cdrom

下面进入cdrom,运行虚拟光盘上 VBoxLinuxAdditions.run(注意:如果客户机是windows,则需要运行VBoxLinuxAdditions.exe):

cd /mnt/cdrom

sh ./VBoxLinuxAdditions.run

 

虚拟机上设置网卡

1.配置成nat根据本机来上网

2.设置成host-only然后mac下virtual box有问题,先在偏好设置里面添加一个host之后就好了,添加了host 192.168.56.1 这里启用了dhcp但是虚机获取不到还是有问题的。

配置后了之后,需要设置虚机里面的ip,192.168.56.2 之后设置完成就可以通过主机和虚机都可以访问了

3.至此就可以长期的开着的了。

配置多个网卡ip

vim /etc/network/interfaces

添加

# This file describes the network interfaces available on your system

# and how to activate them. For more information, see interfaces(5).

 

# The loopback network interface

auto lo

iface lo inet loopback

 

# The primary network interface

auto eth0

iface eth0 inet dhcp

 

auto eth1

iface eth1 inet static

address 192.168.56.3

netmask 255.255.255.0

network 192.168.56.0

broadcast 192.168.56.255

gatway 192.168.56.1

重起网卡

/etc/init.d/networking restart

安装JRE

sudo apt-get install openjdk-7-jre-headless

配置开机启动

支持securecrt上传用的(我这里没有在WIN下所以没有安装)

sudo apt-get install chkconfig

sudo apt-get install cmake

sudo apt-get install libncurses5-dev

sudo apt-get install bison

安装git

apt-get install -y git

安装svn

apt-get install -y subversion

 设置默认语言及LC

vim ~/.bashrc 添加

export LANG=en_US:zh_CN.UTF-8

export LC_ALL=C

source ~/.bashrc

配置 ssh自动登陆ubuntu

生成rsa_pub

ssh-keygen -t rsa

如果用户名和目标机器用户名不一样,请修改一下文件

vim ~/.ssh/config

添加,多个多行:

Host 192.168.56.3

user ubuntu

复制authorized的key,可以复制多次:

cat ~/.ssh/id_rsa.pub | ssh [email protected] “cat >> ~/.ssh/authorized_keys”

接下来就可以之间

ssh [email protected] 自动登陆

安装MySQL 5.5.25

apt-get install bar

apt-get install libncurses5-dev

groupadd mysql

useradd -s /sbin/nologin -g mysql mysql

wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.25.tar.gz/from/http://ftp.jaist.ac.jp/pub/mysql/

tar zxvf myql-5.5.25.tar.gz

mv mysql-5.5.25 mysql

cd mysql-5.5.25

cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr/local/mysql/ -DSYSCONFDIR=/usr/local/mysql/etc/ -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_READLINE=1 -DWITH_EMBEDDED_SERVER=1 -DWITH_SSL=bundled -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -LH

make

make install

cd /usr/local/mysql

chown -R mysql .

chgrp -R mysql .

sudo install -m644 /usr/local/mysql/support-files/my-medium.cnf ./etc/my.cnf

sudo /usr/local/mysql/scripts/mysql_install_db –user=mysql –basedir=/usr/local/mysql –datadir=/usr/local/mysql/data

sudo install -m755 /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

sudo ln -s /usr/local/mysql/bin/mysql /usr/bin/

sudo ln -s /usr/local/mysql/bin/mysqladmin /usr/bin/

sudo ln -s /usr/local/mysql/bin/mysqld_safe /usr/bin/

sudo ln -s /usr/local/mysql/bin/mysql_conf /usr/bin/

sudo ln -s /usr/local/mysql/share/mysql/mysql.server /usr/bin/

vim ./etc/my.cnf

在[mysqld] 下添加

datadir = /usr/local/mysql/data

language= /usr/local/mysql/share/english #此处为language配置项

/etc/init.d/mysqld start

给mysql设置root命令

mysqladmin -h 127.0.0.1 -u root password 123456

/etc/init.d/mysqld status

尝试登陆看看

./mysql -u root -p

use mysql;

update user set Host=”%” where User=”root” and Host=”localhost”;

需要修改my.cnf配置中添加bind_address

设置开机自动启动

update-rc.d mysqld defaults

查看是否设置成功 chkconfig -list mysqld

安装MySQL 5.1.63

groupadd mysql

useradd -g mysql mysql

mkdir -p /usr/local/mysql5001

mkdir -p /usr/local/mysql5001/data

mkdir -p /usr/local/mysql5001/etc

./configure –prefix=/usr/local/mysql5001/ –localstatedir=/usr/local/mysql5001/data/ –sysconfdir=/usr/local/mysql5001/etc/ –with-charset=utf8

make

make install

chown -R root:mysql /usr/local/mysql5001

chown -R mysql:mysql /storage/mysql5001

chown -R mysql:mysql /usr/local/mysql5001/lib

cd /usr/local/mysql5001/bin

cp /usr/local/mysql5001/share/mysql/mysql.server /etc/init.d/mysqld5001

cp /usr/local/mysql5001/share/mysql/my-medium.cnf /usr/local/mysql5001/etc/my.cnf

./mysql_install_db –user=mysql

./mysql -u root -P 5001 -p

use mysql;

update user set Host=”%” where User=”root” and Host=”localhost”;

flush privileges;

php 5.4.3 install

安装PHP 5.4.3

apt-get install php5-gd

apt-get install libxpm-dev

apt-get build-dep t1lib

apt-get install libxslt-dev

apt-get install libt1-dev

apt-get install libmysql++-dev

./configure –prefix=/usr/local/php \

–with-config-file-path=/usr/local/php/etc \

–with-curl \

–with-pear \

–with-gd \

–with-jpeg-dir –with-png-dir –with-zlib \

–with-freetype-dir –with-t1lib \

–with-mcrypt \

–with-mhash \

–with-mysql –with-mysqli \

–with-pdo-mysql –with-openssl \

–with-xmlrpc \

–with-xsl \

–with-bz2 \

–with-gettext \

–with-fpm-user=www-data –with-fpm-group=www-data –enable-fpm \

–enable-exif \

–enable-wddx \

–enable-zip \

–enable-bcmath \

–enable-calendar \

–enable-ftp \

–enable-mbstring \

–enable-soap \

–enable-sockets \

–enable-shmop \

–enable-dba \

–enable-sysvmsg \

–enable-sysvsem \

–enable-sysvshm

 

make && make install

添加PHP的路径到path

vim ~/.bashrc

export PATH=”$PATH:/usr/local/php/bin:/usr/local/php/sbin”

source /etc/profile

准备PHP5的日志文件目录:

mkdir -p /usr/local/php/logs/php-fpm

chown -R www-data:www-data /usr/local/php/logs/php-fpm

准备PHP的配置文件:

cp -f php.ini-production /usr/local/php/etc/php.ini

chmod 644 /usr/local/php/etc/php.ini

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

注意: PHP5的配置文件在/usr/local/php/etc/php.ini, php-fpm的配置文件在/usr/local/php/etc/php-fpm.conf.

设置php-fpm启动管理文件,并让PHP在ubuntu启动时自动运行(下面地sapi是PHP5.4.0安装包中的):

cp -f sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

chmod 755 /etc/init.d/php-fpm

设置开机启动

update-rc.d -f php-fpm defaults

vim /usr/local/php/etc/php.ini

添加php.ini中的error_log

error_log = /usr/local/php/logs/

安装PHP5.3

./configure –prefix=/usr/local/php –enable-fpm –with-fpm-user=www-data –with-fpm-group=www-data –with-curl –with-mcrypt –enable-mbstring –enable-pdo –with-pdo-mysql=mysqlnd –with-mysqli=mysqlnd –with-mysql=mysqlnd –with-openssl –with-imap-ssl –with-gd –with-jpeg-dir=/usr/lib/ –with-png-dir=/usr/lib/ –enable-exif –enable-zip

make

make install

自己编译nginx

查看nginx的版本及配置信息

Nginx -V

配置Nginx

apt-get install schedutils

wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz

wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP.tar.gz

aptitude install geoip-database

groupadd www

useradd -g www www

apt-get install libpcre3 libpcre3-dev openssl libssl-dev gcc automake make

wget http://luajit.org/download/LuaJIT-2.0.0-beta9.tar.gz

make && make install

配置文件

./configure –prefix=/usr/local/nginx –conf-path=/etc/nginx/nginx.conf –error-log-path=/Logs/nginx/error.log \

–http-client-body-temp-path=/Temps/nginx/body –http-fastcgi-temp-path=/Temps/nginx/fastcgi \

–http-log-path=/Logs/nginx/access.log –http-proxy-temp-path=/Temps/nginx/proxy \

–http-scgi-temp-path=/Temps/nginx/scgi –http-uwsgi-temp-path=/Temps/nginx/uwsgi –lock-path=/Locks/nginx.lock \

–pid-path=/Pids/nginx.pid –with-debug –with-http_addition_module –with-http_dav_module \

–with-http_gzip_static_module –with-http_realip_module –with-http_stub_status_module \

–with-http_ssl_module –with-http_sub_module –with-http_xslt_module –with-ipv6 –with-sha1=/usr/include/openssl \

–with-md5=/usr/include/openssl –with-mail –with-mail_ssl_module \

–add-module=/Packages/nginx_modules/ngx_devel_kit \

–add-module=/Packages/nginx_modules/lua-nginx-module \

–add-module=/Packages/nginx_modules/lua-resty-memcached \

–add-module=/Packages/nginx_modules/lua-resty-mysql \

–add-module=/Packages/nginx_modules/lua-resty-redis

–with-http_image_filter_module \

–with-http_geoip_module

make make install

安装Nginx扩展模块

1. 使用参数重新配置:

./configure –prefix=/app/nginx -user=nobody -group=nobody –with-http_stub_status_module \

–with-http_ssl_module –with-http_realip_module \

–add-module=../nginx_upstream_hash-0.3.1/ \

–add-module=../gnosek-nginx-upstream-fair-2131c73/

2. 编译:

make

#不要make install,否则就是覆盖安装

3. 替换nginx二进制文件:

cp /app/nginx/sbin/nginx /app/nginx/sbin/nginx.bak

cp ./objs/nginx /app/nginx/sbin/

nginx的第三方的插件

http://wiki.nginx.org/3rdPartyModules

日志处理

http://www.xmydlinux.org/201105/493.html 启动配置

http://addcn.blogbus.com/logs/107131815.html 脚本

http://longzhiyi.blog.51cto.com/350171/822159 nginx处理cookie

http://linuxcommand.org/man_pages/logrotate8.html log轮询

http://www.5ilinux.com/2011/12/nginx-logrotate.html 详细log轮询配置

咋个安装nginx的模块的内容

http://www.dewen.org/q/655/%E5%A6%82%E4%BD%95%E5%8D%95%E7%8B%AC%E6%B7%BB%E5%8A%A0nginx%E8%87%AA%E5%AE%9A%E4%B9%89%E6%A8%A1%E5%9D%97

LUA语言

http://blog.csdn.net/hong201/article/category/531338

安装OpenResty套件,本次选择agentzh大侠做的,省去上面配置的麻烦

apt-get install libreadline-dev libncurses5-dev libpcre3-dev libssl-dev perl

./configure –with-luajit

make

make install

默认安装到/usr/local/openresty/目录下

nginx.conf中有配置文件错误的时候也会出错的。导致无法route

安装全文检索coreseek/sphinx

wget http://www.coreseek.cn/uploads/csft/4.0/coreseek-4.1-beta.tar.gz

tar zxvf coreseek-4.1-beta.tar.gz

cd mmseg-3.2.14

./bootstrap #输出的warning信息可以忽略,如果出现error则需要解决

./configure –prefix=/usr/local/mmseg3

make && make install

cd ..

##安装coreseek

cd csft-4.1

sh buildconf.sh #输出的warning信息可以忽略,如果出现error则需要解决

./configure –prefix=/usr/local/coreseek –without-unixodbc –with-mmseg –with-mmseg-includes=/usr/local/mmseg3/include/mmseg/ –with-mmseg-libs=/usr/local/mmseg3/lib/ –with-mysql ##如果提示mysql问题,可以查看MySQL数据源安装说明

make && make install

cd ..

编译安装mysql 5.1-*的sphinxse引擎:

1. 在MySQL源码目录中建立storage/sphinx目录,并将Sphinx源码目录中的mysqlse目录下的全部文件拷贝到这个目录。示例:

mkdir -p /home/yangxinqi/down/mysql-5.1.57/storage/sphinx

cp -R /home/yangxinqi/down/coreseek-4.1-beta/csft-4.1/mysqlse/* /home/yangxinqi/down/mysql-5.1.57/storage/sphinx

2. 在MySQL源码目录运行

sh BUILD/autorun.sh

3. 配置(configure)MySQL,启用Sphinx引擎,prefix指定安装到所在的目录

./configure –with-plugins=sphinx –prefix=/usr/local/mysql5004

4. 构建(build)并安装MySQL

make

make install

编译安装mysql 5.5系列的sphinx引擎

cd mysql-5.5.25

mkdir ./storage/sphinx

cp -r /home/ubuntu/down/coreseek-4.1-beta/csft-4.1/mysqlse/* ./storage/sphinx

cmake . -DCMAKE_BUILD_TYPE=Release -DWITH_SPHINX_STORAGE_ENGINE=1

make

cp storage/sphinx/ha_sphinx.so /usr/local/mysql/lib/plugin

mysql -uroot -p

mysql>install plugin sphinx soname “ha_sphinx.so”;

mysql>show engines;

安装redis

1、下载安装Redis:cd /tmp

wget http://redis.googlecode.com/files/redis-2.4.6.tar.gz

tar -zxf redis-2.4.6.tar.gz

cd redis-2.4.6

make

make PREFIX=/usr/local/redis install

ln -s /usr/local/redis/bin/* /usr/bin

2. 配置init脚本:wget https://github.com/ijonas/dotfiles/raw/master/etc/init.d/redis-server

wget https://github.com/ijonas/dotfiles/raw/master/etc/redis.conf

sudo mv redis-server /etc/init.d/redis-server

sudo chmod +x /etc/init.d/redis-server

sudo mv redis.conf /etc/redis.conf

3. 初始化用户和日志路径第一次启动Redis前,建议为Redis单独建立一个用户,并新建data和日志文件夹

sudo useradd redis

sudo mkdir -p /var/lib/redis

sudo mkdir -p /var/log/redis

sudo chown redis.redis /var/lib/redis

sudo chown redis.redis /var/log/redis

4、设置开机自动启动,关机自动关闭update-rc.d redis-server defaults

5、启动Redis:

/etc/init.d/redis-server start

安装scws分词组件

wget http://www.ftphp.com/scws/down/scws-1.2.0.tar.bz2

tar xvf scws-1.2.0.tar.bz2

./configure –prefix=/usr/local/scws

make

make install

安装scws的php扩展

cd phpext

phpize

./configure –with-php-config=/usr/local/php/bin/php-config

make

make install

vim /usr/local/php/etc/php.ini

extensiton=scws.so

安装phpredis

wget https://github.com/nicolasff/phpredis/zipball/master

unzip master

cd nicolasff-phpredis-f1231c9

phpize

./configure -with-php-config=/usr/local/php/bin/php-config

make && make install

vim /usr/local/php/etc/php.ini

extension=redis.so

安装phpunit

cd /usr/local/php/bin #如果不是root,请使用sudo ./pear ….

pear channel-discover pear.phpunit.de

pear channel-discover components.ez.no

pear channel-discover pear.symfony-project.com

pear install phpunit/PHPUnit

安装vim ide (喜欢的可以安装,个人感觉还不错)

http://code.google.com/p/vimide/wiki/GuideCn

sudo apt-get install exuberant-ctags wget unzip

svn checkout http://vimide.googlecode.com/svn/trunk/linux vimide

cd vimide/

sh install.sh

vim /root/.vimrc

map <silent><F3> <ESC>:NERDTreeToggle<CR

FastDFS配置

编译错误的时候需要找到libpthread.a的位置

/usr/lib/x86_64-linux-gnu/libpthread.a

http://blog.csdn.net/chen861201/article/details/7341637

find / -name ‘libpthread.so’

/usr/lib/x86_64-linux-gnu/libpthread.so

按照后配置

1. extension = fastdfs_client.so

2. fastdfs_client.tracker_group_count = 1

3. fastdfs_client.tracker_group0 = /etc/fdfs/client.conf

然后修改client.conf 中的traceserver的地址就好了

http://code.google.com/p/fastdfs/

这里是支持的地方

http://bbs.chinaunix.net/forum.php?mod=forumdisplay&fid=240&page=1

可以直接部署nginx+fastdfs进行存储,还是很方便的

安装memcached

wget http://memcached.googlecode.com/files/memcached-1.4.13.tar.gz

./configure –prefix=/usr/local/memcached

/usr/local/memcached/bin/memcached -m 64 -p 11211 -u ubuntu -l 127.0.0.1 &

telnet 127.0.0.1 11211

 

安装php memcachd扩展

wget https://launchpad.net/libmemcached/1.0/1.0.6/+download/libmemcached-1.0.6.tar.gz

sudo apt-get install libcloog-ppl0

make && make install

wget http://pecl.php.net/get/memcached-2.0.1.tgz

tar zxvf memcached-2.0.1.tgz

cd memcached-2.0.1

phpize

./configure –with-php-config=/usr/local/php/bin/php-config

make

make install

vim /usr/local/php/etc/php.ini

extension=memcached.so

/etc/init.d/php-fpm restart

memcat –servers=127.0.0.1:11211

输出的为 memcached 服务器的一些统计数据等。

 一些维护工具的文章

安装ClusterShell服务器运维工具

sudo apt-get install clustershell

http://huoding.com/2011/11/12/133

MYSQL高可用性方案

http://code.google.com/p/mysql-master-ha/

需要系统开机启动的则可以加入到chkconfig 或者 加入到 /etc/init.d/rc.local中开机自动启动

禁用ROOT,这样会更安全

将ubuntu加入到root

chmod u+w /etc/sudoers

vim /etc/sudoers
添加
loginusername ALL=(ALL) ALL
chmod u-w /etc/sudoers
完成后禁用root

 

 

 

你可能感兴趣的:(Ubuntu12.04 64bit最新环境安装教程)