內容選單標籤

2015年1月27日 星期二

Server5_bind

# yum -y install bind bind-chroot
# vi /etc/sysconfig/iptables
.
-A INPUT -m state --state NEW -m tcp -p tcp --dport 53 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 53 -j ACCEPT

# service iptables restart
# service named start
# netstat -tunlp

# dig @127.0.0.1 tw.yahoo.com
.
;; ANSWER SECTION:
.

# vi /etc/named.conf
.
listen-on port 53 { any; };   //原127.0.0.1
.
allow-query     { any; };   //原localhost
# service named restart
# dig @192.18.2.105 tw.yahoo.com

+++++++++++++++++++++++++++++++++++++++

# vi /etc/named.rfc1912.zones
//只要自己的正解即可
zone "502.kk" IN {
        type master;
        file "named.502.kk";
        allow-update { none; };

};

# vi /var/named/named.502.kk
$TTL 600
@ IN SOA dns.502.kk. guochin369@gmail.com. (0 3H 15M 1W 1D)
@ IN NS dns.502.kk.
dns IN A 192.168.2.105
www IN A 192.168.2.105

# service named restart


# ping www.502.kk
# dig @dns.502.kk tw.yahoo.com

+++++++++++++++++++++++++++++++++++++++

另一測試電腦IP:192.168.2.51 Win7 設定dns:192.168.2.105
cmd
c:\Users\User>ping 192.168.2.105
c:\Users\User>ping dns.502.kk
c:\Users\User>ping www.50.2kk
c:\Users\User>ping tw.yahoo.com

瀏覽器連結tw.yahoo.com

Server4_samba

# yum -y install samba
# useradd kk7 -s /sbin/nologin
# smbpasswd -a kk7
New SMB password:
Retype new SMB password:
Added user kk7.

# service smb start

ps:於win7內
        開始-->執行-->\\192.168.2.105

2015年1月26日 星期一

Server3_php_MySql

# yum -y install php
# rpm -qa | grep php
php-common-5.3.3-40.el6_6.i686
php-cli-5.3.3-40.el6_6.i686

php-5.3.3-40.el6_6.i686

# vi /etc/php.ini
.
register_globals = On
# service httpd restart

# vi /var/www/html/test.php

<?php
phpinfo();
php?>



+++++++++++++++++++++++++++++++++++++++++

# yum -y install mysql mysql-server
# rpm -qa | grep mysql
mysql-libs-5.1.73-3.el6_5.i686
mysql-5.1.73-3.el6_5.i686
mysql-server-5.1.73-3.el6_5.i686

# service mysqld start
# service mysqld status

# mysqladmin -u root password dd123   //設定root登入mysql密碼 

# mysql -u root -p   //帳號root登入mysql
Enter password:
mysql> show databases;
mysql> quit

# mysqladmin -u root -p password db123456   //變更root密碼

Enter password:   //原密碼  


~~~~~~~~~~~~變更MySQL預設編碼以免影響中文呈現
步驟1:
php程式中,資料開啟時加上
mysql_query("SET NAMES 'utf8'");

步驟2:似乎不需
# cp /etc/my.cnf /etc/my.cnf.bk

# cp /usr/share/doc/mysql-server-5.1.73/my-large.cnf /etc/my.cnf
# vi /etc/my.cnf
.
[client]
.
default-character-set=utf8
.
[mysqld]
.
default-character-set=utf8

init_connect='SET NAMES utf8'
.
# service mysqld restart
# mysql -u root -p
Enter password:
mysql> show variables like '%character%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~






+++++++++++++++++++++++++++++++++++++++++


# yum -y install php-mysql php-mbstring

# rpm -qa | grep php
php-common-5.3.3-40.el6_6.i686
php-mbstring-5.3.3-40.el6_6.i686
php-cli-5.3.3-40.el6_6.i686
php-mysql-5.3.3-40.el6_6.i686
php-5.3.3-40.el6_6.i686

php-pdo-5.3.3-40.el6_6.i686

 wget http://sourceforge.net/projects/phpmyadmin/files/phpMyAdmin/4.0.10.8/phpMyAdmin-4.0.10.8-all-languages.tar.gz
# tar -zxvf phpMyAdmin-4.0.10.8-all-languages.tar.gz
# cp -r phpMyAdmin-4.0.10.8-all-languages /var/www/html/phpMyAdmin   //-r複製目錄
# cd /var/www/html/phpMyAdmin/
# cp config.sample.inc.php config.inc.php

# vi config.inc.php

