6.启动Nginx服务并检查
ulimit -SHn 65535
/usr/local/webserver/nginx/sbin/nginx
ps -ef |grep nginx
7.简单站点部署测试
mkdir -p /usr/local/webserver/nginx/conf/vhost/html
cd /usr/local/webserver/nginx/conf/vhost/html
vim onbing.com.conf
输入以下内容:
server
{
listen 80;
server_name onbing.com;
index index.html index.htm ;
root /data0/htdocs/html/onbing.com;
include server.html.conf;
log_format html_onbing '$remote_addr - $remote_user [$time_local] "$request"'
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log /data1/logs/access_html_onbing.log html_onbing;
}
#网站文件存放目录
mkdir -p /data0/htdocs/html/onbing.com
vim /data0/htdocs/html/onbing.com/index.html
输入以下内容:
<html>
<head><title>onbing</title></head>
<body bgcolor="white">
<center><h1>welcome to nginx</h1></center>
</body>
</html>
chown -R www:www /data0/htdocs/html/onbing.com
#配置文件测试并重载
/usr/local/webserver/nginx/sbin/nginx -t
/usr/local/webserver/nginx/sbin/nginx -s reload
注意:
1).测试时关闭iptables
/etc/init.d/iptables stop
2).域名做hosts指向
192.168.1.24 onbing.com
192.168.1.24
3).测试命令
curl -I
8.nginx日志分割
mkdir -p /data0/sh
cd /data0/sh
vim cut_nginx_log.sh
#!/bin/bash
# This script run at 00:00
# The Nginx logs path
logs_path="/usr/local/webserver/nginx/logs/"
mkdir -p ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/
mv ${logs_path}access.log ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/access_$(date -d "yesterday" +"%Y%m%d").log
kill -USR1 `cat /usr/local/webserver/nginx/nginx.pid`
#检查crond服务是否启动
service crond status
#编辑任务计划
crontab -e
输入以下内容:
0 0 * * * /bin/bash /data0/sh/cut_nginx_log.sh
四、MySQL安装
#检查并更新安装mysql所需要依赖的软件包
yum install -y automake autoconf libtool ncurses-devel libxslt groff pcre-devel
#安装cmake,后面安装mysql配置时需要使用
#CMAKE安装MySQL的配置参数说明:
tar zxvf cmake-2.8.7.tar.gz && cd cmake-2.8.7/
./configure
gmake && gmake install && cd ../
#创建mysql用户和组
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
说明:设置mysql用户密码:/usr/bin/passwd mysql
#创建webserver目录,将nginx,php,mysql均安装到此目录
mkdir -p /usr/local/webserver
#创建mysql数据存放目录
mkdir -p /data0/mysql/3306/data/
mkdir -p /data0/mysql/3306/binlog/
mkdir -p /data0/mysql/3306/relaylog/
chown -R mysql:mysql /data0/mysql/
#开始安装mysql-5.5.20
tar zxvf mysql-5.5.20.tar.gz && cd mysql-5.5.20/
/usr/local/bin/cmake -DCMAKE_INSTALL_PREFIX=/usr/local/webserver/mysql/ \
-DMYSQL_DATADIR=/data0/mysql/3306/data/ \
-DSYSCONFDIR=/data0/mysql/3306/ \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1
make
make install
cd ../
说明:如果编译失败,删除文件重新编译:rm -f CMakeCache.txt
chown -R mysql:mysql /usr/local/webserver/mysql
chmod +w /usr/local/webserver/mysql
#以mysql用户帐号的身份建立数据表
/usr/local/webserver/mysql/scripts/mysql_install_db --basedir=/usr/local/webserver/mysql --datadir=/data0/mysql/3306/data --user=mysql
#创建my.cnf配置文件:
vim /data0/mysql/3306/my.cnf
输入以下内容:
[client]
#character-set-server = utf8
port = 3306
socket = /tmp/mysql.sock
[mysqld]
#character-set-server = utf8
replicate-ignore-db = mysql
replicate-ignore-db = test
replicate-ignore-db = information_schema
user = mysql
port = 3306
socket = /tmp/mysql.sock
basedir = /usr/local/webserver/mysql
datadir = /data0/mysql/3306/data
log-error = /data0/mysql/3306/mysql_error.log
pid-file = /data0/mysql/3306/mysql.pid
open_files_limit = 10240
back_log = 600
max_connections = 5000
max_connect_errors = 6000
table_cache = 614
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 1M
join_buffer_size = 1M
thread_cache_size = 300
#thread_concurrency = 8
query_cache_size = 512M
query_cache_limit = 2M
query_cache_min_res_unit = 2k
default-storage-engine = MyISAM
thread_stack = 192K
transaction_isolation = READ-COMMITTED
tmp_table_size = 246M
max_heap_table_size = 246M
long_query_time = 3
log-slave-updates
log-bin = /data0/mysql/3306/binlog/binlog
binlog_cache_size = 4M
binlog_format = MIXED
max_binlog_cache_size = 8M
max_binlog_size = 1G
relay-log-index = /data0/mysql/3306/relaylog/relaylog
relay-log-info-file = /data0/mysql/3306/relaylog/relaylog
relay-log = /data0/mysql/3306/relaylog/relaylog
expire_logs_days = 30
key_buffer_size = 256M
read_buffer_size = 1M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
interactive_timeout = 120
wait_timeout = 120
skip-name-resolve
#master-connect-retry = 10
slave-skip-errors = 1032,1062,126,1114,1146,1048,1396
#master-host = 192.168.1.2
#master-user = username
#master-password = password
#master-port = 3306
server-id = 1
innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 512M
innodb_data_file_path = ibdata1:256M:autoextend
innodb_file_io_threads = 4
innodb_thread_concurrency = 8
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 16M
innodb_log_file_size = 128M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = 0
#log-slow-queries = /data0/mysql/3306/slow.log
#long_query_time = 10
[mysqldump]
quick
max_allowed_packet = 32M
#创建管理MySQL数据库的shell脚本:
vim /data0/mysql/3306/mysql
输入以下内容(这里的用户名bingadmin和密码TQHQoYc55SR68S3M接下来的步骤会创建):
#!/bin/sh
mysql_port=3306
mysql_username="bingadmin"
mysql_password="TQHQoYc55SR68S3M"
function_start_mysql()
{
printf "Starting MySQL...\n"
/bin/sh /usr/local/webserver/mysql/bin/mysqld_safe --defaults-file=/data0/mysql/${mysql_port}/my.cnf 2>&1 > /dev/null &
}
function_stop_mysql()
{
printf "Stoping MySQL...\n"
/usr/local/webserver/mysql/bin/mysqladmin -u ${mysql_username} -p${mysql_password} -S /tmp/mysql.sock shutdown
}
function_restart_mysql()
{
printf "Restarting MySQL...\n"
function_stop_mysql
sleep 5
function_start_mysql
}
if [ "$1" = "start" ]; then
function_start_mysql
elif [ "$1" = "stop" ]; then
function_stop_mysql
elif [ "$1" = "restart" ]; then
function_restart_mysql
elif [ "$1" = "kill" ]; then
function_kill_mysql
else
printf "Usage: /data0/mysql/${mysql_port}/mysql {start|stop|restart|kill}\n"
fi
#赋予shell脚本可执行权限
chmod +x /data0/mysql/3306/mysql
#启动MySQL
/data0/mysql/3306/mysql start
#通过命令行登录管理MySQL服务器
/usr/local/webserver/mysql/bin/mysql -u root -p
#创建一个具有root权限的用户(bingadmin)和密码(TQHQoYc55SR68S3M)
grant SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX,ALTER,CREATE TEMPORARY TABLES on *.* to 'bingadmin'@'localhost' identified by 'TQHQoYc55SR68S3M';
grant SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX,ALTER,CREATE TEMPORARY TABLES on *.* to 'bingadmin'@'127.0.0.1' identified by 'TQHQoYc55SR68S3M';
flush privileges;
LNMP企业应用部署全过程(基于DEDE后台)(2)
内容版权声明:除非注明,否则皆为本站原创文章。
转载注明出处:http://www.heiqu.com/51cd1ee24e012903b3529e08b86fd975.html