分类目录归档:linux
CentOS 6.5 下安装 redis及编译异常处理办法(含php7安装扩展)
CentOS 6.5 下安装 Redis 2.8.19,
1)下载Redis
wget http://download.redis.io/redis-stable.tar.gz
或者:http://download.redis.io/releases/ 下载最新版本
- wget http://download.redis.io/releases/redis-2.8.19.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make MALLOC=libc
make test
make install
这3个命令应该没有问题,主要的问题是执行make的时候,出现了异常。
异常一:
make[2]: cc: Command not found
异常原因:没有安装gcc
解决方案:yum install gcc-c++
异常二:
zmalloc.h:51:31: error: jemalloc/jemalloc.h: No such file or directory
异常原因:一些编译依赖或原来编译遗留出现的问题
解决方案:make distclean。清理一下,然后再make。
在make成功以后,需要make test。在make test出现异常。
异常三:
couldn’t execute “tclsh8.5”: no such file or directory
异常原因:没有安装tcl
解决方案:yum install -y tcl。
异常四:运行make test 报了这样的一个错误:
!!! WARNING The following tests failed:
*** [err]: Test replication partial resync: ok psync (diskless: yes, reconnect: 1) in tests/integration/replication-psync.tcl
Expected condition ‘[s -1 sync_partial_ok] > 0’ to be true ([s -1 sync_partial_ok] > 0)
Cleanup: may take some time… OK
make[1]: *** [test] Error 1
make[1]: Leaving directory `/usr/local/src/redis-3.2.1/src’
make: *** [test] Error 2
■ 解决办法:
1,只用单核运行 make test:
taskset -c 1 sudo make test
2,更改 tests/integration/replication-psync.tcl 文件:
vi tests/integration/replication-psync.tcl
把对应报错的那段代码中的 after后面的数字,从100改成 500。我个人觉得,这个参数貌似是等待的毫秒数。
编辑文件tests/integration/replication-psync.tcl
然后找到after 100 把此值修改成200或者300。重新执行make test就可以了
在make成功以后,会在src目录下多出一些可执行文件:redis-server,redis-cli等等。
方便期间用cp命令复制到usr目录下运行。
cp redis-server /usr/local/bin/
cp redis-cli /usr/local/bin/
然后新建目录,存放配置文件
mkdir /etc/redis
mkdir /var/redis
mkdir /var/redis/log
mkdir /var/redis/run
mkdir /var/redis/6379
在redis解压根目录中找到配置文件模板,复制到如下位置。
cd ..
cp redis.conf /etc/redis/6379.conf
通过vim命令修改
daemonize yes
pidfile /var/redis/run/redis_6379.pid
logfile /var/redis/log/redis_6379.log
dir /var/redis/6379
最后运行redis:
$ redis-server /etc/redis/6379.conf
配置自启动:
/etc/init.d/redis-server
#!/bin/sh
#
# redis - this script starts and stops the redis-server daemon
#
# chkconfig: - 85 15
# description: Redis is a persistent key-value database
# processname: redis-server
# config: /etc/redis.conf
# config: /etc/sysconfig/redis
# pidfile: /var/run/redis.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
redis="/usr/local/bin/redis-server"
prog=$(basename $redis)
REDIS_CONF_FILE="/etc/redis.conf"
[ -f /etc/sysconfig/redis ] && . /etc/sysconfig/redis
lockfile=/var/lock/subsys/redis
start() {
[ -x $redis ] || exit 5
[ -f $REDIS_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $redis $REDIS_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
stop
start
}
reload() {
echo -n $"Reloading $prog: "
killproc $redis -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
exit 2
esac
(2)将redis加入自启动服务
sudo chkconfig --add /etc/init.d/redis-server
sudo chkconfig redis-server --level 345 on
使用chkconfig --list查看添加的服务
(4)启动服务
sudo service redis-server start
三、使用
redis-cli
127.0.0.1:6379>
127.0.0.1:6379>
127.0.0.1:6379> keys *
(empty list or set)
在LINUX下有什么办法防止用户使用nmap -PS扫描时主机显示为host up状态
Installing Redmine3 项目管理工具Redmine安装
Installing Redmine3 项目管理工具Redmine安装In
stalling Redmine
-
Installing Redmine
- Requirements
- Redmine Version
-
Installation procedure
- Step 1 – Redmine application
- Step 2 – Create an empty database and accompanying user
- Step 3 – Database connection configuration
- Step 4 – Dependencies installation
- Step 5 – Session store secret generation
- Step 6 – Database schema objects creation
- Step 7 – Database default data set
- Step 8 – File system permissions
- Step 9 – Test the installation
- Step 10 – Logging into the application
- Configuration
- Logging configuration
- Backups
- Notes on Linux/Unix installation
- Notes on Windows installation
- Alternative to manual installation
This is the installation documentation for Redmine 1.4.0 and higher. You can still read the document for 1.3.x here.
Requirements
Operating system
Redmine should run on most Unix, Linux, Mac, Mac Server and Windows systems as long as Ruby is available on this platform. See specific installation HowTos here.
Ruby interpreter
The required Ruby versions for a given Redmine version is:
Redmine version | Supported Ruby versions | Rails version used |
---|---|---|
current trunk | ruby 1.9.3, 2.0.01, 2.1, 2.2 | Rails 4.2 |
trunk < r13482 | ruby 1.8.72, 1.9.2, 1.9.3, 2.0.01, 2.1, jruby-1.7.6 | Rails 3.2 |
3.0 | ruby 1.9.3, 2.0.01, 2.1, 2.2 | Rails 4.2 |
2.6 | ruby 1.8.72, 1.9.2, 1.9.3, 2.0.01, 2.1, jruby-1.7.6 | Rails 3.2 |
Redmine 2.x does not support Ruby 2.2. Redmine 3.0 supports Ruby 2.2 (#18947).
MRI 1.9.3p327 contains a bug breaking plugin loading under Windows which 1.9.3p194 or 1.9.3p392 haven’t.
1 At time of writing (3/19/2013), SQL Server support is reported broken with ruby 2.0.0 under Windows because of a database adapter gem incompatibility
2 Ruby MRI 1.8.7 support has reached its EOL and its use is discouraged. See #14371 for additional information.
and
Supported database back-ends
-
MySQL 5.0 or higher
-
make sure to install the C bindings for Ruby that dramatically improve performance. You can get them by running
gem install mysql2
. - Redmine 2.x is not compatible with mysql 5.7.3 (#17460). Il will be supported by Redmine 3.
-
make sure to install the C bindings for Ruby that dramatically improve performance. You can get them by running
- PostgreSQL 8.2 or higher
-
Microsoft SQL Server
- Redmine 2.x: 2008 or higher (since Redmine 2.3.0)
- Redmine 3.x: 2012 or higher
- SQLite 3 (not for multi-user production use!)
Optional components
-
SCM binaries (eg.
svn
), for repository browsing (must be available in your PATH). See RedmineRepositories for SCM compatibility and requirements. - ImageMagick (to enable Gantt export to PNG image and thumbnails generation).
- Ruby OpenID Library (to enable OpenID support). Version 2 or greater is required.
Redmine Version
It is recommended that the majority of users install the proper point releases of redmine. Redmine currently releases a new version every 6 months, and these releases are considered very usable and stable. It is not recommended to install redmine from trunk, unless you are deeply familiar with Ruby on Rails and keep up with the changes – Trunk does break from time-to-time.
Installation procedure
Step 1 – Redmine application
Get the Redmine source code by either downloading a packaged release or checking out the code repository.
See the download page for details.
Step 2 – Create an empty database and accompanying user
Redmine database user will be named redmine
hereafter but it can be changed to anything else.
MySQL
For versions of MySQL prior to 5.0.2 – skip the ‘create user’ step and instead:
PostgreSQL
SQL Server
The database, login and user can be created within SQL Server Management Studio with a few clicks.
If you prefer the command line option with SQLCMD
, here’s some basic example:
Step 3 – Database connection configuration
Copy config/database.yml.example
to config/database.yml
and edit this file in order to configure your database settings for “production” environment.
Example for a MySQL database using ruby 1.8 or jruby:
Example for a MySQL database using ruby 1.9 (adapter must be set to mysql2
):
If your server is not running on the standard port (3306), use this configuration instead:
Example for a PostgreSQL database (default port):
Example for a SQL Server database (default host localhost
, default port 1433
):
Step 4 – Dependencies installation
Redmine uses Bundler to manage gems dependencies.
You need to install Bundler first:
Then you can install all the gems required by Redmine using the following command:
Optional dependencies
RMagick (allows the use of ImageMagick to manipulate images for PDF and PNG export)
If ImageMagick is not installed on your system, you should skip the installation of the rmagick gem using:
If you have trouble installing rmagick
on Windows, refer to this HowTo.
Database adapters
Redmine automatically installs the adapter gems required by your database configuration by reading it from the config/database.yml
file (eg. if you configured only a connection using the mysql2
adapter, then only the mysql2
gem will be installed).
Don’t forget to re-run bundle install --without development test ...
after adding or removing adapters in the config/database.yml
file!
Additional dependencies (Gemfile.local
)
If you need to load gems that are not required by Redmine core (eg. Puma, fcgi), create a file named Gemfile.local
at the root of your redmine directory. It will be loaded automatically when running bundle install
.
Example:
- with Redmine 1.4.x:
- with Redmine 2.x:
Step 6 – Database schema objects creation
Create the database structure, by running the following command under the application root directory:
Windows syntax:
It will create tables by running all migrations one by one then create the set of the permissions and the application administrator account, named admin
.
Ubuntu troubleshooting:
If you get this error with Ubuntu:
Then you need to install libopenssl-ruby1.8
just like this: apt-get install libopenssl-ruby1.8
.
Step 7 – Database default data set
Insert default configuration data in database, by running the following command:
Redmine will prompt you for the data set language that should be loaded; you can also define the REDMINE_LANG
environment variable before running the command to a value which will be automatically and silently picked up by the task.
E.g.:
Unices:
Windows:
Step 8 – File system permissions
NB: Windows users can skip this section.
The user account running the application must have write permission on the following subdirectories:
-
files
(storage of attachments) -
log
(application log fileproduction.log
) -
tmp
andtmp/pdf
(create these ones if not present, used to generate PDF documents among other things) -
public/plugin_assets
(assets of plugins)
E.g., assuming you run the application with a redmine user account:
Step 9 – Test the installation
Test the installation by running WEBrick web server:
- with Redmine 1.4.x:
- with Redmine 2.x:
Once WEBrick has started, point your browser to http://localhost:3000/. You should now see the application welcome page.
Note: Webrick is not suitable for production use, please only use webrick for testing that the installation up to this point is functional. Use one of the many other guides in this wiki to setup redmine to use either Passenger (aka
mod_rails
), FCGI or a Rack server (Unicorn, Thin, Puma, hellip;) to serve up your redmine.
Step 10 – Logging into the application
Use default administrator account to log in:
- login: admin
- password: admin
You can go to Administration menu and choose Settings to modify most of the application settings.
Configuration
Redmine settings are defined in a file named config/configuration.yml
.
If you need to override default application settings, simply copy config/configuration.yml.example
to config/configuration.yml
and edit the new file; the file is well commented by itself, so you should have a look at it.
These settings may be defined per Rails environment (production
/development
/test
).
Important
: don’t forget to restart the application after any change.
Email / SMTP server settings
Email configuration is described in a dedicated page.
SCM settings
This configuration section allows you to:
-
override default commands names if the SCM binaries present in the
PATH
variable doesn’t use the standard name (Windows .bat/.cmd names won’t work) - specify the full path to the binary
Examples (with Subversion):
Command name override:
Absolute path:
Attachment storage settings
You can set a path where Redmine attachments will be stored which is different from the default ‘files’ directory of your Redmine instance using theattachments_storage_path
setting.
Examples:
Logging configuration
Redmine defaults to a log level of :info, writing to the log
subdirectory. Depending on site usage, this can be a lot of data so to avoid the contents of the logfile growing without bound, consider rotating them, either through a system utility like logrotate
or via the config/additional_environment.rb
file.
To use the latter, copy config/additional_environment.rb.example
to config/additional_environment.rb
and add the following lines. Note that the new logger defaults to a high log level and hence has to be explicitly set to info
.
Backups
Redmine backups should include:
- data (stored in your redmine database)
-
attachments (stored in the
files
directory of your Redmine install)
Here is a simple shell script that can be used for daily backups (assuming you’re using a mysql database):
Notes on Linux/Unix installation
Be sure to disable security hardenning tools during the installation process if you run into bizarre permission problems. These problems are mostly silent and can be caused by tools like extended ACLs, SELinux, or AppArmor. There tools are mostly used in big companies with a strict security policy, default Linux/Unix distributions settings shouldn’t be a problem.
Notes on Windows installation
There is an prebuilt installer of Ruby MRI available from http://rubyinstaller.org.
After installing it, select Start Command Prompt with Ruby in the start menu.
Specifying the RAILS_ENV
environment variable:
When running command as described in this guide, you have to set the RAILS_ENV
environment variable using a separate command.
I.e. commands with the following syntaxes:
have to be turned into 2 subsequent commands:
MySQL gem installation issue:
You may need to manually install the mysql gem using the following command:
And in some case it is required to copy the libmysql.dll file in your ruby/bin directory.
Not all libmysql.dll are ok this seem to works http://instantrails.rubyforge.org/svn/trunk/InstantRails-win/InstantRails/mysql/bin/libmySQL.dll.
Important note for Win7 and later
On Win7 and later, localhost
is commented out in the hosts file1 and IPV6 is the default2. As the mysql2 gem does no support IPV6 addresses3, a connection can’t be established and you get the error “Can't connect to MySQL server on 'localhost' (10061)
“.
You can confirm this by pinging localhost
, if ping targets “::1:” IPV6 is being used.
Workaround:
Replace localhost
with 127.0.0.1
in database.yml.
3 https://github.com/brianmario/mysql2/issues/279
Alternative to manual installation
Some users may prefer to skip manual installation by using one of the third-party Redmine bundles on the download page.
免费且开源的项目管理工具redmine3的安装和升级
这是一款开源的、灵活的项目管理Web解决方案。使用Ruby on Rails框架编写的,支持跨平台和跨数据库。主要功能包括:
- 灵活的项目控制;
- 支持多个项目;
- 灵活的问题追踪系统;
- Gantt图表;
- 新闻、文件/文档管理;
- 电子邮件/心疼通知;
- 实时追踪;
- 每个项目论坛;
- 每个项目Wiki;
- 自定义字段条目时、问题、影虎以及项目;
- SCM集成(CVS,SVN,Git,Mercurial,Darcs,Bazaar);
- 支持多个LDAP验证;
- 支持多语言;
- 使用email创建问题;
- 支持用户自定义注册;
- 支持多种数据库。
免费且开源的项目管理工具redmine3的安装和升级
参考:
http://www.redmine.org/projects/redmine/wiki/RedmineInstall#Requirements
Redmine 3.0的需求: current trunk ruby 1.9.3, 2.0.01, 2.1, 2.2 Rails 4.2 1. 搭建redmine3环境 【安装软件包】 # yum install zlib-devel gcc gcc-c++ make autoconf curl-devel ImageMagick-devel mysql mysql-devel 【下载安装包,修改db和email的设置】 # tar zxvf redmine-3.0.0.tar.gz && cd redmine-3.0.0/config # cp -a database.yml.example database.yml # cp -a configuration.yml.example configuration.yml 【建立ruby2.2 + rails 4.2的环境】 # gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 # curl -sSL https://get.rvm.io | bash -s stable --ruby --rails 重新登录一次: $ ruby -v ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-linux] $ rails -v Rails 4.2.0 # rvm gemset list gemsets for ruby-2.2.0 (found in /usr/local/rvm/gems/ruby-2.2.0) => (default) global # cd /data/website/ ;mv redmine-3.0.0 redmine 【安装依赖包】 # ./bin/bundle install --without development test
---bundle install
的时候半天没有响应,具体可以用gem install bundle -V
来查看执行过程。
如何更换:
$ gem sources --remove https://rubygems.org/
$ gem sources -a https://ruby.taobao.org/
$ gem sources -l *** CURRENT SOURCES *** https://ruby.taobao.org # 请确保只有 ruby.taobao.org $ gem install rails# useradd -s /sbin/nologin -M -c "redmine" redmine # chown -R redmine:redmine /data/website/redmine-3.0.0 若是全新安装: 【db】 mysql登录后,建立redmine数据库和用户: # mysql -h x.x.x.x -P xxxx -uroot -p mysql> create database redmine character set utf8 collate utf8_bin; mysql> create user ‘redmine‘@‘127.0.0.1‘ identified by ‘xxxxxx‘; mysql> grant all privileges on redmine.* to ‘redmine‘@‘127.0.0.1‘; mysql> exit; # rake generate_secret_token # RAILS_ENV=production rake db:migrate # RAILS_ENV=production rake redmine:load_default_data # mkdir -p tmp tmp/pdf public/plugin_assets # chmod -R 755 files log tmp public/plugin_assets 若是升级: 【db】 备份数据库 检查db用户权限 命令行测试连接 执行: # bundle exec rake generate_secret_token # bundle exec rake db:migrate RAILS_ENV=production 若有插件: # bundle exec rake redmine:plugins:migrate RAILS_ENV=production # bundle exec rake tmp:cache:clear tmp:sessions:clear RAILS_ENV=production 启动服务: # cd /data/website/redmine-3.0.0/ # ruby bin/rails server webrick -e production 也可以放入后台: # nohup ruby bin/rails server webrick -e production >>/data/log/web/redmine/running_redmine.log 2>&1 & 默认管理员:admin, admin 访问http://IP:3000 2. 迁移redmine服务到nginx下 # yum install pcre pcre-devel # wget http://nginx.org/download/nginx-1.6.2.tar.gz # tar zxvf nginx-1.6.2.tar.gz -C /data/download/ # mkdir -p /var/cache/nginx/{client_temp,proxy_temp,fastcgi_temp,uwsgi_temp,scgi_temp} # gem install passenger # passenger -v Phusion Passenger version 4.0.59 "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui. 注:若遇到gem install passenger不能生效的问题,可能是ruby的仓库被GFW了,此时,先安装fastthread可以解决问题: # gem install fastthread # gem install passenger 安装: # passenger-install-nginx-module Enter your choice (1 or 2) or press Ctrl-C to abort: 2 -------------------------------------------- Where is your Nginx source code located? Please specify the directory: /data/download/nginx-1.6.2 -------------------------------------------- Where do you want to install Nginx to? Please specify a prefix directory [/opt/nginx]: /etc/nginx -------------------------------------------- Extra Nginx configure options If you want to pass extra arguments to the Nginx ‘configure‘ script, then please specify them. If not, then specify nothing and press Enter. If you specify nothing then the ‘configure‘ script will be run as follows: sh ./configure --prefix=‘/etc/nginx‘ --with-http_ssl_module --with-http_gzip_static_module \--with-http_stub_status_module --with-cc-opt=‘-Wno-error‘\--add-module=‘/usr/local/rvm/gems/ruby-2.2.0/gems/passenger-4.0.59/ext/nginx‘ Extra arguments to pass to configure script: --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf \--error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log \--pid-path=/var/run/nginx.pid \--lock-path=/var/run/nginx.lock \--http-client-body-temp-path=/var/cache/nginx/client_temp \--http-proxy-temp-path=/var/cache/nginx/proxy_temp \--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \--http-scgi-temp-path=/var/cache/nginx/scgi_temp \--user=nginx \--group=nginx -------------------------------------------- Confirm configure flags The Nginx configure script will be run as follows: sh ./configure --prefix=‘/etc/nginx‘ --with-http_ssl_module --with-http_gzip_static_module \--with-http_stub_status_module --with-cc-opt=‘-Wno-error‘ \--add-module=‘/usr/local/rvm/gems/ruby-2.2.0/gems/passenger-4.0.59/ext/nginx‘ \--sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log \--http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock \--http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp \--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \--http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx -------------------------------------------- Nginx with Passenger support was successfully installed. Please edit your Nginx configuration file, and set the passenger_root and passenger_ruby configuration options in the ‘http‘ block, like this: http { ... passenger_root /usr/local/rvm/gems/ruby-2.2.0/gems/passenger-4.0.59; passenger_ruby /usr/local/rvm/gems/ruby-2.2.0/wrappers/ruby; ... } After you (re)start Nginx, you are ready to deploy any number of web applications on Nginx. Press ENTER to continue. -------------------------------------------- Deploying a web application: an example Suppose you have a web application in /somewhere. Add a server block to your Nginx configuration file, set its root to /somewhere/public, and set ‘passenger_enabled on‘, like this: server { listen 80; server_name www.yourhost.com; root /somewhere/public; # <--- be sure to point to ‘public‘! passenger_enabled on; } And that‘s it! You may also want to check the Users Guide for security and optimization tips and other useful information: /usr/local/rvm/gems/ruby-2.2.0/gems/passenger-4.0.59/doc/Users guide Nginx.html https://www.phusionpassenger.com/documentation/Users%20guide%20Nginx.html Enjoy Phusion Passenger, a product of Phusion (www.phusion.nl) :-) https://www.phusionpassenger.com Phusion Passenger is a trademark of Hongli Lai & Ninh Bui. # useradd -s /sbin/nologin -M -c "nginx Server" nginx # mkdir -p /etc/nginx/conf.d /data/log/svr/nginx /data/log/web/redmine $ cat /etc/nginx/nginx.conf #user nobody; worker_processes 4; error_log /data/log/svr/nginx/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; pid /var/run/nginx.pid; events { use epoll; worker_connections 65535; } http { include mime.types; default_type application/octet-stream; server_tokens off; log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘ ‘$status $body_bytes_sent "$http_referer" ‘ ‘"$http_user_agent" "$http_x_forwarded_for"‘; access_log /data/log/svr/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_body_temp_path /tmp; client_max_body_size 500m; fastcgi_connect_timeout 600; fastcgi_send_timeout 300; fastcgi_read_timeout 3600; fastcgi_buffer_size 400k; fastcgi_buffers 16 1m; fastcgi_busy_buffers_size 10m; fastcgi_temp_file_write_size 20m; fastcgi_intercept_errors on; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 2; gzip_disable "MSIE [1-6]."; gzip_types text/plain application/x-javascript text/css text/javascript application/x-httpd-php image/jpeg image/gif image/png; gzip_vary on; passenger_root /usr/local/rvm/gems/ruby-2.2.0/gems/passenger-4.0.59; passenger_ruby /usr/local/rvm/gems/ruby-2.2.0/wrappers/ruby; # Load config files from the /etc/nginx/conf.d directory # The default server is in conf.d/default.conf include conf.d/*.conf; } $ cat /etc/nginx/conf.d/redmine.conf # # redmine # server { listen 10.221.221.118:80; server_name redmine.xxx.com; root /data/website/redmine-3.0.0/public; passenger_enabled on; access_log /data/log/web/redmine/access.log main; }
linux之CentOS配置proftpd
1.proftpd软件下载安装
[root@chenghy ~]# cd /root
[root@chenghy ~]# wget ftp://ftp.proftpd.org/distrib/source/proftpd-1.3.4c.tar.gz
[root@chenghy ~]# tar zxvf proftpd-1.3.4c.tar.gz
[root@chenghy ~]# cd proftpd-1.3.4c
[root@chenghy ~]# ./configure –prefix=/usr/local/proftpd
[root@chenghy ~]# make
[root@chenghy ~]# make install
2.修改proftpd配置文件
[root@chenghy ~]# vim /usr/local/proftpd/etc/proftpd.conf
ServerName “chenghy’s FTP Server”
ServerType standalone # 以独立进程方式运行
DefaultServer on
Port 2100 # FTP端口
Umask 002 # 权限,建议设置为002
UseReverseDNS off # 禁止DNS反查
IdentLookups off # 禁止DNS反查
ServerIdent off # 隐藏软件版本信息
AllowRetrieveRestart on # 下载断点续传
AllowStoreRestart on # 上传断点续传
## 虚拟用户认证信息
AuthOrder mod_auth_file.c # 只允许虚拟用户登陆
AuthUserFile /usr/local/proftpd/etc/ftp.users
AuthGroupFile /usr/local/proftpd/etc/ftp.group
DefaultRoot ~ # 将用户限定在根目录下
PassivePorts 20000 30000 # 被动模式端口段
SystemLog /var/log/proftpd/proftpd.log # 软件日志
TransferLog /var/log/proftpd/proftpd.xfer.log
LogFormat default “%h %u %t %D \”%r\” %s %b” # 日志格式
ExtendedLog /var/log/proftpd/access.log WRITE,READ default # 访问日志
MaxInstances 250 # 允许最大连接
MaxClients 20 # 最大用户数
MaxLoginAttempts 3 # 最大尝试连接次数
TimeoutLogin 30 # 身份验证超时
TimeoutIdle 120 # 发呆超时
TimeoutNoTransfer 300 # 无数据传输超时
User nobody # 定义ftp以哪个用户身份运行
Group nobody # 定义ftp以哪个用户组身份运行
<Directory ~/>
AllowOverwrite on # 允许写入覆盖
<Limit LOGIN CWD RETR READ DIRS> # 设置虚拟用户读权限
AllowALL
</Limit>
<Limit ALL> # 设置omd用户所有权限
Order allow,deny
AllowUser omd
DenyALL
</Limit>
</Directory>
3.添加proftpd虚拟用户和组
[root@chenghy ~]# /usr/local/proftpd/bin/ftpasswd –passwd –name=bsmp –home=/home/omd/file/ –uid=2001 –gid=2000 –shell=/sbin/nologin –file=/usr/local/proftpd/etc/ftp.users
[root@chenghy ~]# /usr/local/proftpd/bin/ftpasswd –passwd –name=omd –home=/home/omd/ –uid=2002 –gid=2000 –shell=/sbin/nologin –file=/usr/local/proftpd/etc/ftp.users
[root@chenghy ~]# /usr/local/proftpd/bin/ftpasswd –group –name=myftp –gid=2000 –member=bsmp –member=omd –file=/usr/local/proftpd/etc/ftp.group
4.将proftpd用户目录设置权限
[root@chenghy ~]# chown -R 2002:2000 /home/omd/
####下面两行用来删除用户和组###########
[root@chenghy ~]# /usr/local/proftpd/bin/ftpasswd –passwd –name=bsmp –delete-user –file=/usr/local/proftpd/etc/ftp.users
[root@chenghy ~]# /usr/local/proftpd/bin/ftpasswd –group –name=myftp –delete-group –file=/usr/local/proftpd/etc/ftp.group
5.将proftpd添加到系统服务
按照网上的资料修改/etc/rc.d/init.d/proftpd文件后发现配置不成功,后来自己修改了一下此文件完成了配置
[root@chenghy ~]# vim /etc/rc.d/init.d/proftpd
#!/bin/sh
# Source function library.
. /etc/rc.d/init.d/functions
RETVAL=0
start() {
echo -n $”Starting proftpd : “
daemon /usr/local/proftpd/sbin/proftpd -c /usr/local/proftpd/etc/proftpd.conf 2>/dev/null
# daemon命令是/etc/rc.d/init.d/functions中自带的
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/proftpd
}
stop() {
echo -n $”Shutting down proftpd : “
killproc proftpd
# killproc命令是/etc/rc.d/init.d/functions中自带的
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/proftpd
}
# See how we were called.
case “$1” in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo “Usage: proftpd { start | stop | restart }”
esac
[root@chenghy ~]# chmod 755 /etc/rc.d/init.d/proftpd
[root@chenghy ~]# chkconfig add proftpd
[root@chenghy ~]# chkconfig –level 35 proftpd on
[root@chenghy ~]# service proftpd start
6.防火墙设置proftpd端口
只允许主动模式访问添加下面的第①、②条,只允许被动模式访问添加下面的②、③条,两种模式都允许添加下面①、②、③条。
[root@chenghy ~]# iptables -A RH-Firewall-1-INPUT -p tcp -m tcp –dport 20 -j ACCEPT
[root@chenghy ~]# iptables -A RH-Firewall-1-INPUT -p tcp -m tcp –dport 2100 -j ACCEPT
[root@chenghy ~]# iptables -A RH-Firewall-1-INPUT -p tcp -m tcp –dport 20000:30000 -j ACCEPT
Linux上imagemagick对图片进行压缩,convert命令的压缩率还不错
Linux上imagemagick对图片进行压缩,convert命令的压缩率还不错
这里要使用到强大的图片处理工具:imagemagick,它可以对图片进行格式转换、大小压缩、增加水印等操作,而不需要去写第三方的程序,只需要写简单的SHELL脚本就可以完成图片压缩操作,我的操作环境是UBUNTU,在UBUNTU下面安装这个软件超级简单:
sudo apt-get install imagemagick
centos安装: yum -y install ImageMagick
其它linux有对应的软件安装命令,以下有我写的两个脚本,分别对图片进行批量格式以及压缩操作:
图片格式转换,这里的示例是将[bB][mM][pP](所有BMP文件)格式的文件,转换为占空间小的jpg文件:
- #!/bin/sh
- for img in `find ./ -name “*.[bB][mM][pP]”`; do
- #change upper filename to lower
- _imglower=`echo $img|tr “[:upper:]” “[:lower:]”`;
- #get file’s basename
- _basename=`basename $_imglower .bmp`;
- #get file’s dir
- _dirname=`dirname $img`;
- #get desc filename with path
- _basefullname=$_dirname”/”$_basename”.jpg”;
- #do convert
- convert $img $_basefullname;
- #remove bmp file
- rm $img;
- echo “deal $_basefullname successfully”;
- done
图片压缩脚本:
- for img in `find ./ -name “*.[jJ][pP][gG]”`; do
- convert -quality 95% -resize 85%*85% $img $img-resized;
- rm $img;
- mv $img-resized $img
- echo $img
- done
- for img in `find ./ -name “*.[pP][nN][gG]”`; do
- convert -resize 85%*85% $img $img-resized;
- rm $img;
- mv $img-resized $img
- echo $img
- done
- for img in `find ./ -name “*.[gG][iI][fF]”`; do
- convert -resize 85%*85% $img $img-resized;
- rm $img;
- mv $img-resized $img
- echo $img
- done
利用Nginx的ngx_http_image_filter_module做实时的图片压缩缩略图
CentOS使用inotify+rsync实时文件监控的同步备份
inotify是Linux下的一个文件系统事件监控机制(简单说就是用于监控某个文件夹的所有文件及文件夹的改动),作为dnotify的有效替代。inotify是一种强大的、细粒度的、异步的机制,它满足各种各样的文件监控需要。在单独使用rsync同步时,每次同步它会把全部的文件读取一遍,而inotify+rsync同步是触发式文件监控同步备份。假设被镜像端IP为192.168.1.100,镜像端IP为192.168.1.200。
一、被镜像(同步)端
linux内核2.6.13之后就支持inotify了,确认方法:
ls /proc/sys/fs/inotify
如果有以下三项就支持:
max_queued_events max_user_instances max_user_watches
安装rsync:
yum install rsync
安装inotify:
官网:https://github.com/rvoicilas/inotify-tools
cd /tmp
wget --no-check-certificate http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
tar -zxvf inotify-tools-3.14.tar.gz
cd inotify-tools-3.14
./configure
make
make install
默认安装到/usr/local/bin目录。
建立rsync密码文件:
vim /root/rsyncpass
输入密码:
123456
设置权限为600:
chmod 600 /root/rsyncpass
创建同步脚本:
vim /root/rsync.sh
输入:
#!/bin/bash
src=/var/www
des=backup@192.168.1.200::web
/usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' \
-e modify,delete,create,attrib ${src} \
| while read x
do
/usr/bin/rsync -avz --delete --progress $src $des --password-file=/root/rsyncpass &&
echo "$x was rsynced" >> /var/log/rsync.log
done
注释:
inotifywait
-m:保持监听事件。
-r:递归查看目录。
-q:打印出事件。
-e modify,delete,create,attrib:监听写入,删除,创建,属性改变事件。
rsync
-a:存档模式,相当于使用-rlptgoD。
-v:详细模式输出。
-z:传输过程中压缩文件。
为脚本加执行权限:
chmod +x /root/rsync.sh
在rc.local加入自启动:
echo "/root/rsync.sh" >> /etc/rc.local
二、镜像(同步)端
安装rsync:
yum install rsync
编辑配置文件:
vim /etc/rsyncd.conf
输入:
uid = nobody
gid = nobody
use chroot = no
max connections = 10
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
hosts allow = *
[web]
path = /home/webbak
read only = no
list = no
auth users = backup
secrets file = /root/rsync.pass
建立密码文件:
vim /root/rsync.pass
输入:
backup:123456
格式为“用户名:密码”。
设置权限为600:
chmod 600 /root/rsync.pass
建立保存同步文档的目录:
mkdir /home/webbak
chown nobody:nobody /home/webbak
后台启动rsync:
/usr/bin/rsync --daemon --config=/etc/rsyncd.conf
在被镜像端上运行同步脚本:
/root/rsync.sh &
inotify文件监控工具inotify-tools使用方法介绍
inotify文件监控工具notify-tools 是为linux下提供的一套c的开发接口库函数,同时还提供了一系列的命令行工具,这些工具可以用来监控文件系统的事件。 inotify-tools是用c编写的,除了要求内核支持inotify外,不依赖于其他。inotify-tools提供两种工具,一是inotifywait,它是用来监控文件或目录的变化,二是inotifywatch,它是用来统计文件系统访问的次数。现在介绍一下它的使用方法。
源码来源:https://github.com/rvoicilas/inotify-tools/
安装方法
- wget http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
- tar xzf inotify-tools-3.14.tar.gz ;cd inotify-tools-3.14
- ./configure –prefix=/usr && make && su -c ‘make install’
使用例子
inotifywait
1、实时监控/home的所有事件(包括文件的访问,写入,修改,删除等)
- inotifywait -rm /home
2、监控/var/log/messeges中有关httpd的日志
- #!/bin/sh
- while inotifywait -e modify /var/log/messages; do
- if tail -n1 /var/log/messages | grep httpd; then
- kdialog –msgbox “Apache needs love!”
- fi
- done
inotifywatch
1、统计/home文件系统的事件
- inotifywatch -v -e access -e modify -t 60 -r /home
参数说明
inotifywait
语法:
inotifywait [-hcmrq] [-e
参数:
-h,–help
输出帮助信息
@
排除不需要监视的文件,可以是相对路径,也可以是绝对路径。
–fromfile
从文件读取需要监视的文件或排除的文件,一个文件一行,排除的文件以@开头。
-m, –monitor
接收到一个事情而不退出,无限期地执行。默认的行为是接收到一个事情后立即退出。
-d, –daemon
跟–monitor一样,除了是在后台运行,需要指定–outfile把事情输出到一个文件。也意味着使用了–syslog。
-o, –outfile
输出事情到一个文件而不是标准输出。
-s, –syslog
输出错误信息到系统日志
-r, –recursive
监视一个目录下的所有子目录。
-q, –quiet
指定一次,不会输出详细信息,指定二次,除了致命错误,不会输出任何信息。
–exclude
正则匹配需要排除的文件,大小写敏感。
–excludei
正则匹配需要排除的文件,忽略大小写。
-t
设置超时时间,如果为0,则无限期地执行下去。
-e
指定监视的事件。
-c, –csv
输出csv格式。
–timefmt
指定时间格式,用于–format选项中的%T格式。
–format
指定输出格式。
%w 表示发生事件的目录
%f 表示发生事件的文件
%e 表示发生的事件
%Xe 事件以“X”分隔
%T 使用由–timefmt定义的时间格式
inotifywatch
语法:
inotifywatch [-hvzrqf] [-e
参数:
-h, –help
输出帮助信息
-v, –verbose
输出详细信息
@
排除不需要监视的文件,可以是相对路径,也可以是绝对路径。
–fromfile
从文件读取需要监视的文件或排除的文件,一个文件一行,排除的文件以@开头。
-z, –zero
输出表格的行和列,即使元素为空
–exclude
正则匹配需要排除的文件,大小写敏感。
–excludei
正则匹配需要排除的文件,忽略大小写。
-r, –recursive
监视一个目录下的所有子目录。
-t
设置超时时间
-e
只监听指定的事件。
-a
以指定事件升序排列。
-d
以指定事件降序排列。
可监听事件
access | 文件读取 |
modify | 文件更改。 |
attrib | 文件属性更改,如权限,时间戳等。 |
close_write | 以可写模式打开的文件被关闭,不代表此文件一定已经写入数据。 |
close_nowrite | 以只读模式打开的文件被关闭。 |
close | 文件被关闭,不管它是如何打开的。 |
open | 文件打开。 |
moved_to | 一个文件或目录移动到监听的目录,即使是在同一目录内移动,此事件也触发。 |
moved_from | 一个文件或目录移出监听的目录,即使是在同一目录内移动,此事件也触发。 |
move | 包括moved_to和 moved_from |
move_self | 文件或目录被移除,之后不再监听此文件或目录。 |
create | 文件或目录创建 |
delete | 文件或目录删除 |
delete_self | 文件或目录移除,之后不再监听此文件或目录 |
unmount | 文件系统取消挂载,之后不再监听此文件系统。 |
微信加密功能需要用到这个mcrypt扩展,CentOS下php安装mcrypt模块扩展
微信加密功能需要用到这个mcrypt扩展,CentOS下php安装mcrypt模块扩展
大致步骤(1)安装mcrypt,(2)安装php对mcrypt的扩展,(3)重启apache
(1)、确认你的linux没有安装mcrypt库,如果已安装,跳过安装步骤
[root@test-206 ~]# yum list installed|grep mcrypt libmcrypt.x86_64 2.5.8-4.el5.centos installed libmcrypt-devel.x86_64 2.5.8-4.el5.centos installed mcrypt.x86_64 2.6.8-1.el5 installed
以上显示已经安装过,若没有,则按以下两种方式安装
(方法一)yum命令懒人安装
yum install libmcrypt libmcrypt-devel mcrypt mhash
执行后会显示即将安装的相关库,你可以根据你的linux限定x86_64或者i386,如yum install libmcrypt.x86_64(如果yum命令无法连接仓库,请检查你的/etc/yum.repos.d/里的文件正确性,以及你的/etc/host是不是可达里面的域名)
Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: libmcrypt i386 2.5.7-5.el5 epel 124 k libmcrypt x86_64 2.5.8-4.el5.centos extras 105 k libmcrypt-devel i386 2.5.7-5.el5 epel 103 k libmcrypt-devel x86_64 2.5.8-4.el5.centos extras 10 k mcrypt x86_64 2.6.8-1.el5 epel 88 k mhash i386 0.9.2-6.el5 epel 141 k mhash x86_64 0.9.9-1.el5.rf rpmforge 161 k Transaction Summary ================================================================================ Install 7 Package(s) Upgrade 0 Package(s) Total download size: 731 k Is this ok [y/N]:
确定安装,最后显示
Installed: libmcrypt.x86_64 0:2.5.8-4.el5.centos libmcrypt-devel.x86_64 0:2.5.8-4.el5.centos mcrypt.x86_64 0:2.6.8-1.el5 mhash.x86_64 0:0.9.9-1.el5.rf Complete!
(方法二)源码编译安装,去http://www.sourceforge.net下载Libmcrypt,mhash,mcrypt安装包
libmcrypt(libmcrypt-2.5.8.tar.gz ):
mcrypt(mcrypt-2.6.8.tar.gz ):
mhash(mhash-0.9.9.9.tar.gz ):
2 .先安装Libmcrypt
#tar -zxvf libmcrypt-2.5.8.tar.gz #cd libmcrypt-2.5.8 #./configure #make #make install 说明:libmcript默认安装在/usr/local
3.安装mhash
#tar -zxvf mhash-0.9.9.9.tar.gz #cd mhash-0.9.9.9 #./configure #make #make install
4.安装mcrypt
#tar -zxvf mcrypt-2.6.8.tar.gz #cd mcrypt-2.6.8 #LD_LIBRARY_PATH=/usr/local/lib ./configure #make #make install
最后,还是检查下,是否安装成功
(2)、安装php的mcrypt扩展(动态加载编译)
下载php下的mcrypt扩展或者直接下载php的完整安装包
http://cn.php.net/releases/ 网页下找到自己服务器的php版本,下载后tar解压(本人的是php5.3.3)
进入ext/mcrypt文件夹
[root@*_* 14:45 ~]# cd php-5.3.3/ext/mcrypt/
执行phpize命令(phpize是用来扩展php扩展模块的,通过phpize可以建立php的外挂模块,如果没有?yum install php53-devel里包含了,或者其他方法)
[root@*_* 14:48 mcrypt]# whereis phpize //为了确定phpize存在 phpize: /usr/bin/phpize /usr/share/man/man1/phpize.1.gz [root@*_* 14:48 mcrypt]# phpize Configuring for: PHP Api Version: 20090626 Zend Module Api No: 20090626 Zend Extension Api No: 220090626
执行完后,会发现当前目录下多了一些configure文件,最后执行php-config命令就基本完成了
执行以下命令,确保你的/usr/bin/php-config是存在的
[root@*_* 15:02 mcrypt]# whereis php-config php-config: /usr/bin/php-config /usr/share/man/man1/php-config.1.gz [root@*_* 15:02 mcrypt]# ./configure --with-php-config=/usr/bin/php-config
如果遇到以下错误,请先安装gcc,命令yum install gcc
configure: error: no acceptable C compiler found in $PATH
直到不报错,出现:config.status: creating config.h,执行以下命令
[root@*_* 15:06 mcrypt]# make && make install
最后的最后,会提示你如下,说明你大功告成了
Installing shared extensions: /usr/lib64/php/modules/
顺便检查下/usr/lib64/php/modules/里的mcrypt.so扩展是否已经创建成功
然后的事就简单了,给你的php.ini添加一条extension=mcrypt.so
[root@*_* 15:09 mcrypt]# cd /etc/php.d
创建一个mrcypt.ini文件就行,里面写extension=mcrypt.so
[root@*_* 15:17 php.d]# echo 'extension=mcrypt.so' > mcrypt.ini
(3) 、重启apache,查阅phpinfo,mcrypt模块扩展是不是加载了?