.
$cfg['Servers'][$i]['auth_type'] = 'http';   //原cookie改成http

# service mysqld restart
# service httpd restart

瀏覽器
http://192.168.2.105/phpMyAdmin
root
db123456
登入


++++++++++++++++++++++++++++++++++++++++++

phpMyAdmin
資料庫
建立資料庫:kkdb    編碼排序:utf8_unicode_ci  -->建立

建立資料表:tblmen   欄數:4   -->執行

mid varchar 10 utf8_unicode_ci  索引:primary
na varchar 20 utf8_unicode_ci
accnt varchar 10  utf8_unicode_ci
pwd varchar 10  utf8_unicode_ci

編碼與排序: utf8_unicode_ci   -->儲存



~~~~~~~~~~~~~由phpMyAdmin匯入文字資料
原始資料由EXCEL另存新檔-->存檔類型:文字檔(Tab字元分隔)-->按<是> -->再開啟所得文字檔,另存新檔-->存檔類型:UTF-8。
進入phpMyAdmin-->匯入-->選擇檔案-->首列跳過的列數:1(因EXCEL原始資料有標題列)-->格式:CSV-->格式選項:欄位分隔符號:\t (表示Tab字元分隔)-->執行。










2015年1月25日 星期日

Server2_http

# yum -y install httpd
# rpm -qa | grep httpd
httpd-tools-2.2.15-39.el6.centos.i686

httpd-2.2.15-39.el6.centos.i686

# vi /etc/sysconfig/iptable
.
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
# service iptables restart
# service httpd start

# ps aux | grep httpd   //或netstat -tunlp
# chkconfig httpd on   //即setup或ntsysv

# vi /etc/httpd/conf/httpd.conf

.
.
DirectoryIndex index.html index.html.var index.php
.
ServerName www.502.kk:80
.
KeepAlive On
#service httpd restart




++++++++++++++++++


# vi /etc/httpd/conf/httpd.conf

<IfModule mod_userdir.c>
.
# UserDir disabled
.
UserDir public_html


</IfModule>
.
.
Alias /webkk7 /home/kk7/public_html
.
# service httpd restart
# chmod 711 /home/kk7
# vi /home/kk7/index.html

瀏覽器:

http://192.168.2.105/~kk7

http://192.168.2.105/webkk7

(Alias /webkk7 /home/kk7/public_html)


+++++++++++++++++++++++++

# mkdir /webs
# chmod 711 /webs

# cd /webs
# vi index.html
.
this is from /webs


# vi /etc/httpd/conf/httpd.conf
.
Alias /w3 /webs
# service httpd restart

瀏覽器:

http://192.168.2.105/w3/

Server1_vsftp

#vi /etc/selinux/config
.
.
SELINUX=disabled   //預設enforcing,後重新開機


++++++++++++++++++++++++++++++++++

#rpm -qa | grep vsftpd
#yum -y install vsftpd
#service vsftpd start
#netstat -tunlp | grep vsftpd

# vi /etc/sysconfig/iptables
.
.
-A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT
# service iptables restart

# vi /etc/vsftpd/vsftpd.conf
.
.加入

pasv_enable=no

anonymous_enable=NO
chroot_local_user=YES

# service vsftpd restart
#yum -y remove vsftpd


++++++++++++++++++++++++++++++





使用者權限群組相關

#adduser kk1
#passwd kk1
New password:....
#su kk1
$logout   //登出回到root

+++++++++++++++++++++++++++++++++++++++

#groupadd sales   //新增群組sales

#cat /etc/group
#adduser -g sales kk2   //新增帳號kk2且加入sales群組
#passwd kk2
#cat /etc/passwd   //查看帳號資料   或   #id kk2

+++++++++++++++++++++++++++++++++++++++

#cp install.log install.log.kk
#ls -l install.log.kk
#chown kk2:sales install.log.kk   //變更檔案install.log.kk擁有者及群組
#ls -l install.log.kk


#chmod ugo+x install.log.kk   //檔案增加u,g,o 權限r,w,x(4,2,1)

# chmod -R +w /home/kk2   //資料夾變更權限


+++++++++++++++++++++++++++++++++++++++

#gzip install.log.kk   //壓縮為install.log.kk.gz

#gunzip install.log.kk.gz


#tar -cvf Myinstall.log.tar install.log.kk install.log.mm
//打包成Myinstall.log.tar
//-c產生新的包裹檔 -v看指令進度
//-f指定包裹檔名稱 -x將包裹檔解開
#tar -xvf Myinstall.log.tar


