Archive for the ‘Ubuntu’ category

Install samba server on Ubuntu 16.04

October 11th, 2017

Check this tutorial on Ubuntu official site: https://help.ubuntu.com/lts/serverguide/samba-fileserver.html; and its next page about security as well: https://help.ubuntu.com/lts/serverguide/samba-fileprint-security.html.

Howerver while setting up the share dir, I suggest you do not follow the tutorial to set owner as nobody:nogroup, bucause this may make this dir not writable for other users. Instead, you can create a new user and group: ttgshare:ttgshare, and assign the write privilege to the group ttgshare by adding this line to /etc/samba/smb.conf:
write list = @ttgshare

Ant build script for java web project with tomcat on ubuntu

December 7th, 2013

Here is a sample ant build script for java web project with tomcat on ubuntu. It should be put under the root directory of the web project.



<?xml version="1.0" encoding="UTF-8"?>
<project name="ProjectName" default="war" basedir=".">
	<property environment="env" />
	<property name="webapp.name" value="ProjectName" />
	<property name="webapp.dir" value="/data/public/JavaWebapps" />
	<property name="tomcat.lib" value="/usr/share/tomcat7/lib" />
	<property name="ant.lib" value="/usr/share/ant/lib" />
	
	<property name="dist.dir" value="${basedir}/war" />
	<property name="webRoot.dir" value="${basedir}/WebContent" />
	<property name="src.dir" value="${basedir}/src" />
	<property name="config.dir" value="${basedir}/resources" />
	<property name="lib.dir" value="${webRoot.dir}/WEB-INF/lib" />
	<property name="build.dir" value="${basedir}/build" />
	
	<!-- Init classpath -->
	<path id="project.classpath">
		<fileset dir="${lib.dir}">
			<include name="**/*.jar" />
		</fileset>
		<fileset dir="${tomcat.lib}">
			<include name="*.jar" />
		</fileset>
		<!-- ant lib  -->
		<fileset dir="${ant.lib}">
			<include name="*.jar" />
		</fileset>
	</path>

	<!-- get the source compile classpath in a printable form -->
	<pathconvert pathsep="${line.separator}|   |-- "
             property="echo.path.compile"
             refid="project.classpath">
	</pathconvert>
	
	<!-- show classpath jars -->
	<target name="print_classpath">
		<echo message="|-- compile classpath"/>
		<echo message="|   |"/>
		<echo message="|   |-- ${echo.path.compile}"/>
	</target>
	
	<target name="clear" description="Clear the project">
		<delete dir="${build.dir}" />
		<delete dir="${dist.dir}" />
		<delete file="${webapp.name}/${webapp.name}.war" />
		<delete dir="${webapp.name}/${webapp.name}" />
	</target>

	<target name="init" depends="clear" description="Init the directories">
		<mkdir dir="${build.dir}/classes" />
		<mkdir dir="${dist.dir}" />
	</target>

	<target name="compile" depends="init" description="Compile source files">
		<echo message="begin compile..." />
		<javac srcdir="${src.dir}" destdir="${build.dir}/classes" 
			includeantruntime="false" nowarn="on" 
			target="1.7" deprecation="true" debug="true" 
			encoding="UTF-8" classpathref="project.classpath" 
			>
			<compilerarg line="-Xlint:unchecked" />
			<!-- <classpath refid="project.classpath" /> -->
		</javac>
		<copy todir="${build.dir}">
			<fileset dir="${src.dir}">
				<include name="**/*.xml" />
				<include name="**/*.properties" />
				<include name="**/*.sql" />
			</fileset>
			<fileset dir="${config.dir}">
				<include name="**/*.xml" />
				<include name="**/*.properties" />
				<include name="**/*.sql" />
			</fileset>
		</copy>
		<echo message="end compile..." />
	</target>

	<!--  
	    <target name="pack" depends="compile"> 
	        <jar jarfile="${build.dir}/${webapp.name}.jar"> 
	            <fileset dir="${build.dir}/classes"> 
	                <include name="**/*.class"/> 
	            </fileset> 
	        </jar> 
	    </target> 
	-->

	<target name="war" depends="compile" description="Package the project as .war file.">
		<echo message="begin packing war..." />
		<war destfile="${dist.dir}/${webapp.name}.war" basedir="${webRoot.dir}" 
			webxml="${webRoot.dir}/WEB-INF/web.xml">
			<lib dir="${lib.dir}" />
			<classes dir="${build.dir}/classes" />
			<fileset dir="${webRoot.dir}">
				<include name="***.*" />
			</fileset>
		</war>
		<echo message="end war..." />
	</target>

	<target name="deploy" depends="war" description="Deploy the war to tomcat">
		<echo message="begin deploy..." />
		<copy file="${dist.dir}/${webapp.name}.war" todir="${webapp.dir}" />
		<echo message="end deploy..." />
	</target>

</project>

Configure Tomcat 7 & Eclipse on Ubuntu

June 28th, 2013

Install Eclispe

Either via sudo apt-get install eclipse and then install Web Tools Platform for JavaEE, or download Eclipse for JavaEE.

