2012年1月31日 星期二

Linux Ubuntu 10.10 重設遺失的root密碼以及mysql密碼

Linux防健忘日誌No.35-Ubuntu 10.10 重設遺失的root密碼以及mysql密碼

到開機GRUB選單(如果沒有多系統,GRUB選單會閃得很快,請壓住SHIFT開機)

選到recovery mode之後按下"e"

找到ro single後替換成rw single init=/bin/bash

之後ctrl+x繼續讓他進入開機

這時候沒有權限上的問題,可以直接用passwd指令改掉root密碼

************************************

接著是mysql

之前LAMP一文有講過忘記mysql會相當之麻煩!
不過那是以前在windows下不好處理

到linux下甚麼都ok啦...

先幹掉所有mysql的服務

killall mysqld
讓mysqld在背景執行再不檢查安全表單的環境
mysqld -u root --skip-grant-tables &

執行進去
mysql


以下照著打,">"不用打

>use mysql
>UPDATE user SET password=password('你的密碼要含小引號') where user='root';
>FLUSH PRIVILEGES;

thx for:
http://www.wretch.cc/blog/THKAW/21910822

2012年1月19日 星期四

Ubuntu Postfix 郵件轉寄設定

編輯 vim  /etc/aliases
增加一筆轉寄3信箱紀錄
Sample:
usermail:      ooxx@gmail.com,xxoo@yahoo.com.tw,user@pchome.com.tw

儲存後執行newaliases 指令後即可運作。

2011年12月29日 星期四

Linux 各種壓縮與解壓縮指令

.tar

  • 套件:tar
  • 打包:tar cvf FileName.tar DirName
  • 解包: tar xvf FileName.tar

.gz

  • 套件:gzip
  • 壓縮:gzip FileName
  • 解壓1:gunzip FileName.gz
  • 解壓2:gzip -d FileName.gz

.tar.gz

  • 套件:gzip
  • 壓縮:tar zcvf FileName.tar.gz DirName
  • 解壓:tar zxvf FileName.tar.gz

.bz2

  • 套件:bzip2
  • 壓縮: bzip2 -z FileName
  • 解壓1:bzip2 -d FileName.bz2
  • 解壓2:bunzip2 FileName.bz2

.tar.bz2

  • 套件:bzip2
  • 壓縮:tar jcvf FileName.tar.bz2 DirName
  • 解壓:tar jxvf FileName.tar.bz2

bz

  • 壓縮:unkown
  • 解壓1:bzip2 -d FileName.bz
  • 解壓2:bunzip2 FileName.bz

.tar.bz

  • 壓縮:unkown
  • 解壓:tar jxvf FileName.tar.bz

.Z

  • 壓縮:compress FileName
  • 解壓:uncompress FileName.Z

.tar.Z

  • 壓縮:tar Zcvf FileName.tar.Z DirName
  • 解壓:tar Zxvf FileName.tar.Z

.tgz

  • 壓縮:unkown
  • 解壓:tar zxvf FileName.tgz

.tar.tgz

  • 壓縮:tar zcvf FileName.tar.tgz FileName
  • 解壓:tar zxvf FileName.tar.tgz

.zip

  • 套件:zip
  • 壓縮:zip FileName.zip DirName
  • 解壓:unzip FileName.zip

.rar

  • 套件:rar, unrar
  • 壓縮:rar a FileName.rar DirName
  • 解壓1:rar e FileName.rar
  • 解壓2:unrar e FileName.rar

.lha

  • 套件:lha
  • 壓縮:lha -a FileName.lha FileName
  • 解壓:lha -e FileName.lha

.7z

  • 套件:p7zip-full
  • 壓縮:7zr a FileName
  • 解壓:7zr x FileName.7z
Writing by凍仁翔

Ubuntu MYSQL 匯出資料庫程式與星期備份檔名語法用法

1.日期第一行 宣告日期
 now=`/bin/date`

2.MYSQL DB匯出指令
/usr/bin/mysqldump --opt --user=帳號 -p --password=密碼  資料庫名稱  > /mnt/匯出路徑/`echo $now | cut -b 1-3`-檔案定義名稱.sql

3.還原指令

mysqldump --lock-all-tables -u root -p 資料庫名稱 > example.sql


mysql -u root -p 資料庫名稱 < example.sql

Ubuntu之NFS SERVER & Client 安裝及開機自動掛載設定

Server 部份:

1. 安裝 NFS server 套件
 
    sudo apt-get install nfs-common nfs-kernel-server

2. 設定要共享的路徑和使用權限

    sudo vim /etc/exports

    #將 /nfs_root 這個路徑 share 給 all net 使用,但只可讀並且資料會同步寫入到記憶體與硬碟中。
    /nfs_root *(ro,sync,no_subtree_check)

