需求:内部人员经常到查阅资料,考虑在内网搭建wiki站点。
实验拓扑:
实验环境:
Nginx,PHP:192.168.198.160,10.0.0.07
MySQL:10.0.0.8
软件包:
HDWiki-v5.1UTF8-20141205.zip
nginx-1.8.0.tar.gz
xcache-3.2.0.tar.gz
mysql-5.5.46-linux2.6-x86_64.tar.gz
php-5.3.27.tar.bz2
1、安装Nginx
1.1准备
ntpdate 202.120.2.101 yum install pcre-devel -y #解决依赖关系 useradd -r -s /sbin/nologin nginx #添加Nginx用户和组
1.2编译安装
cd /tools tar -xf nginx-1.8.0.tar.gz cd nginx-1.8.0 ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module make && make install
1.3 提供配置文件 (这一步在编译PHP的时候进行,节约时间)
worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name wiki.edelweiss0.com; location / { root html/wiki; index index.html index.htm index.php; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~ \.php$ { root html/wiki; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } } }
2、安装PHP
2.1解决依赖关系
yum install zlib libxml libjpeg freetype libpng gd curl zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel openssl-devel libxslt-devel -y
wget http://ftp.gnu.org/gnu/libiconv/libiconv-1.14.tar.gz tar zxf libiconv-1.14.tar.gz cd libiconv-1.14 ./configure --prefix=/usr/local/libiconv make make install #如果有依赖关系报错,自行百度,安装相应的软件包即可
2.2编译安装
tar -xf php-5.3.27.tar.bz2 cd php-5.3.27 ./configure \ --prefix=/usr/local/php \ --enable-fpm \ --with-mysql=mysqlnd \ --with-pdo-mysql=mysqlnd \ --with-mysqli=mysqlnd \ --with-xmlrpc \ --with-openssl \ --with-zlib \ --with-freetype-dir \ --with-gd \ --with-jpeg-dir \ --with-png-dir \ --with-iconv=/usr/local/libiconv \ --enable-short-tags \ --enable-sockets \ --enable-soap \ --enable-mbstring \ --enable-static \ --enable-gd-native-ttf \ --with-curl \ --with-xsl \ --enable-ftp \ --with-libxml-dir \ --with-fpm-user=nginx \ --with-fpm-group=nginx \ --with-config-file-path=/etc \ --with-config-file-scan-dir=/etc/php.d #这是某运维老鸟说的他企业里都是这么配置的,不需要更改。可自行搜索
make && make install #这里需要等待一段时间了,可以同时进行第三步操作
2.3为php提供配置文件,以fastcgi方式监听在9000端口
cp php.ini-production /etc/php.ini #为php提供配置文件 cd /usr/local/php/ cp etc/php-fpm.conf.default etc/php-fpm.conf #如果要实现php和web服务分离可以编辑此文件,这里保持默认
2.4安装与配置xcache加速器
tar -xf xcache-3.2.0.tar.gz cd xcache-3.2.0 /usr/local/php/bin/phpize #注意这里要先解压xcache在运行此命令 ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config make && make install #注意输出的最后信息Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/
mkdir /etc/php.d #提供xcache扩展配置文件 cp xcache.ini /etc/php.d/ vim /etc/php.d/xcache.ini [root@edeiweiss0 xcache-3.2.0]# diff xcache.ini /etc/php.d/xcache.ini 4c4 < extension = xcache.so --- > extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/xcache.so
3、安装MySQL(在另一台机器)
3.1准备
mkdir /data cd /usr/local/src/ #mysql-5.5.46-linux2.6-x86_64.tar.gz tar -xf mysql-5.5.46-linux2.6-x86_64.tar.gz -C /usr/local ln -sv /usr/local/mysql-5.5.46-linux2.6-x86_64/ /usr/local/mysql groupadd mysql useradd -g mysql mysql cd /usr/local/mysql
3.2初始化数据库
chown -R mysql.mysql . scripts/mysql_install_db --user=mysql --datadir=/data/ --basedir=/usr/local/mysql #一般出现两个OK代表安装正常
3.3提供配置文件和服务脚本
cp support-files/my-medium.cnf /etc/my.cnf cp: overwrite `/etc/my.cnf'? y vim /etc/my.cnf
[root@node1 mysql]# diff /etc/my.cnf support-files/my-medium.cnf 38,39c38 < datadir=/data < log-error=/data/mysql-err --- >
cp support-files/mysql.server /etc/init.d/mysqld service mysqld start [root@node1 mysql]# ss -tnl | grep 330 LISTEN 0 50 *:3306 *:* echo "PATH=/usr/local/mysql/bin:/$PATH" > /etc/profile.d/mysql.sh source /etc/profile.d/mysql.sh
3.4为站点提供数据库和用户
mysql> drop database test; #删除无用的数据库 Query OK, 0 rows affected (0.06 sec) mysql> delete from mysql.user where user=''; #删除无用的用户 Query OK, 2 rows affected (0.10 sec) mysql> create database wiki; #创建wiki数据库 Query OK, 1 row affected (0.00 sec) mysql> grant all on wiki.* to 'wiki'@'10.0.0.%' identified by '123456'; #创建并授权wiki数据的用户 Query OK, 0 rows affected (0.05 sec) mysql> flush privileges; #刷新权限 Query OK, 0 rows affected (0.00 sec)
4、整合Nginx,PHP,MySQL
sbin/nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful sbin/nginx /usr/local/php/sbin/php-fpm
4.1测试Nginx和PHP
mkdir html/wiki vim html/wiki/index.php <?php phpinfo(); ?>
4.2测试PHP和MySQL
#注意防火墙的配置 vim /usr/local/nginx/html/wiki/index.php <?php $link_id=mysql_connect('192.168.198.130','wiki','123456') or mysql_error(); if($link_id){ echo "mysql successful by yunzhonghe !"; }else{ echo mysql_error(); } ?>
4.3建站
cd /tools/ unzip HDWiki-v5.1UTF8-20141205.zip mv HDWiki-v5.1UTF8-20121102/* /usr/local/nginx/html/wiki/ chown nginx.nginx -R /usr/local/nginx/
#结果展示
到时候可以自行扩展
5、总结:希望大家有所收获。
原创文章,作者:艾贺,如若转载,请注明出处:http://www.178linux.com/8712