centos + nginx + php + redis + python + mysql+ java环境搭建(测试环境)
配置结果
> uname -a
Linux bogon 2.6.32-279.el6.x86_64 #1 SMP Fri Jun 22 12:19:21 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
> mysql -uroot -pnew-password
mysql> status
mysql Ver 14.14 Distrib 5.1.73, for redhat-inux-gnu (x86_64) using readline 5.1
> nginx -v
nginx version: nginx/1.8.0
> php-fpm -i|grep 'php version' -i
PHP Version => 5.4.45
> python -V
Python 2.7.10
> redis-server -v
Redis server version 2.4.10 (00000000:0)
> java -version
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.1) (rhel-1.45.1.11.1.el6-x86_64)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)
安装mysql
安装mysql
yum install mysql
yum install mysql-server
/usr/bin/mysqladmin -u root password 'new-password' # 设置root帐号密码
打开3306和80端口
vi /etc/sysconfig/iptables
> -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
> -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
service iptables restart
允许root非本机访问
mysql -u root -pnew-password
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'new-password' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
测试验证
在客户机上测试数据库连接是否OK
安装nginx
安装php
nginx与php集成
php配置redis
安装phpredis
git clone git://github.com/phpredis/phpredis
phpize
./configure --with-php-config=/usr/bin/php-config --enable-redis
make && make install
./configure
配置php-fpm加载so
在php.ini中添加extension=redis.so
php.ini文件位置,php-fpm -i查看
php.ini的demo可以通过"find /usr -name php.ini"找到。
Configuration File (php.ini) Path => /usr/local/lib
修改php.ini后重启PHP-FPM。
之后验证是否php.ini加载成功以及是否加载了redis.so
仍然使用php-fpm -i
查看
[root@bogon phpredis]# php-fpm -i | grep Configuration
Configuration File (php.ini) Path => /usr/local/lib
Loaded Configuration File => /usr/local/lib/php.ini
再看看redis.so是否加载
[root@bogon phpredis]# php-fpm -i | grep Redis
[28-Oct-2015 08:03:06] NOTICE: PHP message: PHP Warning: Unknown: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in Unknown on line 0
Redis Support => enabled
Redis Version => 2.2.5
PHP-FPM使用信号控制
master进程可以理解以下信号
INT, TERM 立刻终止
QUIT 平滑终止
USR1 重新打开日志文件
USR2 平滑重载所有worker进程并重新载入配置和二进制模块
示例
php-fpm 启动
/usr/local/php/sbin/php-fpm
php-fpm 关闭
kill -INT \
cat /usr/local/php/var/run/php-fpm.pid`php-fpm 重启
kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid` `
php-fpm中加载curl插件
cd
/ext/curl -
编译
phpize ./configure --with-curl make && make install
-
restart php-fpm
ps -elf | grep php-fpm # 获取php-fpm的主进程号 kill -INT
php-fpm -
验证
php-fpm -i | grep curl -i > cURL support => enabled > cURL Information => 7.19.7
** bash环境 **
全局变量
/etc/bashrc # 不要动
/etc/profile # 不要动
/etc/profile.d # 在这里加用户登录后的脚本
用户变量
~/.bashrc
~/.bash_profile
升级python到2.7
安装python
- 我看的:CentOS 6 安装 Python3.5以及配置Django
wget http://www.python.org/ftp/python/2.7.10/Python-2.7.10.tgz
tar zxvf Python-2.7.10.tgz
Python-2.7.10
./configure
make && make install
python -V
> Python 2.7.10
yum # 注意检查yum是否能够正常工作。如果不能,修改yum:vi /usr/bin/yum
一般默认安装情况下,
/usr/local/bin/python
是2.7版本,/usr/bin/python
是2.6版本。yum
引用的是/usr/bin/python
安装setuptools和pip
pip官网有如下介绍:
Do I need to install pip?
pip is already installed if you're using Python 2 >=2.7.9 or Python 3 >=3.4 downloaded from python.org, but you'll need to upgrade pip./usr/local/python3/bin/pip3 install -U pip
python ez_setup.py : 如果报错“zipimport.ZipImportError: can’t decompress data; zlib not available” 或者 binascii 。。。 :zlib 解决办法:(1)先安装系统相应的依赖库文件1sudo apt-get install zlibc zlib1g-dev(2)到python安装目录下执行1sudo ./configure编辑Modules/Setup文件vim Modules/Setup找到下面这句,去掉注释#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz重新编译安装:12sudo makesudo make -i installbinascii 类似
wget http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg --no-check-certificate
sh setuptools-0.6c11-py2.7.egg
wget http://pypi.python.org/packages/source/p/pip/pip-1.0.2.tar.gz --no-check-certificate
tar zxf pip-1.0.2.tar.gz
cd pip-1.0.2
python setup.py install
如果pypi.python.org不可用,也可使用豆瓣的pypi.douban.org
安装virtualenv和virtualenvwrapper
pip install virtualenv
pip install virtualenvwrapper
如果使用豆瓣源:
pip install virtualenv -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
如果长期使用:
> mkdir ~/.pip
> vi ~/.pip/pip.conf
[global]
index-url = http://pypi.douban.com/simple
Ref to: http://www.cnblogs.com/hushaojun/p/4606986.html
安装java
> yum install java-1.8.0-openjdk
> java -version
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.1) (rhel-1.45.1.11.1.el6-x86_64)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)
配置uwsgi
get http://projects.unbit.it/downloads/uwsgi-1.4.2.tar.gz
tar -zxvf uwsgi-1.4.2.tar.gz
cd uwsgi-1.4.2
python setup.py build
make
mv uwsgi /usr/bin
vim /usr/local/nginx/conf/nginx.conf
在server下的location下增加以下2行
location / {
uwsgi_pass 127.0.0.1:9001;
include uwsgi_params;
}
在启动服务器时出现下列出错信息
raise ImproperlyConfigured("Error loading either pysqlite2 or sqlite3 modules (tried in that order): %s" % exc)
django.core.exceptions.ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named _sqlite3
解决办法:
安装sqllite-devel
yum -y install sqlite-devel
然后重新编译安装python即可