Install tomcat

We can also install tomcat in 2 ways:
1. sudo apt-get tomcat7
2. download tomcat7 and extract it into folder, such as ~/Prog/tomcat

Integrate Eclipse and Tomcat

When I run the project with “Run On Server” and follow the instruction of “Define a new server” with tomcat v7, I always get this error message: “Cannot create a server using the selected type”. Well, here is the solution: http://oramirez.wordpress.com/2012/02/03/eclipse-with-tomcat-v7-0-in-ubuntu-11-10/.

And then somehow I encounter this error: Could not load the Tomcat server configuration at /Servers/Tomcat v7.0 Server at localhost-config. The configuration may be corrupt or incomplete., and http://www.jusuchyne.com/codingchyne/2010/10/installing-tomcat-7-on-ubuntu/ tells that it’s because eclipse failed to copy the conf files into eclipse tomcat conf. so:
1. first sudo chmod -R 777 ~/Prog/tomcat7/conf;
2. and delete the server in Eclipse Perferences -> Server -> Runtime Environment, re-add it;
3. and then re-define the server at “Run on Server”.

install igraph (C) on Linux(ubuntu) and use it in Eclipse

November 30th, 2011

Build and install igraph.

      download the source code package;
      unpack it into a directory, eg. igraph-0.5.4 (I’ll use IGRAPH_DIR instead below)
      enter the directory: user> cd IGRAPH_DIR
          user> make
          user> sudo make install This will install the igraph libary files into /usr/local/lib

Add igraph libraries to the shared libraries search path

If you haven’t include /usr/local/lib into your shared libraries search path as defined in /etc/ld.so.conf, add it. Otherwise, you will see an error like this: error while loading shared libraries: libigraph.so.0: cannot open shared object file: No such file or directory.

And DON’T forget to reload the config:user> sudo ldconfig

Use igraph in Eclipse

      Go to Project -> Properties-> C/C++ Build -> Settings
      Go to GCC C++ Compiler -> Directories, add /usr/loccal/include/igraph.
      Go to GCC C++ Linker -> Libraries, add “igraph” to Libraries (-l) and add “/usr/loca/lib” to Library search path (-L).

move Mysql’s datadir on ubuntu

March 8th, 2011