3. 啟動 NFS server

    sudo /etc/init.d/nfs-kernel-server start

4. 檢查 NFS server 是否成功被啟動了

    sudo showmount -e localhost

    #看到底下剛剛設定的共享路徑代表成功了。
    Export list for localhost:
    /nfs_root *


註:
(1) 使用者可以用 showmount -e nfs_server_ip 看這個NFS server有哪些共享路徑。
(2) 使用者可以用 mount -t nfs nfs_server_ip:共享路徑 /mnt 來掛載NFS server提供的共享路徑。




Client 方式一:
1. 安裝 nfs client
$ sudo apt-get install nfs-common
2. 將 nas 分享的資料夾,掛上伺服器
$ sudo mount -t nfs 192.168.0.125:/test/遠端路徑  /mnt/本地端路徑
3. 若要重新開機後,自動掛載,則需修改 /etc/fstab
$ sudo nano fstab
加入
192.168.0.125:/test/遠端路徑     /mnt/本地端路徑   nfs defaults 1 1
即可
Client 方式二:

將 NFS 開機即掛載就寫入 /etc/rc.d/rc.local 即可。

mount -t nfs -o nosuid,noexec,nodev,rw,bg,soft,rsize=32768,wsize=32768 \192.168.100.254遠端IP:/home/public遠端目錄位置   /home/nfs/public本機目錄位置

2011年12月6日 星期二

Ubuntu VSFtp 安裝

我們使用ubuntu預設的 apt-get 套件來做安裝。

sudo apt-get install vsftpd

過程中,它會問你是否要安裝,請你按Y即可。
安裝完成後,我們可以來查看是否安裝成功,可用下列指令。

netstat -tul | grep ftp

下列會顯示一行訊息,最後會有一個LISTEN,表示已運行待命中。



你可以使用root開啟檔案總管,然後開啟/etc/vsftpd.conf,並編輯他
或者是直接在終端機內輸入。

sudo vim /etc/vsftpd.conf

接下來以下為我的參數設定:
#==================================================

# Example config file /etc/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
#
# Run standalone? vsftpd can run either from an inetd or as a standalone
# daemon started from an initscript.
listen=YES
#
# Run standalone with IPv6?
# Like the listen parameter, except vsftpd will listen on an IPv6 socket
# instead of an IPv4 one. This parameter and the listen parameter are mutually
# exclusive.
#listen_ipv6=YES
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=NO
#
# Uncomment this to allow local users to log in.
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
#anon_upload_enable=YES
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=YES
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# Activate logging of uploads/downloads.
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# You may override where the log file goes if you like. The default is shown
# below.
xferlog_file=/var/log/vsftpd.log
#
# If you want, you can have your log file in standard ftpd xferlog format
xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
idle_session_timeout=600
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
#ascii_upload_enable=YES
#ascii_download_enable=YES
#
# You may fully customise the login banner string:
#ftpd_banner=Welcome to OIpingo FTP service.
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd.banned_emails
#
# You may restrict local users to their home directories. See the FAQ for
# the possible risks in this before using chroot_local_user or
# chroot_list_enable below.
#chroot_local_user=YES
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
chroot_list_enable=YES
# (default follows)
chroot_list_file=/etc/vsftpd.chroot_list
#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES
#
#
# Debian customization
#
# Some of vsftpd's settings don't fit the Debian filesystem layout by
# default. These settings are more Debian-friendly.
#
# This option should be the name of a directory which is empty. Also, the
# directory should not be writable by the ftp user. This directory is used
# as a secure chroot() jail at times vsftpd does not require filesystem
# access.
secure_chroot_dir=/var/run/vsftpd
#
# This string is the name of the PAM service vsftpd will use.
pam_service_name=vsftpd
#
# This option specifies the location of the RSA certificate to use for SSL
# encrypted connections.
rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
# This option specifies the location of the RSA key to use for SSL
# encrypted connections.
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key


#可以接受的最大clinet可連線的數目
max_clients=20
#每個ip的最大連線數目
max_per_ip=15#啟用被動式連線pasv_enable=YES
#設定連線的port,可以自訂listen_port=21

Network 修改固定IP

在 Ubuntu Server 更改 IP 。
1. 編輯 ip 設定檔

Goldenmelon@ubuntu:~$ sudo vi /etc/network/interfaces


2. 更改 eth0 設定,將
auto eth0
iface eth0 inet dhcp

改為
auto eth0
iface eth0 inet static
address 192.168.˙˙˙.˙˙˙
netmask 255.255.255.0
gateway 192.168.˙˙˙.˙˙˙


3. 重新連線
GoldenMelon@ubuntu:~$ sudo /etc/init.d/networking restart