vsftpd, samba, nfs, mariadb基础入门

2018-03-01 11:09:03来源:网络收集作者:KYOERCY人点击

分享
1、搭建php-fpm工作方式的LAMP环境,实现wordpress正常访问

一、配置mariadb-server


二、配置httpd
1)配置web server


2)配置将php资源反代至php-fpm


三、配置php-fpm


四、布署php开发的开源动态应用程序


五、面临的问题整理
测试V1


测试V2


测试V3


测试V4


附上脚本:生成测试页面
#!/bin/bash # Date: 2018/2/11 # dir=”$1″ dir=${dir%/}
get_ip() { local iface=$1 ifconfig $1 | awk ‘NR==2{print $2}’ } cp_index() { local file=$1 if [ ! -f ${dir}/$file ]; then echo “

Web service on $ip

” > ${dir}/$file fi } cp_phpinfo() { local file=$1 if [ ! -f ${dir}/phpinfo.php ]; then echo “ test page

$ip

<?php phpinfo(); ?> ” > ${dir}/$file fi } cp_php-mysql() { local file=$1 while true; do if [ ! -f ${dir}/$file ]; then read -p “Enter your mysql host: ” mysql_host [ “$mysql_host” == “n” ] && break echo “$mysql_host” | egrep ‘(<([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])>.?){4}’ || continue read -p “Enter your mysql user: ” mysql_user [ “$mysql_user” == “n” ] && break [ -z “$mysql_user” ] && continue read -p “Enter your mysql pass: ” mysql_pass [ “$mysql_pass” == “n” ] && break
echo “<?php $conn = mysql_connect(‘$mysql_host’,’$mysql_user’,’$mysql_pass’); if ($conn) echo ”connect $mysql_host success”; else echo ”connect $mysql_host failure”; ?>” > ${dir}/$file && break else break fi done } main() { local file=$1 [ $# -ne 1 ] && return 1 case $file in index.html) cp_index $file ;; phpinfo.php) cp_phpinfo $file ;; php-mysql.php) cp_php-mysql $file ;; esac }
# —————- pre config —————————————————————————– [ $# -lt 1 ] && echo “Usage: $(basename $0) /PATH/TO/SOMEDIR” && exit 1 [ -d $dir ] || mkdir -p $dir rpm -q net-tools &> /dev/null || yum -d 0 -e 0 -y install net-tools ifaces=$(ifconfig | awk -F: ‘/^[^[:space:]]/ && !/lo/{print $1}’) echo ${ifaces[@]} read -p ‘select a iface ‘ iface ! echo “${ifaces[@]}” | grep -q “$iface” && echo “No such interface” && exit 2 ip=$(get_ip $iface) echo “current ip is : $ip”
# —————- copy file ——————————————————————————- files=(“index.html” “phpinfo.php” “php-mysql.php”)
# —————— Confirmation files —————– for i in 0 1 2; do read -p “copy ${files[$i]}? ” opt [[ “$opt” =~ [yY] ]] && myfiles[${#myfiles[@]}]=${files[$i]} done
# —————– copy files —————– for i in ${myfiles[@]}; do main $i [ $? -ne 0 ] && echo “error” && exit done 2、什么是DML?常用SQL举例,每个命令至少1个例子,最多不超过3个例子



INSERT

添加YangGuo, 单行插入, 所有字段插件

MariaDB [hidb]> INSERT INTO students VALUES ('1','YangGuo','M','899-06-04',3);

添加Guo Jing, Ding Dian, 多行插入, 给定字段插入

MariaDB [hidb]> INSERT INTO students(name,gender) VALUES ('Guo Jing','M'),('Ding Dian','M');

添加与主键冲突的Ding Dang

MariaDB [hidb]> REPLACE INTO students VALUES ('3','Ding Dang','F','1001-09-10',5);
SELECT



显示同学班级编号为空或不空的同学;

MariaDB [hidb]> SELECT * FROM students WHERE classid IS NULL;

用户的名字以d开头的同学?


MariaDB [hidb]> SELECT * FROM students WHERE name LIKE 'd%';

注意: VARCHAR类型不区分大小写




属于1、2、3班的同学且性别不是女性?

MariaDB [hidb]> SELECT * FROM students WHERE classid IN (1,2,3) AND NOT gender='F';

男同学人数?

MariaDB [hidb]> SELECT gender,count(*) FROM students GROUP BY gender HAVING gender='M';
DELETE



删除id大于2的用户

MariaDB [hidb]> DELETE FROM students WHERE stuid>=3;

删除年龄从大到小排序的前100个用户

MariaDB [hidb]> DELETE FROM students ORDER BY age DESC LIMIT 100;
UPDATE



将所有classid设定为2

MariaDB [hidb]> UPDATE students SET classid=2;

将Guo Jing班级设定为3

MariaDB [hidb]> UPDATE students SET classid=3 WHERE name='Guo Jing';

修改当前root@localhost用户的密码为magedu

MariaDB [hidb]> UPDATE mysql.user SET Password=PASSWORD('magedu') WHERE user='root' AND host='localhost';
MariaDB [hidb]> FLUSH PRIVILEGES;
3、简述ftp的主动和被动模式,并实现基于pam认证的vsftpd
1)ftp协议


2)vsftpd Server