Mysql’s datadir (on ubuntu) by default is /var/lib/mysql. Sometimes, if your DB grows bigger and bigger, and finally exceeds the limit of /var partition, you may think of moving it to some other place. Here are the steps.

  1. stop the server
    sudo service mysql stop

    or

    sudo /etc/init.d/mysql stop
  2. copy data to the new folder
    For example, you want to set the new folder in /home2/: 

    sudo cp /var/lib/mysql /home2/

    Now /home2/mysql is the new datadir. Of course, you can change it to whatever name you want.

    Here I deleted the log file ib_logfile* by:

    sudo rm /home2/mysql/ib_logfile0

    Maybe you also want to change the original datadir to some other name to make sure it won’t be in effect any more.

    sudo mv /var/lib/mysql /var/lib/mysql.bak
  3. change the permission of the new directory
    Make sure the owner of /home2/mysql and all its subdirectories is mysql:mysql. When necessary, use chown to change the permission:sudo chown -R mysql:mysql /home2/mysql 

    Also make sure the permissions of the new datadir and its subdiretories are the same as those under /var/lib/mysql. In my experiment, the permission of table files in each database was changed to 400 when copying, so I had to use chmod to correct them:

    sudo chown -R me:me /home2/mysql;
    sudo chmod 660 /home2/mysql/*/*;
    sudo chown -R mysql:mysql /home2/mysql

    The reason why I changed the owner to me (my username on my computer) at the beginning and change it back to mysql at last is so that I can use the wildcast * to change all files’ permission at once.

  4. modify my.cnf and point datadir to the new directory
  5. sudo vi /etc/mysql/my.cnf

    Find datadir and change it to:

    datadir=/home2/mysql

    It seems in Mysql 4 you also need to change the basedir and socket accordingly, but I’m not sure.

  6. add the new diretory into the AppArmor configure file
  7. This part is special on some Linux distributions like Ubuntu >= 7.04. AppArmor is a Linux Security Module implementation of name-based access controls. It confines individual programs to a set of listed files and posix 1003.1e draft capabilities.

    You can use

    sudo aa-status

    to check whether mysql is confined by AppArmor. If so, use

    sudo vi /etc/apparmor.d/usr.sbin.mysqld

    to add the new datadir at the end of the file.

  8. restart apparmor service
    sudo /etc/init.d/apparmor reload
  9. start mysql server
    sudo service mysql start

    or

    sudo /etc/init.d/mysql start

    Refer to /var/log/mysql/error.log to see if there are any errors.

  10. do some tests.
    List all the database, select some records from a table, create a new table and see whether it’s in the new datadir, insert some records, delete them, and whatever.
    WARNING: you may need to run Mysql with the new datadir for a few days before deleting the old datadir.

export mysql data to a custom directory on ubuntu linux

March 8th, 2011

On ubuntu,  mysql is confined with AppArmor to certian directories. Thus when you try to export data into a directory other than /tmp, you’ll get a Errcode 13. So if you really want to export db data inoto a custom dictory, you need to add it to the AppMrmor configure file.

First, check whether mysql is restricted to certain dirs:

sudo aa-status

If you see mysqld listed, then add the custom dirs at the end of the configure file:

sudo vi /etc/apparmor.d/usr.sbin.mysqld

Finally, reload the service:

sudo /etc/init.d/apparmor reload

Enable USB support in Virtualbox

January 14th, 2011

OK, I only tried a Windows XP client on the Ubuntu 10.10 host. here I’m not sure it will work on other hosts or clients. :-)

I was using Virtualbox OSE which I installed through Ubuntu repository. However, only Virtualbox PUEL supports USB.

So this is what I did:

First, uninstall virtualbox-ose:
sudo apt-get remove virtualbox-ose
. also run
sudo apt-get autoremove
to remove unnecessary dependencies.

Now install virtualbox PUEL version. There are 2 ways:

  • Download .deb package and install it directly. Here is the download page: http://www.virtualbox.org/wiki/Linux_Downloads
  • Add http://download.virtualbox.org/ to your repository source list, and install it via
    sudo apt-get install
    . The source url for ubuntu 10.10 isdeb http://download.virtualbox.org/virtualbox/debian maverick contrib, add the public key via
    wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | sudo apt-key add -
    , and install it by
    sudo apt-get update;
    sudo apt-get install virtualbox-4.0

    . The lastest info can be found here: http://www.virtualbox.org/wiki/Linux_Downloads

NOTE: uninstalling virtualbox-ose and reinstalling virtualbox PUEL won’t affect the installed guest machines.

Install VirtualBox Extension Pack to suport USB 2.0. The lastest version is still listed in the download page: http://www.virtualbox.org/wiki/Downloads. Here is the directly link for VirtualBox 4.0.0: http://download.virtualbox.org/virtualbox/4.0.0/Oracle_VM_VirtualBox_Extension_Pack-4.0.0-69151.vbox-extpack

Update guest additions. You can download the guest additions ISO file here: http://download.virtualbox.org/virtualbox/. Remember to choose the right version, here I chose 4.0.0.

Now, plugin your usb device, and add a usb filter in your guest machine’s settings. Remember, you have to all these before you turn on your guest machine machine. Maybe you think now everything is done, you boot your guest machine and it will tell you a new device is found. No way!

Refer to http://ubuntuforums.org/showthread.php?p=2202027#18 for the coming steps.

Create a group “usbfs”
sudo addgroup usbfs
, and add yourself to this group:
sudo usermod -aG usbfs <your accout>

Add this line
none /proc/bus/usb usbfs devgid=1001,devmode=664 0 0
(remember to change the “1001″ to your own group id for “usbfs”!) to the end of the file “/etc/fstab”.

Reboot the host machine (here is ubuntu).

In the reference, it says: *USB DEVICES HAVE TO BE UNMOUNTED BEFORE VIRTUAL MACHINE CAN RECOGNIZE THEM*. However, I didn’t do this and it also worked. So I think with version 4.0.0, it’s not necessary.

Now start the guest machine (here is Winsows XP), it should report new USB devices found.

use “checkInstall” instead of “make install”

July 22nd, 2010

as said:

CheckInstall keeps track of all files installed by a “make install” or equivalent, creates a Slackware, RPM, or Debian package with those files, and adds it to the installed packages database, allowing for easy package removal or distribution.

detail: https://help.ubuntu.com/community/CheckInstall

install sopcast player in Ubuntu 10.04(Lucid Lynx) AMD64

June 12th, 2010

If you are installing sopcast player on a X86 machine, you can read this article:

http://www.ubuntugeek.com/how-to-install-sopcast-player-in-ubuntu-9-10karmic.html.

But if you want to install sopcast on a AMD64 machine, you need to manually install sp-auth as said in here:

http://tinformix.blogspot.com/2009/05/how-to-sopcast-on-gentoo-amd64.html.

In summary (for AMD64):

  • add the sopcast player PPA:
    sudo add-apt-repository ppa:jason-scheunemann/ppa
  • update the source list:
    sudo apt-get update
  • install sp-auth:
    wget http://download.easetuner.com/download/sp-auth.tgz
    tar xzf sp-auth.tgz
    sudo mv sp-auth /usr/local/share
    sudo ln -s /usr/local/share/sp-auth/sp-sc-auth /usr/local/bin/sp-sc
  • install spcast-player:
    sudo apt-get install sopcast-player

setting virtualbox networking to allow host & guests communicate

May 21st, 2010

If you use the default  NAT for as your guest machine’s network adaptor, you can access your host from the guests but can’t access the guests from your host. But in the latest version of VirtualBox, it’s very easy to set the networking so that both host and guests can access each other. You only need to set your network adaptor as “bridge” as shown below:

virtualbox-network-bridge