#tar -czvf Myinstall.log.tar.gz install.log.kk install.log.mm
//先打包再壓縮 *.tar + *.gz =*.tar.gz
#tar -xzvf  Myinstall.log.tar.gz   //先解壓縮再解開包裹檔






2015年1月16日 星期五

常用指令

#date 080414302014  //設定系統時間 2014/8/4  14:30 

# du -sh /home  //目錄空間使用量  s:不顯示子目錄,全部加總
                                                          h:以磁碟單位顯示用量
# df -h              //掛載分割區資訊


+++++++++++++++++++++++++++++++++


#yum -y update

# vi /etc/crontab
.
.
0 5 * * * root /user/bin/yum -y update
//minute hour day month day of week 
//每天早上5時自動更新
//#which yum 查詢令位置


+++++++++++++++++++++++++++++++++


# cat /etc/passwd   //帳號相關
# cat /etc/shadow   //密碼相關
# cat /etc/group  //群組名稱

+++++++++++++++++++++++++++++++++


# ps aux | grep vsftpd
# kill 2845   //當時的pid
# netstat -tunlp   //-t:只列tcp -u:只列udp
                             -n:埠號顯示 -l:只列正在傾聽
                             -p:行程編號

+++++++++++++++++++++++++++++++++


#wget ftp://.../vsftpd-2...rpm

#rpm -ivh vsftpd-2...rpm   //-i:安裝 -h:顯示進度列###
#rpm -Uvh vsftpd-2...rpm   //更新套件
#rpm -e vsftpd-2...rpm   //移除 erase

+++++++++++++++++++++++++++++++++


# more /root/install.log   //空白鍵 下ㄧ頁 q:離開

# less /root/install.log   //PageUp + PageDown q:離開
                                        :20移動到20行
                                        /可搜尋文字
# tail -n 3 -f /root/install.log   //-n 3 顯示檔尾3行
                                                  -f 持續監看  Ctrl+C 中斷

# touch /root/install.log   //1.可新增空白檔案 

                                           2.改變檔案更動時間

# cat -n /root/install.log   //-n行號檢視


+++++++++++++++++++++++++++++++++


# ls -l /usr/lib | more   //ls輸出結果 接至 more輸入來源

                                      | 管線

# df > mydf   //將df結果產生檔案mydf若mydf存在則覆蓋

# cat mydf


# echo "data1" > myfile   //檔案不存在則產生檔案

# cat myfile
# echo "data2" > myfile   //覆蓋
# cat myfile
# echo "data3" >> myfile   //新資料加至原檔尾端

# cat myfile


+++++++++++++++++++++++++++++++++

# mkdir dvdrom
# mount -t iso9660 /dev/cdrom dvdrom   //VirtualMachine要設定好CD/DVD-->Connection-->Use physical drive:實際光碟位置
# ls dvdrom
# umount dvdrom

+++++++++++++++++++++++++++++++++

#mkdir usb
#mount -t vfat /dev/sdb usb   //需為FAT32,NTFS不支援
#ls usb
#umount usb

++++++++++++++++++++++++++++++++
# route -n > RouteTable.txt
# cat RouteTable.txt
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.2.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0

0.0.0.0         192.168.2.1     0.0.0.0         UG    0      0        0 eth0



網路設定

#setup
設定Network configuration  -->  Device configuration  -->  eth0

# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=00:0c:29:d7:4c:b2
TYPE=Ethernet
UUID=eca79f97-5737-4fa7-8a47-b7407cfccfbd
ONBOOT=yes                                                       //設定此項後 network restart 網路即啟動
NM_CONTROLLED=yes
BOOTPROTO=none
IPADDR=192.168.2.105
NETMASK=255.255.255.0
GATEWAY=192.168.2.1
DNS1=163.28.136.14
IPV6INIT=no
USERCTL=no

#service network restart
#ifconfig
後即以pietty連線操作即可



# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.2.105 centos.502.kk   //設定電腦名稱
以上設定需與
#cat /etc/sysconfig/network  //設定HostName
#cat /etc/resolv.conf   //設定DNS

#setup  //若以pietty 連線 需將  選項  -->  亞洲語系修正  -->  Unicode亞洲寬符號字元  取消,才能正常顯示畫面
網路設定 -->  DNS組態設定

#ping centos.502.kk



-----------------------------------------------------------
關閉root使用ssh

# vi /etc/ssh/sshd_config
.
#PermitRootLogin yes改為
PermitRootLogin no
.
# systemctl restart sshd

$ su root    //以chinku帳號登入後再取得root權限