วันพฤหัสบดีที่ 20 สิงหาคม พ.ศ. 2558

การติดตั้ง Tomcat บน CentOS 6.5

การติดตั้ง Tomcat บน CentOS 6.5 สามารถใช้วิธีด้วยใช้การติดตั้งแบบ Group install ดังนี้
1. ก่อนอื่นให้ทำงานติดตั้งแพ็กเกจ JAVA ก่อน
yum groupinstall 'Java Platform' -y
2. ติดตั้งแพ็กเกจรวมของ tomcat
yum groupinstall 'Web Servlet Engine' -y
แพ็กเกจที่ถูกติดตั้งมีดังนี้

แนวทางแก้ไข กรณี bad interpreter: No such file or directory

# sed -i 's/\r//' filename

Set Bonding NIC on CentOS

1. #ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no
ETHTOOL_OPTS="autoneg off speed 1000 duplex full"

change ssh port

; ระบุ port ในค่า xxxxx เช่น "port 12345"
# nano /etc/ssh/sshd_config
  Port xxxxx

# nano /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport xxxxx -j ACCEPT

# service iptables stop
# service ip6tables stop

Change nano(text editor) to default


# yum install nano -y
# export EDITOR=nano

Install Vsftpd On CentOS

Install Vsftpd to configure FTP server to transfer files.

# yum install vsftpd ftp -y
# nano /etc/vsftpd/vsftpd.conf

วันพุธที่ 19 สิงหาคม พ.ศ. 2558

Install JAVA On CentOS (เก็บไว้ดู ครับ)

1. Install
# cd /opt
# wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/7u72-b14/jdk-7u72-linux-x64.tar.gz"
# tar xzf jdk-7u72-linux-x64.tar.gz
# cd /opt/jdk1.7.0_72/
# alternatives --install /usr/bin/java java /opt/jdk1.7.0_72/bin/java 2
# alternatives --config java

Install Postgresql with yum on CentOS

Download the latest production release for your distro here: http://yum.pgrpms.org/repopackages.php

The repo rpms are 32 and 64 bit specific.

I am installing on CentOS 6 x64, I will need:
# wget http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-centos93-9.3-1.noarch.rpm
or
# wget http://yum.pgrpms.org/9.1/redhat/rhel-6-x86_64/pgdg-centos91-9.1-4.noarch.rpm
or
# wget http://yum.pgrpms.org/8.4/redhat/rhel-6-x86_64/pgdg-centos-8.4-3.noarch.rpm

# rpm -i pgdg-centos91-9.1-4.noarch.rpm 
# cd /etc/yum.repos.d 
# nano CentOS-Base.repo 
----------------------
[base] 
name=CentOS-$releasever - Base 
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os 
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/ 
gpgcheck=1 
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 
exclude=postgresql* 

#released updates 
[updates] 
name=CentOS-$releasever - Updates 
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates 
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/ 
gpgcheck=1 
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 
exclude=postgresql* 
------------------------------
# yum list postgres*
# yum install postgresql93 postgresql93-devel postgresql93-server postgresql93-libs postgresql93-contrib
# service postgresql-9.3 initdb
# service postgresql-9.3 start

4. Set PostgreSQL 9 Environment
# nano /var/lib/pgsql/bash_profile
------------------------------------
[ -f /etc/profile ] && source /etc/profile 
PGDATA=/var/lib/pgsql/9.1/data 
export PGDATA 
PATH=$PATH:$HOME/bin:/usr/pgsql-9.1/bin 
export PATH
------------------------------------

5. Set postgres Password
# su - postgres
-bash-4.1$ psql template1
postgres=# alter user postgres with password 'grespost';

6. Configure PostgreSQL 9 pg_hba.conf File
# nano /var/lib/pgsql/9.1/data/pg_hba.conf

7. Configure PostgreSQL 9 postgresql.conf File
# nano /var/lib/pgsql/9.1/data/ postgresql.conf.conf

Set UTF-8 ฐานข้อมูล MySQL CentOS ( my.cnf )

To set the default to UTF-8,
แก้ไขไฟล์  my.cnf
ใน /etc/my.cnf
----------------------
[client]
default-character-set=utf8

[mysql]
default-character-set=utf8


[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
------------------------------

ลืม Password MySQL ทำไงดี ( Lost MySQL Admin Password )

###### On Linux
Lost MySQL Admin Password
1.  First, stop current MySQL database server:
  #  /etc/init.d/mysqld stop

2. Now, start mysql server without password so that you can restart the password:
 #  mysqld_safe --skip-grant-tables &

3. Login without a password, enter:
#  mysql -u root

4. Finally, setup a new MySQL root user password, enter::
   mysql>  USE mysql;
   mysql>  UPDATE user SET password=PASSWORD('NEW-ROOT-PASSWORD') WHERE User='root';
   mysql>  FLUSH privileges;
   mysql>  quit
 # Replace NEW-ROOT-PASSWORD with actual password you want to use.
5. Restart running mysql server
  # /etc/init.d/mysqld restart
6. test to connect.
 # mysql -u root -p



#### กรณี On Windows

1.stop mysql ไปที่ contol panel > service >mysql กด stop
2.ไปที่ run พิมพ์ cmd >กด enter
3.พิมพ์ cd\
4.พิมพ์ cd appserv\mysql\bin กด enter
หมายเหตุ ที่เก็บ mysql จะแตกต่างกันแล้วแต่ว่าท่านเลือกใช้ web server ตัวใด
5.พิมพ์ mysqld-nt -u root --skip-grant-tables กด enter

ให้เปิดหน้าต่าง command อีกหน้าต่าง หน้าต่างเดิมไม่ต้องปิด โดย

ไปที่ run พิมพ์ cmd >กด enter
1.พิมพ์ cd\
2.พิมพ์ cd appserv\mysql\bin กด enter
หมายเหตุ ที่เก็บ mysql จะแตกต่างกันแล้วแต่ว่าท่านเลือกใช้ web server ตัวใด
3.พิมพ์ mysql กด enter
4.พิมพ์ use mysql
5.พิมพ์ UPDATE user SET Password = PASSWORD('NEW_PASSWORD') WHERE User = 'root'; กด enter

แก้ปัญหา MySQL ERROR 1045 (28000)

วิธีแก้ไข
1.Restart MySQL
2.ไปที่ Path ที่ลง MySQL ไว้หาไฟล์ชื่อ  my.ini  เปิดไฟลล์ด้วย notepad++   หาคำว่า [mysqld]  
แล้วทำการ enter พิมพ์คำว่า skip-grant-tables ลงไป
3.run MySQL อีกครั้ง
4.เปิด Navicat เลือก database ชื่อ mysql  ตาราง user  ให้ลบ password ของ user   root ออกไปให้เป็นค่าว่าง
5.stop MySQL ไปที่ Path ที่ลง MySQL ไว้หาไฟล์ชื่อ  my.ini แล้วลบคำว่า skip-grant-tables ที่เราเพิ่มออกไป
6.run MySQL อีกครั้ง เสร็จเรียบร้อยครับ