Cài đặt JDK 1.6 update 10 trên FreeBSD 7
Ports mặc định của FreeBSD 7 chỉ là JDK 1.6 update 3 do đó để cài đặt JDK 1.6 update 10 trước tiên cần phải cập nhật port linux-sun-jdk16 từ FreeBSD.
(Xem tiếp)
Ra mắt diễn đàn chính thức dành cho cộng đồng FreeBSD
Cuối cùng thì FreeBSD Foundation cũng cho ra mắt diễn đàn chính thức dành cho cộng đồng người dùng FreeBSD tại địa chỉ http://forums.freebsd.org.
Linux + FreeBSD mini Howto
http://www.faqs.org/docs/Linux-mini/Linux+FreeBSD.html
Làm thế nào để đọc dữ liệu từ một ổ cứng Linux trên FreeBSD?
Mặc định thì Linux không hiểu cấu trúc file của FreeBSD và ngược lại. Do đó, khi bạn gắn một ổ cứng đang chạy Linux vào một máy đang chạy FreeBSD thì bạn sẽ không thể nào mount được.
(Xem tiếp)
Theo dõi các user đã làm gì trên shell
Đôi khi có nhiều user xóa history của họ trước khi logout, hoặc chuyển output của shell log ra /dev/null, hoặc xóa luôn file /var/log/wtmp,... làm người quản trị hệ thống không thể biết họ làm gì trên server. Khi đó thì chỉ có nước pó tay thôi chứ đâu còn cách nào khác. Chỉ có thể đề phòng từ trước thôi.
(Xem tiếp)
Kích hoạt Accounting
Thêm dòng accounting_enable="YES" vào tập tin /etc/rc.conf để chạy khi server khởi động. Sau đó chạy:
#/etc/rc.d/accounting start
(Xem tiếp)
Xử lý mail queue của Sendmail
Xem mail queue: #mailq hoặc #sendmail -bp
(Xem tiếp)
Đếm IP truy cập
Đoạn code sau sẽ in ra danh sách 10 IP truy cập nhiều nhất vào server dựa vào Apache log:
(Xem tiếp)
Makefile cho ZendOptimizer hỗ trợ FreeBSD 7
Hiện tại đến thời điểm này thì ZendOptimizer chưa chính thức hỗ trợ FreeBSD 7. Tuy nhiên có thể download Makefile này về rồi chép đè vào thư mục ZendOptimizer trong ports sau đó make thì sẽ ok.
(Xem tiếp)
/etc/my.cnf
[mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock skip-locking #skip-networking safe-show-database query_cache_limit=1M query_cache_size=64M ## 32MB for every 1GB of RAM query_cache_type=1 max_user_connections=200 max_connections=500 interactive_timeout=10 wait_timeout=20 connect_timeout=20 thread_cache_size=128 key_buffer=128M ## 64MB for every 1GB of RAM join_buffer=1M max_connect_errors=20 max_allowed_packet=16M table_cache=1024 record_buffer=1M sort_buffer_size=2M ## 1MB for every 1GB of RAM read_buffer_size=2M ## 1MB for every 1GB of RAM read_rnd_buffer_size=2M ## 1MB for every 1GB of RAM thread_concurrency=2 ## Number of CPUs x 2 myisam_sort_buffer_size=64M server-id=1 log_slow_queries=/var/log/mysql-slow-queries.log long_query_time=2 collation-server=latin1_general_ci old-passwords [mysql.server] user=mysql basedir=/var/lib [safe_mysqld] err-log=/var/log/mysqld.log pid-file=/var/lib/mysql/mysql.pid open_files_limit=8192 [mysqldump] quick max_allowed_packet=16M [mysql] no-auto-rehash #safe-updates [isamchk] key_buffer=32M sort_buffer=32M read_buffer=16M write_buffer=16M [myisamchk] key_buffer=32M sort_buffer=32M read_buffer=16M write_buffer=16M [mysqlhotcopy] interactive-timeout
Wael __________________
Đổi tên files hàng loạt
Đổi tên file hàng loạt:
Ví dụ, muốn đổi tất cả tập tin dạng IMG_00123.jpg thành IMG_000123.jpg ta dùng lệnh:
#rename IMG_ IMG_0 IMG_?????.jpg
FreeBSD 7, Apache 2, PHP 5, Mysql 5 optimize
About configuration
This post was redacted with at least this configuration in mind:
- Apache 2.2.3
- PHP 5.1.6
- MySQL 5.0.24
- FreeBSD 6.1-STABLE
Of course, it may be usable for other configurations, or give elements to think about.
MySQL performances
Under FreeBSD and not under GNU/Linux, performances drop down where there are too many simultaneous connections. With my 1.8 GHz Celeron and 1.2 MB RAM, I can't go over 30 simultaneous connections without blocking the computer.
This issue seems to be fixed with FreeBSD 7.0, but it may be possible to attenuate it with previous versions.
Here are some ideas:
- Build MySQL with Linux threads. You have to use "WITH_LINUXTHREADS=yes" parameter while building it (the way to use it may vary depending your installation procedure: portupgrade, make install within ports' tree or source install).
- Build MySQL with "BUILD_OPTIMIZED=yes" parameter. This parameter passes more optimized parameters to compiler in order to get better binaries. It's hard to know how much performances are improved, but it can't do any harm.
- Build MySQL with "BUILD_STATIC=yes" parameter. This parameter allows MySQL to be compiled with static links to external libraries. Each time this call to these libraries will be made, it won't be needed to search for this library as the link is hard-coded into executable binary. But if one day you update these libraries, you may break these static links, then need to build MySQL again.
- Start MySQL without DNS resolution. Each time a client connects to MySQL daemon, it solve client's IP address to hostname. With many simultaneous connections, MySQL must wait for name server answer before execute the query, answer which may be slow to come depending on network or system usage. If you want to disable this reverse DNS resolution, you have to add parameter "--skip-name-resolve" when starting MySQL. Under FreeBSD, just add into file "/etc/rc.conf" the line "mysql_args="--skip-name-resolve"" then restart MySQL.
- Setup MySQL memory usage. A database manager need as many RAM as possible: bigger is the cache, quicker are queries execution (it's quicker to access to previous results into RAM than take them from hard disk). But allocate to many memory to MySQL will penalize other system processes. You must find yourself the good values. There are into "/usr/local/share/mysql/" folder many ".cnf" with are many usecase MySQL configuration files. You just have to choose the right file, copy it to "/etc/my.cnf", and adapt it to your needs. Then restart MySQL.
- Allocate more memory to temporary tables buffer ("tmp_table_size" parameter into "/etc/my.cnf" file). This buffer is used to store temporary tables created while executing some queries. If this parameter is set to low, MySQL will use the harddrive, slower than system memory. Default value is set to 32 MB.
MPM and PHP
Since version 2, Apache support many distinct MPM. The most often used are the following ones:
- prefork: each time a client connects, a new process is created from the father's one. This new process will load all apache modules into memory. It's the old school way used with Apache 1.3.
- worker: each time a client connects, a new thread is created from father's process. This way is less slower than the previous one, because it's not necessary to create a new process with all related Apache modules. As modules are shared between all threads from the same father process, memory usage will be less important.
If you read the previous list, you will want to use worker MPM: less slower, better memory usage, why hesitate ? the problem is that PHP only support prefork MPM, and nothing is guaranteed with worker MPM. It's may work, but it may not. In my case, it perfectly worked with PHP 5.0.x, but didn't worked with PHP 5.1.x. Related symptoms were session lost or blank pages.
Then if you don't want to prematurely loose your hairs, only use prefork MPM. So you may want to stay with Apache 1.3, and you're right. But remember, one day, this version will be obsolete and not supported anymore, and sooner than version 2.0.
PHP and MySQL
You have to ways to connect to a MySQL database: persistent connections, and non persistent connections. A persistent connection is a connection which will stay open until it's explicitly closed (with the related function or when the script ends). If may be useful if you don't want to lose time waiting to open connection again when you need it, but if you have too many simultaneous connexions the MyQSL service may be overloaded.
A non persistent connection is a connection which is open and close each time a query is sent to MySQL. Connection open and close functions are only here to create the variable used to manage the connexion. Unlike persistent connection, you have a slight overhead due to connection opening and closing, but it may be unnoticeable (unless your scripts need to often execute queries). In non persistent connection case, the server will be less often overloaded while getting many simultaneous connections.
In order to disable persistent connections with PHP, you have to set the parameter "mysql.allow_persistent" to "Off" into "/usr/local/etc/php.ini" file.
PHP and memory usage
It may be evident to you, but PHP is memory hungry. After a few quick tries, an Apache process use 7 MB without PHP, and 20 MB with PHP. And don't forget: more you have connections, more you have open Apache processes. With 20 MB per processes, memory usage will grow quickly.
In order to avoid important memory usage, only install PHP modules you need. And if you have problems with a module, you will loose less time to find which one is guilty with few modules than with many. When I write about problems with a module, I mean this: I open a page with use no function from this module, but Apache crashes with an error code 11. If you want to find the guilty module, disable all modules one by one, then restart Apache and reload the page until Apache doesn't crash anymore.
PHP and performances.
PHP is an interpreted language. This means each time a PHP script is opened and executed, PHP engine will need to check the syntax, compile it to a semi-native language ( called "bytecode"), then execute it. For only one PHP script, this syntax check then compilation dedicated time is invisible to the user. But when the web server has to treat hundreds of PHP script within a second, this overhead may be too important.
If you want to accelerate things, there are tools called "PHP accelerators" which optimize PHP scripts loading. When a PHP script is open for the first time, the syntax is checked, it's compiled to bytecode in an optimized may, and this bytecode is saved then executed. Then, each time this script is asked for, PHP engine will use the previously generated bytecode. This time gain may be appreciable.
There are many PHP accelerator. The most known are:
- ZendOptimizer. It's a closed source accelerator, made by Zend, the company behind the Zend Engine (the engine used by PHP).
- eAccelerator. It's a free PHP accelerator, and it's performances are closed to ZendAccelerator's ones.
I first tried eAccelerator, but had some issues with: cache was not updated, some session loose, etc. With ZendOptimizer, I still have these issues, but less often. Then I don't use any of them.
If you want to use a PHP accelerator, you can accelerate ZendOptimizer if you don't use files protected by ZendGuard. You just have to add into "/usr/local/etc/php.ini" file, within ZendOptimizer section, the following lines:
zend_optimizer.enable_loader=0
zend_optimizer.disable_licensing=0
Apache and AcceptFilter
AcceptFilter is a feature based on kernel options used to optimize HTTP connections (see "accf_http" kernel module for FreeBSD). Said like that, it looks good. But I'm really not convinced: processes memory usage grow (45 MB memory usage per process), processes are opened but never closed (which does not help with memory usage). The only good thing is, when system was not overloaded, that connections seemed to answer quicker. Then disable AcceptFilter. With FreeBSD, it's easy: just add a line
apache22_http_accept_enable="NO"
into "/etc/rc.conf" ("apache22" may change depending the version you use).
Apache and connections limitation.
I just come back to memory use with some trick to avoid server overload:
- Add RAM, many RAM. Remember Apache won't be the only running process on your computer, and if you use a database manager, it will be happy with many memory for its buffers. In my case, the server has 1.2 GB of system memory, and MySQL is set to use 512 MB of RAM. To these 1.2 GB of RAM, I added 512 MB of swap.
- Think about Apache maximum connections limits. It's useless to let to many clients to simultaneously connect if your server can't handle them. Think about to a maximum of 200 MB swap usage to avoid system overload when it will begin to swap. In my case, I use the following parameterd:
- 512 MB of RAM for Apache processes (1.2 GB - 512 MB for MySQL - 176 MB for other processes). I had 200 MB of swap memory. Apache will be able to access to 712 MB of memory.
- 30 MB per Apache process: 712 / 30 = 24 simultaneous connections. Then I set Apache not to use more than 25 running processes.
Conclusion
I hope these tricks will be useful to you. There are not perfect one because they come from empiric experience
Nguồn: http://goddess-gate.com/dc2/index.php/post/255
Fix cấu hình SSH2 để DreamWeaver có thể connect via SFTP
Khi cài đặt ssh2 thì với cấu hình mặc định, DreamWeaver hoặc WS_FTP không thể connect vào server thông qua giao thức SFTP. Để khắc phục lỗi này, chỉnh lại trong file cấu hình /etc/ssh/sshd_config như sau:
(Xem tiếp)
How Do I Enable Remote Access To MySQL Database Server?
By default, MySQL database server remote access disabled for security reasons. However, some time you need to provide the remote access to database server from home or from web server.
MySQL Remote Access
You need type the following commands which will allow remote connections:
Step # 1: Login over ssh if server is outside your IDC
First, login over ssh to remote MySQL database server
Step # 2: Enable networking
Once connected you need edit the mysql configuration file my.cfg using text editor such as vi.
- If you are using Debian Linux file is located at /etc/mysql/my.cnf location
- If you are using Red Hat Linux/Fedora/Centos Linux file is located at /etc/my.cnf location
- If you are using FreeBSD you need to create a file /var/db/mysql/my.cnf
# vi /etc/my.cnf
Step # 3: Once file opened, locate line that read as follows
[mysqld]
Make sure line skip-networking is commented (or remove line) and add following line
bind-address=YOUR-SERVER-IP
For example, if your MySQL server IP is 65.55.55.2 then entire block should be look like as follows:[mysqld]Where,
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
language = /usr/share/mysql/English
bind-address = 65.55.55.2
# skip-networking
....
..
....
- bind-address : IP address to bind to.
- skip-networking : Don't listen for TCP/IP connections at all. All interaction with mysqld must be made via Unix sockets. This option is highly recommended for systems where only local requests are allowed. Since you need to allow remote connection this line should removed from file or put it in comment state.
Step# 4 Save and Close the file
Restart your mysql service to take change in effect:# /etc/init.d/mysql restart
Step # 5 Grant access to remote IP address
# mysql -u root -p mysqlGrant access to new database
If you want to add new database called foo for user bar and remote IP 202.54.10.20 then you need to type following commands at mysql> prompt:mysql> CREATE DATABASE foo;
mysql> GRANT ALL ON foo.* TO bar@'202.54.10.20' IDENTIFIED BY 'PASSWORD';
How Do I Grant access to existing database?
Let us assume that you are always making connection from remote IP called 202.54.10.20 for database called webdb for user webadmin, To grant access to this IP address type the following command At mysql> prompt for existing database:mysql> update db set Host='202.54.10.20' where Db='webdb';
mysql> update user set Host='202.54.10.20' where user='webadmin';
Step # 5: Logout of MySQL
Type exit command to logout mysql:mysql> exit
Step # 6: Open port 3306
You need to open port 3306 using iptables or BSD pf firewall.
A sample iptables rule to open Linux iptables firewall
/sbin/iptables -A INPUT -i eth0 -p tcp --destination-port 3306 -j ACCEPT
OR only allow remote connection from your web server located at 10.5.1.3:
/sbin/iptables -A INPUT -i eth0 -s 10.5.1.3 -p tcp --destination-port 3306 -j ACCEPT
OR only allow remote connection from your lan subnet 192.168.1.0/24:
/sbin/iptables -A INPUT -i eth0 -s 192.168.1.0/24 -p tcp --destination-port 3306 -j ACCEPT
A sample FreeBSD / OpenBSD pf rule ( /etc/pf.conf)
pass in on $ext_if proto tcp from any to any port 3306
OR allow only access from your web server located at 10.5.1.3:
pass in on $ext_if proto tcp from 10.5.1.3 to any port 3306 flags S/SA synproxy state
Step # 7: Test it
From remote system or your desktop type the command:$ mysql -u webadmin -h 65.55.55.2 -p
Where,
- -u webadmin: webadmin is MySQL username
- -h IP or hostname: 65.55.55.2 is MySQL server IP address or hostname (FQDN)
- -p : Prompt for password
You can also use telnet to connect to port 3306 for testing purpose:$ telnet 65.55.55.2 3306
Ấn tượng với FreeBSD 7.0
FreeBSD 7.0 thực sự là một hệ điều hành ưu việt dành cho máy chủ. Khả năng hỗ trợ SMP được cải tiến mạnh mẽ, tốc độ cải thiện cực kỳ ấn tượng so với các phiên bản cũ. Đặc biệt là khi đem so sánh với một kernel Linux tốt nhất có thể thì FreeBSD 7.0 vẫn nhanh hơn đến 15%.
(Xem tiếp)
Bản in