环境:ubuntu 10.10
每天上班的第一件事就是开电脑 , 开一些工作上必须用的软件 或者一些服务 , 每天 都要动你的鼠标 去打开 应用程序 或者 在terminal 上敲命令启动 服务,这样 未免 太麻烦了 ,一点也不 DRY , 那就 把你每天必备的 服务 , 都放在 rc.local中 或者使用 update-rc.d , GUI 软件放到 startup applications 中 随着 开机一起启动吧
开机 自启动服务
使用 rc.local
1,把你需要 启动的 程序都放到 /etc/rc.local 中,注意写到 exit 0 前面
2,默认 ubuntu 的 shell 是 dash ,据说 是为了 提高 开机速度
wxianfeng@ubuntu:~$ ls -l /bin/sh lrwxrwxrwx 1 root root 4 2010-11-12 19:12 /bin/sh -> dash
但是 dash 是一个 对脚本 兼容性 和 容错性 非常差的 shell,修改 rc.local 用 bash 来执行不要使用 dash
#!/bin/sh
改为
#!/bin/bash
或者直接修改 ubuntu 默认shell
wxianfeng@ubuntu:~$ ll /bin/sh lrwxrwxrwx 1 root root 4 2010-11-12 19:12 /bin/sh -> dash* wxianfeng@ubuntu:~$ sudo dpkg-reconfigure dash # 选择 NO wxianfeng@ubuntu:~$ ll /bin/sh lrwxrwxrwx 1 root root 4 2010-12-24 10:37 /bin/sh -> bash*
3,服务 无法 开启 daemon(守护进程) 的 用 nohup 启动 ,例如 mongodb
4,确保 文件的执行权限 登录的普通用户可以使用 , 默认 ubuntu 登录 是非 root 账户
修改前:
wxianfeng@ubuntu:~$ ll /etc/rc.local -rwxr-xr-x 1 root root 736 2010-12-24 09:35 /etc/rc.local*
修改:
wxianfeng@ubuntu:~$ sudo chgrp -R wxianfeng /etc/rc.local wxianfeng@ubuntu:~$ sudo chown -R wxianfeng /etc/rc.local
修改后:
wxianfeng@ubuntu:~$ ll /etc/rc.local -rwxr-xr-x 1 wxianfeng wxianfeng 736 2010-12-24 09:35 /etc/rc.local*
5,把 rc.local 中的 第一行 -e 给去掉
-e 参数 是 脚本遇到 错误 就退出 , 这个 很不好 , 可以 man sh 看下 -e 参数:
>man sh -e errexit If not interactive, exit immediately if any untested command fails. The exit status of a command is considered to be explicitly tested if the command is used to control an if, elif, while, or until; or if the command is the left hand operand of an “&&” or “||” operator.
6,DEMO:
wxianfeng@ubuntu:~$ cat /etc/rc.local #!/bin/bash # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. /etc/init.d/mysql start # 启动 mysql exit 0
说了 那么多 , 说下 rc.local 的 启动原理:
ubuntu 的开机的时候 会根据当前的 运行级别 即 runlevel
wxianfeng@ubuntu:~$ runlevel N 2
可以看出是2 ,然后 通过 runlevel 执行 /etc/rc*.d 下的 所有文件 ,这里即 rc2.d
wxianfeng@ubuntu:~$ ll /etc/rc2.d/ total 20 drwxr-xr-x 2 root root 4096 2010-12-06 10:30 ./ drwxr-xr-x 141 root root 12288 2010-12-24 11:04 ../ -rw-r--r-- 1 root root 677 2010-09-25 02:16 README lrwxrwxrwx 1 root root 20 2010-11-12 19:12 S20fancontrol -> ../init.d/fancontrol* lrwxrwxrwx 1 root root 20 2010-11-12 19:12 S20kerneloops -> ../init.d/kerneloops* lrwxrwxrwx 1 root root 27 2010-11-12 19:12 S20speech-dispatcher -> ../init.d/speech-dispatcher* lrwxrwxrwx 1 root root 24 2010-12-06 10:30 S20virtualbox-ose -> ../init.d/virtualbox-ose* lrwxrwxrwx 1 root root 19 2010-11-12 19:12 S25bluetooth -> ../init.d/bluetooth* lrwxrwxrwx 1 root root 20 2010-11-12 19:12 S50pulseaudio -> ../init.d/pulseaudio* lrwxrwxrwx 1 root root 15 2010-11-12 19:12 S50rsync -> ../init.d/rsync* lrwxrwxrwx 1 root root 15 2010-11-12 19:12 S50saned -> ../init.d/saned* lrwxrwxrwx 1 root root 19 2010-11-12 19:12 S70dns-clean -> ../init.d/dns-clean* lrwxrwxrwx 1 root root 18 2010-11-12 19:12 S70pppd-dns -> ../init.d/pppd-dns* lrwxrwxrwx 1 root root 14 2010-11-12 19:12 S75sudo -> ../init.d/sudo* lrwxrwxrwx 1 root root 24 2010-11-12 19:12 S90binfmt-support -> ../init.d/binfmt-support* lrwxrwxrwx 1 root root 17 2010-11-15 13:45 S91apache2 -> ../init.d/apache2* lrwxrwxrwx 1 root root 22 2010-11-12 19:12 S99acpi-support -> ../init.d/acpi-support* lrwxrwxrwx 1 root root 21 2010-11-12 19:12 S99grub-common -> ../init.d/grub-common* lrwxrwxrwx 1 root root 18 2010-11-12 19:12 S99ondemand -> ../init.d/ondemand* lrwxrwxrwx 1 root root 18 2010-11-12 19:12 S99rc.local -> ../init.d/rc.local*
可以 看到 S99rc.local 软链接 从 /etc/init.d/rc.local 过来的 ,打开 看看 ,这里有 调用 /etc/rc.local 的文件 ,/etc/rc.local 也就是 从这里启动的:
wxianfeng@ubuntu:~$ cat /etc/init.d/rc.local #! /bin/sh ### BEGIN INIT INFO # Provides: rc.local # Required-Start: $remote_fs $syslog $all # Required-Stop: # Default-Start: 2 3 4 5 # Default-Stop: # Short-Description: Run /etc/rc.local if it exist ### END INIT INFO PATH=/sbin:/usr/sbin:/bin:/usr/bin . /lib/init/vars.sh . /lib/lsb/init-functions do_start() { if [ -x /etc/rc.local ]; then [ "$VERBOSE" != no ] && log_begin_msg "Running local boot scripts (/etc/rc.local)" /etc/rc.local ES=$? [ "$VERBOSE" != no ] && log_end_msg $ES return $ES fi } case "$1" in start) do_start ;; restart|reload|force-reload) echo "Error: argument '$1' not supported" >&2 exit 3 ;; stop) ;; *) echo "Usage: $0 start|stop" >&2 exit 3 ;; esac
使用 update-rc.d
apache 开机自启动
>sudo update-rc.d apache2 defaults
mysql 开机自启动
>sudo update-rc.d mysql defaults
开机 启动 GUI 软件
上面 是 开机 启动一些服务 ,例如 mysql ,apache 啥的 ,但是 开机启动一些软件 怎么办,例如 netbeans , eclipse 等
ubuntu 已经 给了我们 gui的配置工具
system -> prefences -> start applications
把所有启动的 GUI 软件 放到一个 shell 里,然后 添加 启动这个shell 即可:
wxianfeng@ubuntu:~$ cat /usr/local/system/shell/autostart.sh #!/bin/sh nohup /usr/local/system/netbeans6_9/bin/netbeans --locale zh_CN.UTF-8 & # 启动netbeans nohup firefox & # 启动 firefox 可以 默认开启一个网页 firefox blog.wxianfeng.com nohup /opt/google/chrome/google-chrome & # 启动 chrome nohup guake & # 启动guake nohup emesene & # 启动 emesene (ubuntu MSN客户端) nohup empathy & # 启动 empathy (登录gtalk之用)
添加 过后 其实 是在 ~/.config/autostart 目录下 建立了一个新的.desktop启动文件
cd ~/.config/autostart/ wxianfeng@ubuntu:~/.config/autostart$ ll total 12 drwx------ 2 wxianfeng wxianfeng 4096 2010-12-24 11:03 ./ drwxr-xr-x 18 wxianfeng wxianfeng 4096 2010-12-24 11:03 ../ -rw-r--r-- 1 wxianfeng wxianfeng 266 2010-12-24 11:03 autostart.sh.desktop wxianfeng@ubuntu:~/.config/autostart$ cat autostart.sh.desktop [Desktop Entry] Type=Application Exec=/usr/local/system/shell/autostart.sh Hidden=false NoDisplay=false X-GNOME-Autostart-enabled=true Name[en_US]=autostart_shell Name=autostart_shell Comment[en_US]=start GUI software when boot Comment=start GUI software when boot
也就是说 这个文件 你可以 手动建立 , 从里面可以看出 我开机启动的 shell 脚本 路径在 /usr/local/system/shell/autostart.sh
注意点:
刚开始 我想把我的 gui 软件 启动也放到rc.local 中 ,这个 是不允许的 ,rc.local 只能启动服务,不能启动 图形界面的 程序
see:
http://www.bettershop.com.cn/bbs/read.php?tid-1029.html http://blog.163.com/lgh_2002/blog/static/44017526201032803748503 http://www.ihacklog.com/linux/tips-linux/fcitx-autostart-via-rc-local.htm
最终环境 : ubuntu 10.10 + ruby 1.8.7 + rails 2.3.5 + mysql 5.1
换了新工作,重新搭建开发环境,鉴于之前mysql遇到问题,总是不好解决,束手无策,甚至找不到 mysql 安装哪去了,所以这次主要想编译安装mysql,这样有利于了解mysql
1,下载ruby1.8.7 (http://www.ruby-lang.org/en/news/2010/08/16/ruby-1-8-7-p302-is-released/)
wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p302.tar.bz2
2,安装依赖的库
sudo apt-get install build-essential sudo apt-get install autoconf sudo apt-get install zlib1g-dev sudo apt-get install openssl libssl-dev
3,编译安装ruby
tar -jxvf ruby-1.8.7-p302.tar.bz2 cd ruby-1.8.7-p302/ autoconf ./configure --prefix=/usr/local/system/ruby make sudo make install
4,ruby 加到PATH 中
vim ~/.bashrc export PATH="$PATH:/usr/local/system/ruby/bin"
5,ruby -v
安装rubygems(http://rubyforge.org/frs/?group_id=126&release_id=43601)
1,下载
wget http://rubyforge.org/frs/download.php/70696/rubygems-1.3.7.tgz
2,解压
tar -zvxf rubygems-1.3.7.tgz
3,安装
cd rubygems-1.3.7/ wxianfeng@ubuntu:~/Desktop/rubygems-1.3.7$ ruby setup.rb ERROR: While executing gem ... (Errno::EACCES) Permission denied - /usr/local/system/ruby/lib/ruby/site_ruby/1.8/rubygems wxianfeng@ubuntu:~/Desktop/rubygems-1.3.7$ sudo ruby setup.rb [sudo] password for wxianfeng: sudo: ruby: command not found 改变权限 cd /usr/local sudo chmod -R 777 system/ 再次安装就ok了,不然你以后还会遇到这个问题
4,gem -v
安装rails 2.3.5
>gem install rails -v 2.3.5 --no-ri --no-rdoc
编译安装 mysql
1,下载并且编译安装
download (http://downloads.mysql.com/archives.php?p=mysql-5.1) 从archives 找到 ,注意下载的是source包
sudo apt-get install g++ libncurses5-dev # 安装依赖的库 sudo groupadd mysql # 建立mysql用户组 sudo useradd -g mysql mysql # 添加用户mysql tar -zvxf mysql-5.1.51.tar.gz cd mysql-5.1.51/ ./configure --prefix=/usr/local/system/mysql --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=latin1(all) --with-plugins=innobase(all) # config 很重要,括号里是或者 make sudo make install sudo cp support-files/my-medium.cnf /etc/my.cnf # 配置文件
注意mysql sock文件安默认装在tmp路径下 /tmp/mysql.sock,编译的时候 —with-plugins=all 建议加上 不然你会发现编译后不支持innodb引擎,那就麻烦了!
2, 初始化数据库并修改目录权限
cd /usr/local/system/mysql sudo bin/mysql_install_db --user=mysql sudo chown -R root . sudo chown -R mysql /usr/local/system/mysql/var sudo chgrp -R mysql .
3,启动mysql
bin/mysqld_safe --user=mysql & netstat -antup | grep 3306 sudo cp /usr/local/system/mysql/share/mysql/mysql.server /etc/init.d/mysql sudo killall mysqld # kill 刚刚启动的mysql sudo /etc/init.d/mysql start|stop|restart|status # 重启mysql
4,添加PATH
>vim ~/.bashrc export PATH="$PATH:/usr/local/system/mysql/bin" wxianfeng@ubuntu:/usr/local/system/mysql/bin$ mysql --version mysql Ver 14.14 Distrib 5.1.51, for pc-linux-gnu (i686) using EditLine wrapper
5, 修改mysql root 密码
>sudo /etc/init.d/mysql start --skip-grant-tables >mysql -uroot -p mysql >update user set password=passsword('root') where user='root'; 重启mysql 就ok了 root 账户的密码为root
6,怎么判断我的mysql是编译安装的
wxianfeng@ubuntu:~$ mysql --version mysql Ver 14.14 Distrib 5.1.51, for pc-linux-gnu (i686) using EditLine wrapper
如果你是apt-get 安装的话就显示 for ubuntu-linux-gnu
yum 安装的话就显示 for redhat-linux-gnu 了
遇到的问题:
1,
>mysql -uroot -p
Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)
>mysql -uroot -p --socket=/tmp/mysql.sock 可以启动,所以是sock问题 后来发现 my.cnf 有两个配置文件,/etc/mysql/my.cnf 多了一个这个,里面sock路径指定不一样所致,rename 掉 >mv /etc/mysql/my.cnf /etc/mysql/my_cnf.bak
2,
Starting MySQL. * Manager of pid-file quit without updating file. 错误
wxianfeng@ubuntu:/usr/local/system/shell$ /etc/init.d/mysql start Starting MySQL. * Manager of pid-file quit without updating file.
需要加sudo
3,查看mysql data目录
root@ubuntu:/usr/local/system/mysql/var# ps auxf | grep mysql root 25756 0.0 0.0 4012 764 pts/3 S+ 15:32 0:00 | \_ grep --color=auto mysql root 25000 0.0 0.0 4904 1400 ? S 14:22 0:00 /bin/sh /usr/local/system/mysql/bin/mysqld_safe --datadir=/usr/local/system/mysql/var --pid-file=/usr/local/system/mysql/var/ubuntu.pid mysql 25106 0.0 0.8 119652 16568 ? Sl 14:22 0:00 \_ /usr/local/system/mysql/libexec/mysqld --basedir=/usr/local/system/mysql --datadir=/usr/local/system/mysql/var --user=mysql --log-error=/usr/local/system/mysql/var/ubuntu.err --pid-file=/usr/local/system/mysql/var/ubuntu.pid --socket=/tmp/mysql.sock --port=3306
可以看出在var下 ,注意 var目录的用户是 mysql ,必须root用户才能cd进入
sudo su # 切换到root用户
4,启动rails project报错:因为mysql gem的版本过高的原因
uninitialized constant MysqlCompat::MysqlRes (NameError) >sudo apt-get install libmysqlclient-dev >gem install mysql -v=2.7 --no-ri --no-rdoc
SEE:
http://blog.sitearth.com/ubuntu%E4%B8%8A%E6%90%AD%E5%BB%BAlamp%E7%8E%AF%E5%A2%83%E7%AC%94%E8%AE%B0%E2%80%94%E2%80%94mysql%E6%BA%90%E7%A0%81%E5%AE%89%E8%A3%85%E5%8F%8A%E9%85%8D%E7%BD%AE/
http://51jsp.cn/html/ror/2010/0327/14859.html
see:http://qichunren.javaeye.com/blog/577556

整整一天都趴在电脑前, 只因为方正宽带 , 本想下午去打篮球的 , 也没有玩成, 情况是这样的 ,方正宽带 一台电脑(一个系统) 只容许 一个ip , 不能接路由器 , 也就是 说 如果你重新装了系统 都要 打 电话给 客服, 重新绑定下 网卡 , 变态吧 , 我现在 是 想在我的vmware种虚拟一个 centos 系统来使用 , 可是 一切都是那么的不顺利 。。。
我为什么要虚拟一个centos?
本人准备 放弃 wordpress 了 , 用起来时多么的别扭 , 最重要的是我 不熟悉 php , 只会搭站, 所以很无奈 , 虚拟 centos 是因为我准备 到linode 购买VPS , 就在等我的 信用卡 下来了 , 那样我本地 也用 centos , 服务器也用centos , 这样好保持同步
首先, 刻录centos系统盘
到官网下载了 i386-live-cd.iso (5.5)映象 , 回来刻录 , 刻录过程也 蛮痛苦的 , 期间刻录失败了N张盘不说 ,害的我到taobao 买了 20 张cd碟 , 回来继续可虑 , 最终总算刻录成功了 , 失败的原因 第一 因为 我选择了 copy的方式 , 第二 刻录软件的 问题 , 应该选择burn的方式刻录 , 刻录软件 试了好几款 , 包括强大的nero , 但是最后 总结下来 , 最好用的 是 imgburn 和 poweriso ,imgburn 是免费版 , 比较好用 , 激励推荐 , poweriso 需要破解版, 可以查看 iso文件 内容 , 还可以 burn , 真是 不错 , 刻录好了 , 到虚拟机 里安装, 一直失败 。。。 后来 就没有折腾了 , 还是拿出了 自己很老的一张 ubuntu 8.10 的盘来安装了
解决ubuntu 汉字输入
一直以来 我安装linux , 都是选择安装的英文版 , 这次很失败 , 首先安装玩ubuntu , 然后 又安装了 中文语言包, 如果这里 到language support 中 看不到 chinese 语言 , 请先执行 sudo apt-get update 更新下source , 这样 再打开 language support 就可以 看到 chinese , 安装玩 chinese 语言包, 然后 重启ubuntu , 俺道理说这样 就可以 输入 中文了 , 可是 开启后 连scim 输入法 都没 激活 , 真是 变态 , 只好 shell 下 > sudo scim 手动启动 scim了, 可是启动了还是 不能 使用 , 折腾了好大 一会 还是不能 使用 , 最后 只好选择中文语言环境, 重启后 OK 了 , 行了 , 就这样吧, 中文版一样用 , 如果 你安装了 英文版 , 但是连上了 网 无法输入中文 , 去google 的话 , 给你一个好办法, firefox 安装一个 fireinput 插件 , 这样可以解决 燃眉之急 , 至少我都是这么办的 。。
解决虚拟机内的 屏幕太小
众所周知 , 虚拟机内的 系统屏幕太小, 怎么办呢 , 到网上google 了下, 说要修要 xorg.conf 而且还很 麻烦, 最后 还是没有 修改 成功 , 后来才发现 其实 ubuntu 已经自带了这个 系统工具 , 在菜单里找到 screen resolution 打开 , 即可调节分辨率 , 哇, ok , 搞定了 。。。。。
解决 虚拟机 ubuntu 上网
这个 过程 时间最长 , 所以也放在最后一步写,都TMD 方正惹得祸 , 打了N次客服 , 要不是 没人接, 要不是 接了说 linux 没培训过, 不知道 怎么设置 , 最终 终于有人会了 , 他让我试一试 , 不过最后还是折腾成功了 , 平时 我们都是 用的 windows 方正宽带客户端 , 这个时候 该抛弃了 , 使用 web登陆方式 ,
(1) windows 下 设置好 你的ip , 网关 , DNS 什么的, 在浏览器里 打入 10.0.238.1 网关地址 , 如果出错的话, 这时候 你应该 打电话给客服了 , 让他给你重新绑定网卡 , 这是你windows想ia已经可以上网了
(2) 解决 虚拟机内的ubuntu 上网 , 首先 windows 下 输入 10.0.238.1 这个提示你是一家登陆了,点击退出 , 然后修改 你的 windows 下的ip 不要和 能 上网的那个重复 , 随便 改个好了 , 虚拟机的网卡 选择 桥连 方式 , 设置ubuntu 内的 ip ,netmask , gateway ,dns为正确的 值 , 也就是你之前windows 下的 设置的值 , 这个 时候 你浏览器里输入 10.0.238.1 网关地址 , 如果出现 错误 , 该打电话 给客服了 , 又需要 重新绑定下 网卡 , 绑定之后 , ok , 你的 ubuntu 现在 已经可以上网了
(3) , 也就是 说你windows 上网了 , 虚拟机内的ubuntu 不可以上 , 虚拟机内的ubuntu上网的话, windows 就不能上了 。前提是你还要 退出之前 那个系统的的web登陆 。
这个 对 在于北京 的 使用方正 宽带的用户 还是有帮助的 , 前提是你用 linux 上网 , 或者用了虚拟机 , 或者装了 双系统, 要不然还是比较麻烦的。。。。
ok 。。结束!