附上脚本
#!/bin/bash
#
# Date: 2018/1/30
#

trap 'exit' INT
mysql_user='root'
mysql_host='localhost'

grant_database='vsftpd'
grant_user='vsftpd'
grant_host='127.0.0.1'
grant_password='vsftpd'

yum -y -d 0 -e 0 install vsftpd mariadb-server mariadb-devel pam-devel

# ---------------------- complie pam_mysql.so for vsftpd-----------------------
yum -y -d 0 -e 0 groupinstall "Development Tools" "Server Platform Development"
until [ -f /usr/lib64/security/pam_mysql.so ]; do
[ -f pam_mysql-0.7RC1.tar.gz ] || wget http://prdownloads.sourceforge.net/pam-mysql/pam_mysql-0.7RC1.tar.gz
[ -d pam_mysql-0.7RC1 ] || tar xf pam_mysql-0.7RC1.tar.gz
cd pam_mysql-0.7RC1/
./configure --with-mysql=/usr --with-pam=/usr --with-pam-mods-dir=/usr/lib64/security
make
make install
done
ls /usr/lib64/security/pam_mysql.so
sleep 2

# ---------------------- configure mariadb ----------------------------------
cat > /etc/my.cnf << EOF
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
skip_name_resolve = ON
innodb_file_per_table = ON
log_bin=mysql-bin
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
!includedir /etc/my.cnf.d
EOF
# start mariadb service
systemctl restart mariadb.service

# ---------------------- configure env -----------------------------------------------------
if ! mysql -u$mysql_user -h$mysql_host -D ${grant_database} -e 'SHOW TABLES' &> /dev/null; then
mysql -u$mysql_user -h$mysql_host -e "CREATE DATABASE ${grant_database};"
&& mysql -u$mysql_user -h$mysql_host -e "GRANT ALL ON ${grant_database}.* TO '${grant_database}'@'$grant_host' IDENTIFIED BY '${grant_password}';"
&& mysql -u$mysql_user -h$mysql_host -e "CREATE TABLE ${grant_database}.users(id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(60) NOT NULL, password CHAR(48) NOT NULL, UNIQUE KEY(name));"
fi

# ---------------------- create user -----------------------------------------------------
while true; do
echo -e 'Start create users, until input "33[1;31mquit33[0m"'
read -p "Enter a username: " username
[ -z "$username" ] && continue
[ "$username" == "quit" -o "$password" == "quit" ] && break
read -p "Enter a password: " password
[ -z "$username" ] && continue
[ "$username" == "quit" -o "$password" == "quit" ] && break
mysql -u$mysql_user -h$mysql_host -e "INSERT INTO ${grant_database}.users(name,password) VALUES ("$username",PASSWORD("$password"));" && users[${#users[@]}]=$username
done

# ---------------------- pam configure file -----------------------------------------------------
cat > /etc/pam.d/vsftpd.vusers << EOF
auth required /usr/lib64/security/pam_mysql.so user=${grant_user} passwd=${grant_password} host=${grant_host} db=${grant_database} table=users usercolumn=name passwdcolumn=password crypt=2
account required /usr/lib64/security/pam_mysql.so user=${grant_user} passwd=${grant_password} host=${grant_host} db=${grant_database} table=users usercolumn=name passwdcolumn=password crypt=2
EOF

# ---------------------- vsftpd.conf add virtual user -----------------------------------------------------
[ -f /etc/vsftpd/vsftpd.conf.bak ] || cp /etc/vsftpd/vsftpd.conf{,.bak}
sed -i 's/(pam_service_name=).*/1vsftpd.vusers/' /etc/vsftpd/vsftpd.conf
grep -q 'guest_enable=TRUE' /etc/vsftpd/vsftpd.conf
&& grep -q 'guest_username=vuser' /etc/vsftpd/vsftpd.conf || cat >> /etc/vsftpd/vsftpd.conf << EOF
guest_enable=TRUE
guest_username=vuser
EOF

# 准备虚拟用户的家目录
dir='/zz'
[ -d $dir ] || mkdir -p $dir
id vuser &> /dev/null && usermod -d ${dir}/vuser vuser &> /dev/null || useradd -d ${dir}/vuser vuser &> /dev/null

# 要求:1. 家目录没有写权限;2. 所有用户均有其它用户有rx权限
chmod 555 ${dir}/vuser &> /dev/null

# 准备一个公共可下载目录
[ -d ${dir}/vuser/pub ] || mkdir -p ${dir}/vuser/pub

systemctl restart vsftpd.service

# 准备一个文件,登陆tom, jerry尝试下载,删除,上传等操作
# cp /etc/fstab /zz/vuser/pub/
# lftp tom@172.16.0.6:/pub> get fstab
# 713 bytes transferred
# lftp tom@172.16.0.6:/pub> rm fstab
# rm: Access failed: 550 Permission denied. (fstab)
# lftp tom@172.16.0.6:/pub> put issue
# put: Access failed: 550 Permission denied. (issue)
# ...
# 结果,只能下载(默认权限),不能上传,不能删除;

# -------------- 配置 虚拟用户可分配权限 ----------
share_dir='/etc/vsftpd/vusers_config'
echo -e "vuser configure dir : 33[1;31m$share_dir33[0m"
[ -d $share_dir ] || install -d $share_dir
grep -q "user_config_dir" /etc/vsftpd/vsftpd.conf || echo "user_config_dir=$share_dir" >> /etc/vsftpd/vsftpd.conf

# --------------配置上传、删除权限 --------------
install -d -o vuser -g vuser ${dir}/vuser/upload

while true; do
echo -e 'configure exist user, until input "33[1;31mquit33[0m"'
read -p 'Enter a username: ' user
[ "$user" == "quit" ] && break
[ -f ${share_dir}/$user ] && users[${#users[@]}]=$user || continue
done

for i in ${users[@]}; do
echo "configure $i user permission....., Please input YES or NO, default is NO"
read -p 'download? ' d
[ "$d" = "YES" ] && permission[${#permission[@]}]='download'
[ "$d" != "YES" ] && d=NO
read -p 'upload? ' u
[ "$u" = "YES" ] && permission[${#permission[@]}]='upload'
[ "$u" != "YES" ] && u=NO
read -p 'mkdir? ' m
[ "$m" = "YES" ] && permission[${#permission[@]}]='mkdir'
[ "$m" != "YES" ] && m=NO
read -p 'writeable? ' w
[ "$w" = "YES" ] && permission[${#permission[@]}]='write'
[ "$w" != "YES" ] && w=NO
echo "-------------- 给${i}配置${permission[@]} --------------"
cat > $share_dir/${i} << EOF
anonymous_enable=$d
anon_upload_enable=$u
anon_mkdir_write_enable=$m
anon_other_write_enable=$w
anon_umask=022
EOF
[ $? -eq 0 ] && echo "OK"
done
# 注释:anon_umask必须设置其它用户可读,否则创建的目录下的所有文件不可见;
4、简述NFS服务原理及配置
5、简述samba服务,并实现samba配置

本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/91556

最新文章

123

最新摄影

闪念基因

微信扫一扫

第七城市微信公众平台